Class: ItunesSearch::Search

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(search_type, query, media, entity, limit) ⇒ Search

Returns a new instance of Search.



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

def initialize(search_type, query, media, entity, limit)
  self.search_type = search_type
  self.query = query
  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/search.rb', line 4

def entity
  @entity
end

#jsonObject

Returns the value of attribute json.



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

def json
  @json
end

#limitObject

Returns the value of attribute limit.



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

def limit
  @limit
end

#mediaObject

Returns the value of attribute media.



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

def media
  @media
end

#queryObject

Returns the value of attribute query.



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

def query
  @query
end

#result_hashObject

Returns the value of attribute result_hash.



4
5
6
# File 'lib/itunes-search/search.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/search.rb', line 4

def search_type
  @search_type
end

Instance Method Details

#fetchObject



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

def fetch
  itunes_search_url = "#{ItunesSearch::ENDPOINT}/search/?#{self.search_type}=#{self.query}&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/search.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/search.rb', line 29

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