Class: KpApi::People

Inherits:
Agent
  • Object
show all
Defined in:
lib/kp_api/people.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Agent

#arr_data, #bool_data, #current_page, #data, #data2, #dn, #film_hash, #int_data, #json, #json2, #min_data, #next_page, #page_count, #people_hash, #s2a, #status, #status2, #str_data, #time_data, #url_data, #year_data

Constructor Details

#initialize(id) ⇒ People

Returns a new instance of People.



5
6
7
8
9
10
11
12
13
# File 'lib/kp_api/people.rb', line 5

def initialize(id)
  @id = id.to_i
  @url = "#{DOMAINS[:api]}#{METHODS[:get_people][:method]}?#{METHODS[:get_people][:id]}=#{id}"
  @json = json

  if !status || (@json['nameRU'] == "" && @json["nameEN"] == "" && @json["sex"] == nil)
    raise ApiError.new(@json[:mesage], @json[:data])
  end
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/kp_api/people.rb', line 3

def id
  @id
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/kp_api/people.rb', line 3

def url
  @url
end

Instance Method Details

#film_idsObject



51
52
53
# File 'lib/kp_api/people.rb', line 51

def film_ids
  filmography.map {|film| int_data(String, film['filmID']) }
end

#filmsObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/kp_api/people.rb', line 31

def films
  if filmography.nil?
    []
  else
    filmography.map do |film|
      {
        :id                 =>  int_data(String, film['filmID'         ]),
        :rating             =>  int_data(String, film['rating'         ], nil, Float),
        :rating_vote_count  =>  int_data(String, film['ratingVoteCount']),
        :description        =>  str_data(String, film['description'    ]),
        :profession_text    =>  str_data(String, film['professionText ']),
        :profession_key     =>  str_data(String, film['professionKey'  ]),
        :name_ru            =>  str_data(String, film['nameRU'         ]),
        :name_en            =>  str_data(String, film['nameEN'         ]),
        :year               =>  int_data(String, film['year'           ])
      }
    end
  end
end

#viewObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/kp_api/people.rb', line 15

def view
  {
    :id          => @id,
    :kp_type     => str_data(nil, 'class'),
    :name_ru     => str_data(nil, 'nameRU'),
    :name_en     => str_data(nil, 'nameEN'),
    :poster_url  => url_data(nil, 'posterURL', @id, :name),
    :sex         => str_data(nil, 'sex'),
    :growth      => int_data(nil, 'growth'),
    :birthday    => time_data(nil, 'birthday'),
    :birthplace  => str_data(nil, 'birthplace'),
    :has_awards  => bool_data(nil, 'has_awards'),
    :profession  => s2a(str_data(nil, 'profession'))
  }
end