README.md in goodreads-0.2.1 vs README.md in goodreads-0.2.2

- old
+ new

@@ -1,49 +1,49 @@ -# Goodreads API wrapper +# Goodreads [![Build Status](https://secure.travis-ci.org/sosedoff/goodreads.png)](http://travis-ci.org/sosedoff/goodreads) -Ruby library to connect with Goodreads API. +Ruby wrapper to communicate with Goodreads API. -[![Build Status](https://secure.travis-ci.org/sosedoff/goodreads.png)](http://travis-ci.org/sosedoff/goodreads) - ## Installation -You can install this library via rubygems: +Install gem with rubygems: ``` gem install goodreads ``` -Or using rake: +Or manually: ``` rake install ``` ## Getting Started -In order to use Goodreads API you must obtain an API key for your account. +Before using Goodreads API you must create a new application. Visit [signup form](http://www.goodreads.com/api/keys) for details. Setup client: -```ruby -client = Goodreads::Client.new(:api_key => 'YOUR_KEY') - -# or using a shortcut -client = Goodreads.new(:api_key => 'YOUR_KEY') +``` ruby +client = Goodreads::Client.new(:api_key => 'KEY', :api_secret => 'SECRET') +client = Goodreads.new(:api_key => 'KEY') # short version ``` ### Global configuration -Library allows you to define a global configuration options. +You can define client credentials on global level. Just create an initializer file (if using rails) under +`config/initializers`: -```ruby -Goodreads.configure(:api_key => 'YOUR_KEY') +``` ruby +Goodreads.configure( + :api_key => 'KEY', + :api_secret => 'SECRET' +) ``` -Get current options: +Get global configuration: -```ruby +``` ruby Goodreads.configuration # => {:api_key => 'YOUR_KEY'} ``` In case you need to reset options: @@ -53,36 +53,59 @@ ## Usage ### Lookup books -Find a book by ISBN: +You can lookup a book by ISBN, ID or Title: ```ruby -book = client.book_by_isbn('ISBN') +client.book('id') +client.book_by_isbn('ISBN') +client.book_by_title('Book title') ``` - -Find a book by Goodreads ID: +Search for books (by title, isbn, genre): + ```ruby -book = client.book('id') +search = client.search_books('The Lord Of The Rings') + +search.results.work.each do |book| + book.id # => book id + book.title # => book title +end ``` - -Find a book by title: +### Authors + +Look up an author by their Goodreads Author ID: + ```ruby -book = client.book_by_title('Book title') +author = client.author('id') + +author.id # => author id +author.name # => author's name +author.link # => link to author's Goodreads page +author.fans_count # => number of fans author has on Goodreads +author.image_url # => link to image of the author +author.small_image_url # => link to smaller of the author +author.about # => description of the author +author.influences # => list of links to author's influences +author.works_count # => number of works by the author in Goodreads +author.gender # => author's gender +author.hometown # => author's hometown +author.born_at # => author's birthdate +author.died_at # => date of author's death ``` - -Search for books (by title, isbn, genre): +Look up an author by name: + ```ruby -search = client.search_books('Your search query') -search.results.work.each do |book| - book.id # => book ID - book.title # => book title -end +author = client.author_by_name('Author Name') + +author.id # => author id +author.name # => author name +author.link # => link to author's Goodreads page ``` ### Reviews Pull recent reviews: @@ -93,56 +116,96 @@ r.book.title # => review book title r.body # => review message r.user.name # => review user name end ``` - + Get review details: ```ruby review = client.review('id') -review.id # => ID -review.user # => User information -review.book # => Book information -review.rating # => User rating + +review.id # => review id +review.user # => user information +review.book # => uook information +review.rating # => user rating ``` ### Shelves Get the books on a user's shelf: ```ruby shelf = client.shelf(user_id, shelf_name) + shelf.books # array of books on this shelf shelf.start # start index of this page of paginated results shelf.end # end index of this page of paginated results shelf.total # total number of books on this shelf ``` -### User Id +### Groups -Get the user id of the user who authorized via OAuth: +Get group details: ```ruby -client = Goodreads::Client.new(:api_key => 'YOUR_KEY', :oauth_token => token) -client.user_id # id of user who authorized via OAuth +group = client.group('id') + +group.id # => group id +group.title # => group title +group.access # => group's access settings + # => (e.g., public or private) +group.group_users_count # => number of users in the group ``` -`token` is an instance of `OAuth::AccessToken`. See the [Goodreads documentation](http://www.goodreads.com/api/oauth_example) for examples of how to correct create one. +List the groups a given user is a member of: -## Contributions +```ruby +group_list = client.group_list('user_id', 'sort') -Feel free to contribute any patches or new features. +group_list.total # => total number of groups +group_list.group.count # => number of groups returned in the request -Make sure to add a test coverage so it does not break any existing code. +# Loop through the list to get details for each of the groups. -For documentation please visit [API Reference](http://www.goodreads.com/api) +group_list.group.each do |g| + g.id # => group id + g.access # => access settings (private, public) + g.users_count # => number of members + g.title # => title + g.image_url # => url of the group's image + g.last_activity_at # => date and time of the group's last activity +end +``` +The `sort` parameter is optional, and defaults to `my_activity`. For other sorting options, [see here](http://www.goodreads.com/api#group.list). + +### OAuth + +For API calls requiring permission, such as write operations or browsing friends, see our [OAuth tutorial](examples/oauth.md). + +## Testing + +To run the test suite: + +``` +rake test +``` + +## Contributions + +You're welcome to submit patches and new features. + +- Create a new branch for your feature of bugfix +- Add tests so it does not break any existing code +- Open a new pull request +- Check official [API documentation](http://www.goodreads.com/api) + ## License -Copyright © 2011-2012 Dan Sosedoff. +Copyright © 2011-2013 Dan Sosedoff. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.