Class: GoogleBooksClient::Resources::Volumes

Inherits:
HttpClientAdapter show all
Defined in:
lib/google_books_client/resources/volumes.rb

Class Method Summary collapse

Methods inherited from HttpClientAdapter

#get

Class Method Details

.generate_query(search_hash) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/google_books_client/resources/volumes.rb', line 50

def self.generate_query(search_hash)
  search_hash.map do |search_type, search_value|
    case search_type
    when :title, :author, :publisher
      "in#{search_type}:#{search_value}"
    when :subject, :isbn, :lccn, :oclc
      "#{search_type}:#{search_value}"
    else
      raise ArgumentError, "Invalid search type"
    end
  end.join("+")
end

.list(params = {}) ⇒ Object



10
11
12
# File 'lib/google_books_client/resources/volumes.rb', line 10

def self.list(params = {})
  new.get("volumes", params)
end

.list_by_author(author, params: {}, start_index: 0) ⇒ Object



26
27
28
# File 'lib/google_books_client/resources/volumes.rb', line 26

def self.list_by_author(author, params: {}, start_index: 0)
  list_volumes({ author: author }, params: params, start_index: start_index)
end

.list_by_isbn(isbn, params: {}) ⇒ Object



38
39
40
# File 'lib/google_books_client/resources/volumes.rb', line 38

def self.list_by_isbn(isbn, params: {})
  list_volumes({ isbn: isbn }, params: params)
end

.list_by_lccn(lccn, params: {}) ⇒ Object



42
43
44
# File 'lib/google_books_client/resources/volumes.rb', line 42

def self.list_by_lccn(lccn, params: {})
  list_volumes({ lccn: lccn }, params: params)
end

.list_by_oclc(oclc, params: {}) ⇒ Object



46
47
48
# File 'lib/google_books_client/resources/volumes.rb', line 46

def self.list_by_oclc(oclc, params: {})
  list_volumes({ oclc: oclc }, params: params)
end

.list_by_publisher(publisher, params: {}, start_index: 0) ⇒ Object



30
31
32
# File 'lib/google_books_client/resources/volumes.rb', line 30

def self.list_by_publisher(publisher, params: {}, start_index: 0)
  list_volumes({ publisher: publisher }, params: params, start_index: start_index)
end

.list_by_query(query, params: {}, start_index: 0) ⇒ Object



14
15
16
# File 'lib/google_books_client/resources/volumes.rb', line 14

def self.list_by_query(query, params: {}, start_index: 0)
  list(params.merge({ q: query, startIndex: start_index }))
end

.list_by_subject(subject, params: {}, start_index: 0) ⇒ Object



34
35
36
# File 'lib/google_books_client/resources/volumes.rb', line 34

def self.list_by_subject(subject, params: {}, start_index: 0)
  list_volumes({ subject: subject }, params: params, start_index: start_index)
end

.list_by_title(title, params: {}, start_index: 0) ⇒ Object



22
23
24
# File 'lib/google_books_client/resources/volumes.rb', line 22

def self.list_by_title(title, params: {}, start_index: 0)
  list_volumes({ title: title }, params: params, start_index: start_index)
end

.list_volumes(search_hash, params: {}, start_index: 0) ⇒ Object



18
19
20
# File 'lib/google_books_client/resources/volumes.rb', line 18

def self.list_volumes(search_hash, params: {}, start_index: 0)
  list_by_query(generate_query(search_hash), params: params, start_index: start_index)
end

.show(volume_id) ⇒ Object



6
7
8
# File 'lib/google_books_client/resources/volumes.rb', line 6

def self.show(volume_id)
  new.get("volumes/#{volume_id}")
end