Skip to content

Commit

Permalink
add /author/list
Browse files Browse the repository at this point in the history
  • Loading branch information
ariejan committed Mar 21, 2020
1 parent a3a5e84 commit 036ee5f
Show file tree
Hide file tree
Showing 4 changed files with 1,374 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ author.name # => author name
author.link # => link to author's Goodreads page
```

Look up books by an author:

```ruby
author = client.author_Book("id")

author.id # => author id
author.name # => author name
author.link # => link to author's Goodreads page
author.books # => array of books by this author
```

### Reviews

Pull recent reviews:
Expand Down
8 changes: 8 additions & 0 deletions lib/goodreads/client/authors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ def author(id, params = {})
Hashie::Mash.new(data["author"])
end

# Get an author's books
#
def author_books(id, params = {})
params[:id] = id
data = request("/author/list", params)
Hashie::Mash.new(data["author"])
end

# Search for an author by name
#
def author_by_name(name, params = {})
Expand Down
17 changes: 17 additions & 0 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,23 @@
end
end

describe "#author_books" do
before do
stub_with_key_get("/author/list", { id: "18541" }, "author_books.xml")
end

it "returns author's books" do
author = client.author_books("18541")

expect(author).to be_a(Hashie::Mash)
expect(author.id).to eq("18541")
expect(author.name).to eq("Tim O'Reilly")
expect(author.link).to eq("https://www.goodreads.com/author/show/18541.Tim_O_Reilly")

expect(author.books.book.size).to eq(30)
end
end

describe "#user" do
before { stub_with_key_get("/user/show", { id: "878044" }, "user.xml") }

Expand Down
Loading

0 comments on commit 036ee5f

Please sign in to comment.