Class: IceAndFireApi::Character

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Character

Returns a new instance of Character.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ice_and_fire_api/character.rb', line 8

def initialize(attributes)
  @url = attributes['url']
  @name = attributes['name']
  @gender = attributes['gender']
  @culture = attributes['culture']
  @born = attributes['born']
  @died = attributes['died']
  @titles = attributes['titles']
  @aliases = attributes['aliases']
  @father = attributes['father']
  @mother = attributes['mother']
  @spouse = attributes['spouse']
  @allegiances = attributes['allegiances']
  @books = attributes['books']
  @pov_books = attributes['povBooks']
  @tv_series = attributes['tvSeries']
  @played_by = attributes['playedBy']
end

Instance Attribute Details

#aliasesObject (readonly)

Returns the value of attribute aliases.



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

def aliases
  @aliases
end

#allegiancesObject (readonly)

Returns the value of attribute allegiances.



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

def allegiances
  @allegiances
end

#booksObject (readonly)

Returns the value of attribute books.



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

def books
  @books
end

#bornObject (readonly)

Returns the value of attribute born.



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

def born
  @born
end

#cultureObject (readonly)

Returns the value of attribute culture.



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

def culture
  @culture
end

#diedObject (readonly)

Returns the value of attribute died.



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

def died
  @died
end

#fatherObject (readonly)

Returns the value of attribute father.



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

def father
  @father
end

#genderObject (readonly)

Returns the value of attribute gender.



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

def gender
  @gender
end

#motherObject (readonly)

Returns the value of attribute mother.



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

def mother
  @mother
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#played_byObject (readonly)

Returns the value of attribute played_by.



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

def played_by
  @played_by
end

#pov_booksObject (readonly)

Returns the value of attribute pov_books.



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

def pov_books
  @pov_books
end

#spouseObject (readonly)

Returns the value of attribute spouse.



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

def spouse
  @spouse
end

#titlesObject (readonly)

Returns the value of attribute titles.



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

def titles
  @titles
end

#tv_seriesObject (readonly)

Returns the value of attribute tv_series.



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

def tv_series
  @tv_series
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.find(id) ⇒ Object



27
28
29
30
31
# File 'lib/ice_and_fire_api/character.rb', line 27

def self.find(id)
  response = Faraday.get("#{IceAndFireApi::API_URL}/characters/#{id}")
  attributes = JSON.parse(response.body)
  new(attributes)
end

.find_by_name(name) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/ice_and_fire_api/character.rb', line 33

def self.find_by_name(name)
  name_query = URI.encode_www_form_component(name.to_s)
  response = Faraday.get("#{IceAndFireApi::API_URL}/characters?name=#{name_query}")
  attributes_response = JSON.parse(response.body)
  attributes_array = []
  attributes_response.each do |attributes|
    attributes_array << new(attributes)
  end
  attributes_array
end