Class: KpApi::GlobalSearch

Inherits:
Agent
  • Object
show all
Defined in:
lib/kp_api/global_search.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(keyword) ⇒ GlobalSearch

Returns a new instance of GlobalSearch.



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

def initialize(keyword)
  @keyword = URI.encode(keyword)
  @url     = "#{DOMAINS[:api]}#{METHODS[:search_global][:method]}?#{METHODS[:search_global][:keyword]}=#{@keyword}"
  @json    = json

  unless status
    raise ApiError.new(@json[:message], @json[:data])
  end
end

Instance Attribute Details

#keywordObject

Returns the value of attribute keyword.



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

def keyword
  @keyword
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#filmsObject



39
40
41
42
43
44
45
# File 'lib/kp_api/global_search.rb', line 39

def films
  unless @json['searchFilms'].nil?
    @json['searchFilms'].map do |film|
      film_hash(film, 'id')
    end
  end
end

#films_countObject



19
20
21
22
23
24
25
# File 'lib/kp_api/global_search.rb', line 19

def films_count
  if @json['searchFilmsCountResult'].nil?
    0
  else
    @json['searchFilmsCountResult']
  end
end

#found?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/kp_api/global_search.rb', line 15

def found?
  films_count != 0  || peoples_count != 0
end

#peoplesObject



47
48
49
50
51
52
53
# File 'lib/kp_api/global_search.rb', line 47

def peoples
  unless @json['searchPeople'].nil?
    @json['searchPeople'].map do |name|
      people_hash(name)
    end
  end
end

#peoples_countObject



27
28
29
30
31
32
33
# File 'lib/kp_api/global_search.rb', line 27

def peoples_count
  if @json['searchPeoplesCountResult'].nil?
    0
  else
    @json['searchPeoplesCountResult']
  end
end

#youmeanObject



35
36
37
# File 'lib/kp_api/global_search.rb', line 35

def youmean
  film_hash(@json['youmean'], 'id')
end