Class: ItunesSearch::Lookup

Inherits:
Object
  • Object
show all
Defined in:
lib/itunes-search/lookup.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(search_type, id, media, entity, limit) ⇒ Lookup

Returns a new instance of Lookup.



7
8
9
10
11
12
13
# File 'lib/itunes-search/lookup.rb', line 7

def initialize(search_type, id, media, entity, limit)
  self.search_type = search_type
  self.id = id
  self.media = media
  self.entity = entity
  self.limit = limit
end

Instance Attribute Details

#entityObject

Returns the value of attribute entity.



4
5
6
# File 'lib/itunes-search/lookup.rb', line 4

def entity
  @entity
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/itunes-search/lookup.rb', line 4

def id
  @id
end

#jsonObject

Returns the value of attribute json.



4
5
6
# File 'lib/itunes-search/lookup.rb', line 4

def json
  @json
end

#limitObject

Returns the value of attribute limit.



4
5
6
# File 'lib/itunes-search/lookup.rb', line 4

def limit
  @limit
end

#mediaObject

Returns the value of attribute media.



4
5
6
# File 'lib/itunes-search/lookup.rb', line 4

def media
  @media
end

#result_hashObject

Returns the value of attribute result_hash.



4
5
6
# File 'lib/itunes-search/lookup.rb', line 4

def result_hash
  @result_hash
end

#search_typeObject

Returns the value of attribute search_type.



4
5
6
# File 'lib/itunes-search/lookup.rb', line 4

def search_type
  @search_type
end

Instance Method Details

#fetchObject



14
15
16
17
18
19
20
# File 'lib/itunes-search/lookup.rb', line 14

def fetch
  itunes_search_url = "#{ItunesSearch::ENDPOINT}/lookup/?#{self.search_type}=#{self.id}&media=#{media}&entity=#{entity}&limit=#{limit}"
  puts "itunes_search_url: #{itunes_search_url}"
  self.json = RestClient.get(itunes_search_url)
  puts self.json
  self.json
end

#resultsObject



21
22
23
24
25
26
27
# File 'lib/itunes-search/lookup.rb', line 21

def results
  ra = []
  ra = self.to_hash["results"].collect {|r| ItunesSearch::Result.new(r)} unless self.to_hash["results"].empty?
  puts "result"
  puts ra.inspect
  return ra
end

#to_hashObject



29
30
31
# File 'lib/itunes-search/lookup.rb', line 29

def to_hash
  self.result_hash ||= JSON.parse(fetch)
end