Class: KpApi::LiveSearch

Inherits:
Agent
  • Object
show all
Defined in:
lib/kp_api/live_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) ⇒ LiveSearch

Returns a new instance of LiveSearch.



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

def initialize(keyword)
  @keyword = URI.encode(keyword)
  @url     = "#{DOMAINS[:api]}#{METHODS[:search_live][:method]}?#{METHODS[:search_live][: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/live_search.rb', line 3

def keyword
  @keyword
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#found?Boolean

Returns:

  • (Boolean)


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

def found?
  !@json['items'].nil?
end

#itemsObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/kp_api/live_search.rb', line 19

def items
  if found?
    @json['items'].map{|item|
      if item['type'] == "KPFilmObject"
        film_hash(item, 'id')
      elsif item['type'] == "KPPeopleObject"
        people_hash(item)
      end
    }.compact
  end
end