Class: RestBooks::Books
Constant Summary
Constants included from Api
Api::AUTHOR_PARAMETERS, Api::BOOK_PARAMETERS, Api::LIST_PARAMETERS, Api::ORDERED_AUTHOR_PARAMETERS, Api::ORDERED_BOOK_PARAMETERS, Api::RANGED_AUTHOR_PARAMETERS, Api::RANGED_BOOK_PARAMETERS
Instance Method Summary collapse
-
#all(options = {}) ⇒ Object
Endpoint: /books Formats: Atom Description: List all books (20 items) Parameters: * letter: display the books with …
-
#comments(book_id, options = {}) ⇒ Object
Endpoint: /book/:id/comments Formats: Atom.
-
#get(book_id, options = {}) ⇒ Object
Endpoint: /book/:id/comments Formats: Atom, EPub, Mobipocket, PDF, png Description: Get the book, information or cover Parameters: * size: for png cover you can use smaller.
-
#lists ⇒ Object
Endpoint: /book/:id/lists Formats: Atom Description: View in which list a book is included Parameters: * order: normally the order is based on the number of favorites, use asc or desc to switch this to alphabetical order.
-
#recent(options = {}) ⇒ Object
Endpoint: /books/recent Formats: Atom, RSS Description: List recent books (20 items) Parameters: * letter: display the books with …
-
#search(query, options = {}) ⇒ Object
Endpoint: /books/search Formats: Atom Description: Search for a book Parameters: * query: you can use advanced queries too (for example “type:Horror AND Lovecraft”).
-
#similar(book_id, options = {}) ⇒ Object
Endpoint: /book/:id/similar Formats: Atom Description: List similar books for a given book Parameters: none.
-
#top(options = {}) ⇒ Object
Endpoint: /books/top Formats: Atom Description: List top books (20 items) Parameters: * letter: display the books with …
Instance Method Details
#all(options = {}) ⇒ Object
Endpoint: /books
Formats: Atom
Description: List all books (20 items)
Parameters:
* letter: display the books with ... as the first letter of their name
* year: book released in ...
* lang: language of the book
* order: normally from A to Z, use desc to reverse order or year to sort them by release date
36 37 38 39 |
# File 'lib/restbooks/books.rb', line 36 def all( ={} ) create_url( "/books", , ORDERED_BOOK_PARAMETERS ) return do_request( :book ) end |
#comments(book_id, options = {}) ⇒ Object
Endpoint: /book/:id/comments
Formats: Atom
100 101 102 103 104 |
# File 'lib/restbooks/books.rb', line 100 def comments( book_id, ={} ) book_id = book_id.id if book_id.kind_of? RestBooks::Models::Book create_url( "/book/#{book_id}/comments", , [:page] ) return do_request( :comment ) end |
#get(book_id, options = {}) ⇒ Object
Endpoint: /book/:id/comments
Formats: Atom, EPub, Mobipocket, PDF, png
Description: Get the book, information or cover
Parameters:
* size: for png cover you can use smaller
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/restbooks/books.rb', line 111 def get( book_id, ={} ) book_id = book_id.id if book_id.kind_of? RestBooks::Models::Book .delete(:size) if [:format] != :png create_url( "/book/#{book_id}", , [:size] ) if @uri.format.to_sym == :atom return do_request( :book ) elsif [ :epub, :mobi, :pdf, :atom, :png ].include?( @uri.format.to_sym ) responce = RestClient::Request.execute(:method => :get, :url => @uri.to_s, :headers => {}, :raw_response => true) return { :content_type => responce.headers[:content_type], :path => responce.file.path } end end |
#lists ⇒ Object
Endpoint: /book/:id/lists
Formats: Atom
Description: View in which list a book is included
Parameters:
* order: normally the order is based on the number of favorites, use asc or desc to switch this to alphabetical order
92 93 94 95 96 |
# File 'lib/restbooks/books.rb', line 92 def lists book_id = book_id.id if book_id.kind_of? RestBooks::Models::Book create_url( "/book/#{book_id}/lists", , LIST_PARAMETERS ) return do_request( :list ) end |
#recent(options = {}) ⇒ Object
Endpoint: /books/recent
Formats: Atom, RSS
Description: List recent books (20 items)
Parameters:
* letter: display the books with ... as the first letter of their name
* year: book released in ...
* lang: language of the book
61 62 63 64 |
# File 'lib/restbooks/books.rb', line 61 def recent( ={} ) create_url( "/books/recent", , BOOK_PARAMETERS ) return do_request( :book ) end |
#search(query, options = {}) ⇒ Object
Endpoint: /books/search
Formats: Atom
Description: Search for a book
Parameters:
* query: you can use advanced queries too (for example "type:Horror AND Lovecraft")
71 72 73 74 75 |
# File 'lib/restbooks/books.rb', line 71 def search( query, ={} ) [:query] = query create_url( "/books/search", , [:query] ) return do_request( :book ) end |
#similar(book_id, options = {}) ⇒ Object
Endpoint: /book/:id/similar
Formats: Atom
Description: List similar books for a given book
Parameters: none
81 82 83 84 85 |
# File 'lib/restbooks/books.rb', line 81 def similar( book_id, ={} ) book_id = book_id.id if book_id.kind_of? RestBooks::Models::Book create_url( "/book/#{book_id}/similar", , [:page] ) return do_request( :book ) end |
#top(options = {}) ⇒ Object
Endpoint: /books/top
Formats: Atom
Description: List top books (20 items)
Parameters:
* letter: display the books with ... as the first letter of their name
* year: book released in ...
* lang: language of the book
* range: normally overall, week will display the most popular for the previous week and month for the last 4 weeks
49 50 51 52 |
# File 'lib/restbooks/books.rb', line 49 def top( ={} ) create_url( "/books/top", , RANGED_BOOK_PARAMETERS ) return do_request( :book ) end |