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) ⇒ Search

Returns a new instance of Search.



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

def initialize(search_type, query)
  self.search_type = search_type
  self.query = query
end

Instance Attribute Details

#jsonObject

Returns the value of attribute json.



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

def json
  @json
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



11
12
13
14
15
16
17
# File 'lib/itunes-search/search.rb', line 11

def fetch
  itunes_search_url = "#{ItunesSearch::ENDPOINT}/?#{self.search_type}=#{self.query}"
  puts "itunes_search_url: #{itunes_search_url}"
  self.json = RestClient.get(itunes_search_url)
  puts self.json
  self.json
end

#resultsObject



18
19
20
21
22
23
24
# File 'lib/itunes-search/search.rb', line 18

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



26
27
28
# File 'lib/itunes-search/search.rb', line 26

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