Class: ItunesSearch::Lookup
- Inherits:
-
Object
- Object
- ItunesSearch::Lookup
- Defined in:
- lib/itunes-search/lookup.rb
Instance Attribute Summary collapse
-
#entity ⇒ Object
Returns the value of attribute entity.
-
#id ⇒ Object
Returns the value of attribute id.
-
#json ⇒ Object
Returns the value of attribute json.
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#media ⇒ Object
Returns the value of attribute media.
-
#result_hash ⇒ Object
Returns the value of attribute result_hash.
-
#search_type ⇒ Object
Returns the value of attribute search_type.
Instance Method Summary collapse
- #fetch ⇒ Object
-
#initialize(search_type, id, media, entity, limit) ⇒ Lookup
constructor
A new instance of Lookup.
- #results ⇒ Object
- #to_hash ⇒ Object
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
#entity ⇒ Object
Returns the value of attribute entity.
4 5 6 |
# File 'lib/itunes-search/lookup.rb', line 4 def entity @entity end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/itunes-search/lookup.rb', line 4 def id @id end |
#json ⇒ Object
Returns the value of attribute json.
4 5 6 |
# File 'lib/itunes-search/lookup.rb', line 4 def json @json end |
#limit ⇒ Object
Returns the value of attribute limit.
4 5 6 |
# File 'lib/itunes-search/lookup.rb', line 4 def limit @limit end |
#media ⇒ Object
Returns the value of attribute media.
4 5 6 |
# File 'lib/itunes-search/lookup.rb', line 4 def media @media end |
#result_hash ⇒ Object
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_type ⇒ Object
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
#fetch ⇒ Object
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 |
#results ⇒ Object
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_hash ⇒ Object
29 30 31 |
# File 'lib/itunes-search/lookup.rb', line 29 def to_hash self.result_hash ||= JSON.parse(fetch) end |