Module: Readmill::Client::Books

Included in:
Readmill::Client
Defined in:
lib/readmill/client/books.rb

Overview

Public: This module will bring all of the methods from the book section of the API.

Instance Method Summary collapse

Instance Method Details

#book(id, opts = {}) ⇒ Object

Public: Get a specific book from readmill.

id - The id of a book to get from readmill. opts - A Hash of options used to modify the results. All of the values

of this Hash will be forwarded to the API as parameters
(default: {}).
:readers  - Boolean whether or not to get readers of a book
            (default: false).

Returns a Hashie::Mash.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/readmill/client/books.rb', line 29

def book(id, opts={})
  if opts[:closing_remarks] && opts[:readers]
    raise ArgumentError,
      'You can pass either closing_remarks or readers, but not both.'
  end

  if opts.delete(:closing_remarks)
    get("books/#{id}/closing_remarks", opts).items
  elsif opts.delete(:readers)
    get("books/#{id}/readers", opts).items
  else
    get("books/#{id}", opts)
  end
end

#books(opts = {}) ⇒ Object

Public: Get all books from readmill.

opts - A Hash of options used to modify the results. All of the values

of this Hash will be forwarded to the API as parameters
(default: {}).

Returns an Array.



15
16
17
# File 'lib/readmill/client/books.rb', line 15

def books(opts={})
  get('books', opts).items
end