Class: IceAndFireApi::Book

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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']
  @authors = 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

#authorsObject (readonly)

Returns the value of attribute authors.



3
4
5
# File 'lib/ice_and_fire_api/book.rb', line 3

def authors
  @authors
end

#charactersObject (readonly)

Returns the value of attribute characters.



3
4
5
# File 'lib/ice_and_fire_api/book.rb', line 3

def characters
  @characters
end

#countryObject (readonly)

Returns the value of attribute country.



3
4
5
# File 'lib/ice_and_fire_api/book.rb', line 3

def country
  @country
end

#isbnObject (readonly)

Returns the value of attribute isbn.



3
4
5
# File 'lib/ice_and_fire_api/book.rb', line 3

def isbn
  @isbn
end

#mediaTypeObject (readonly)

Returns the value of attribute mediaType.



3
4
5
# File 'lib/ice_and_fire_api/book.rb', line 3

def mediaType
  @mediaType
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/ice_and_fire_api/book.rb', line 3

def name
  @name
end

#numberOfPagesObject (readonly)

Returns the value of attribute numberOfPages.



3
4
5
# File 'lib/ice_and_fire_api/book.rb', line 3

def numberOfPages
  @numberOfPages
end

#povCharactersObject (readonly)

Returns the value of attribute povCharacters.



3
4
5
# File 'lib/ice_and_fire_api/book.rb', line 3

def povCharacters
  @povCharacters
end

#publisherObject (readonly)

Returns the value of attribute publisher.



3
4
5
# File 'lib/ice_and_fire_api/book.rb', line 3

def publisher
  @publisher
end

#releasedObject (readonly)

Returns the value of attribute released.



3
4
5
# File 'lib/ice_and_fire_api/book.rb', line 3

def released
  @released
end

#urlObject (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