Class: Booksr

Inherits:
Object
  • Object
show all
Defined in:
lib/booksr.rb

Class Method Summary collapse

Class Method Details

.search(query_string, query_type = :keyword) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/booksr.rb', line 9

def self.search(query_string, query_type = :keyword)
	accepted_type = [:title, :author, :isbn, :keyword]
	if !accepted_type.include?(query_type)
		return nil
	end

	api = ApiHandler.new
	parser = Parser.new
	books = Array.new

	responses = api.search_by_google(query_string, query_type)
	responses.each do |response|
		volumes = parser.parse_json(response)
		
		volumes.each do |volume|
			volume_info = volume["volumeInfo"]
	        books.push(Book.new(parser.parse_info_from_google(volume_info)))
		end
	end

	return books
end