Class: Aladin::Books

Inherits:
Array
  • Object
show all
Defined in:
lib/aladin/books.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Books

Returns a new instance of Books.



50
51
52
53
54
55
56
57
58
# File 'lib/aladin/books.rb', line 50

def initialize(hash)
  if hash["errorCode"]
    set_error(hash)
  else
    set_page_info(hash)

    super hash["item"].map {|i| Book.new(i)}
  end
end

Class Attribute Details

.per_pageObject

Returns the value of attribute per_page.



5
6
7
# File 'lib/aladin/books.rb', line 5

def per_page
  @per_page
end

.ttb_keyObject

Returns the value of attribute ttb_key.



5
6
7
# File 'lib/aladin/books.rb', line 5

def ttb_key
  @ttb_key
end

Instance Attribute Details

#error_codeObject

Returns the value of attribute error_code.



48
49
50
# File 'lib/aladin/books.rb', line 48

def error_code
  @error_code
end

#error_msgObject

Returns the value of attribute error_msg.



48
49
50
# File 'lib/aladin/books.rb', line 48

def error_msg
  @error_msg
end

#pageObject

Returns the value of attribute page.



48
49
50
# File 'lib/aladin/books.rb', line 48

def page
  @page
end

#per_pageObject

Returns the value of attribute per_page.



48
49
50
# File 'lib/aladin/books.rb', line 48

def per_page
  @per_page
end

#totalObject

Returns the value of attribute total.



48
49
50
# File 'lib/aladin/books.rb', line 48

def total
  @total
end

Class Method Details

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Aladin::Books)

    the object that the method was called on



6
7
8
# File 'lib/aladin/books.rb', line 6

def configure
  yield self
end

.search(query, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/aladin/books.rb', line 10

def search(query, options={})
  set_query(query, options)
  res = Net::HTTP.get_response(uri)
  if res.is_a?(Net::HTTPSuccess)
    body = res.body.gsub(/;?/, "")
    hash = JSON.parse(body) rescue JSON.parse(body.gsub("'", '"'))

    Books.new(hash)
  end
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/aladin/books.rb', line 60

def error?
  @error_code.present?
end