Sha256: d166ec4d70db4da3f2041ec2c0c337ead6a6bf9abaf7bd999d68042e58d67b58

Contents?: true

Size: 978 Bytes

Versions: 1

Compression:

Stored size: 978 Bytes

Contents

module ItunesSearch
  
  class Lookup
    attr_accessor :id, :media, :entity, :limit, :result_hash, :json, :search_type
    alias :original_method_missing :method_missing
    
    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
    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
    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
    
    def to_hash
      self.result_hash ||= JSON.parse(fetch)
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
itunes-search-rb-0.3.4 lib/itunes-search/lookup.rb