Class: IceAndFireApi::Book
- Inherits:
-
Object
- Object
- IceAndFireApi::Book
- Defined in:
- lib/ice_and_fire_api/book.rb
Instance Attribute Summary collapse
-
#authors ⇒ Object
readonly
Returns the value of attribute authors.
-
#characters ⇒ Object
readonly
Returns the value of attribute characters.
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#isbn ⇒ Object
readonly
Returns the value of attribute isbn.
-
#mediaType ⇒ Object
readonly
Returns the value of attribute mediaType.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#numberOfPages ⇒ Object
readonly
Returns the value of attribute numberOfPages.
-
#povCharacters ⇒ Object
readonly
Returns the value of attribute povCharacters.
-
#publisher ⇒ Object
readonly
Returns the value of attribute publisher.
-
#released ⇒ Object
readonly
Returns the value of attribute released.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Book
constructor
A new instance of Book.
Constructor Details
#initialize(attributes) ⇒ Book
Returns a new instance of Book.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ice_and_fire_api/book.rb', line 7 def initialize(attributes) @url = attributes['url'] @name = attributes['name'] @isbn = attributes['isbn'] = attributes['authors'] @number_of_pages = attributes['numberOfPages'] @publisher = attributes['publisher'] @country = attributes['country'] @media_type = attributes['mediaType'] @released = attributes['released'] @characters = attributes['characters'] @pov_characters = attributes['povCharacters'] end |
Instance Attribute Details
#authors ⇒ Object (readonly)
Returns the value of attribute authors.
3 4 5 |
# File 'lib/ice_and_fire_api/book.rb', line 3 def end |
#characters ⇒ Object (readonly)
Returns the value of attribute characters.
3 4 5 |
# File 'lib/ice_and_fire_api/book.rb', line 3 def characters @characters end |
#country ⇒ Object (readonly)
Returns the value of attribute country.
3 4 5 |
# File 'lib/ice_and_fire_api/book.rb', line 3 def country @country end |
#isbn ⇒ Object (readonly)
Returns the value of attribute isbn.
3 4 5 |
# File 'lib/ice_and_fire_api/book.rb', line 3 def isbn @isbn end |
#mediaType ⇒ Object (readonly)
Returns the value of attribute mediaType.
3 4 5 |
# File 'lib/ice_and_fire_api/book.rb', line 3 def mediaType @mediaType end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/ice_and_fire_api/book.rb', line 3 def name @name end |
#numberOfPages ⇒ Object (readonly)
Returns the value of attribute numberOfPages.
3 4 5 |
# File 'lib/ice_and_fire_api/book.rb', line 3 def numberOfPages @numberOfPages end |
#povCharacters ⇒ Object (readonly)
Returns the value of attribute povCharacters.
3 4 5 |
# File 'lib/ice_and_fire_api/book.rb', line 3 def povCharacters @povCharacters end |
#publisher ⇒ Object (readonly)
Returns the value of attribute publisher.
3 4 5 |
# File 'lib/ice_and_fire_api/book.rb', line 3 def publisher @publisher end |
#released ⇒ Object (readonly)
Returns the value of attribute released.
3 4 5 |
# File 'lib/ice_and_fire_api/book.rb', line 3 def released @released end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
3 4 5 |
# File 'lib/ice_and_fire_api/book.rb', line 3 def url @url end |
Class Method Details
.find(id) ⇒ Object
21 22 23 24 25 |
# File 'lib/ice_and_fire_api/book.rb', line 21 def self.find(id) response = Faraday.get("#{IceAndFireApi::API_URL}/books/#{id}") attributes = JSON.parse(response.body) new(attributes) end |
.find_by_name(name) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ice_and_fire_api/book.rb', line 27 def self.find_by_name(name) name_query = URI.encode_www_form_component(name.to_s) response = Faraday.get("#{IceAndFireApi::API_URL}/books?name=#{name_query}") attributes_response = JSON.parse(response.body) attributes_array = [] attributes_response.each do |attributes| attributes_array << new(attributes) end attributes_array end |