Module: Readmill::Client::Readings

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

Overview

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

Instance Method Summary collapse

Instance Method Details

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

Public: Get a specific reading from readmill.

id - The id of a reading 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: {}).
:periods    - Boolean whether to get the periods or not
              (default: false).
:locations  - Boolean whether to get the locations or not
              (default: false).

Returns a Hashie::Mash.



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/readmill/client/readings.rb', line 46

def reading(id, opts={})
  ensure_valid_reading_options(opts)

  if opts.delete(:periods)
    get("readings/#{id}/periods", opts).items
  elsif opts.delete(:locations)
    get("readings/#{id}/locations", opts).items
  elsif opts.delete(:highlights)
    get("readings/#{id}/highlights", opts).items
  else
    get("readings/#{id}", opts)
  end
end

#readings(opts = {}) ⇒ Object

Public: Get all readings 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: {}).
:book_id - Limit the readings to a specific book.
:user_id - Limit the readings to a specific user.

Returns an Array.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/readmill/client/readings.rb', line 17

def readings(opts={})
  if !opts[:user_id].nil? && !opts[:book_id].nil?
    raise ArgumentError,
      'You can pass either book_id or user_id, but not both.'
  end

  if !opts[:user_id].nil?
    url = "users/#{opts.delete(:user_id)}/readings"
  elsif !opts[:book_id].nil?
    url = "books/#{opts.delete(:book_id)}/readings"
  else
    url = 'readings'
  end

  get(url, opts).items
end