lib/itunes_api/request.rb in itunes_api-0.0.3 vs lib/itunes_api/request.rb in itunes_api-0.0.4

- old
+ new

@@ -2,18 +2,39 @@ require 'json' module ItunesApi # Allow requests to the iTunes API. module Request + + def response + JSON.parse(request) + end + + private + def request @request ||= open(url).read end - def response - JSON.parse(request) + def query + Addressable::URI.new( + query_values: query_values + ).query end + def query_values + { + country: COUNTRY_CODE, + limit: LIMIT, + media: 'music' + } + end + def results response.fetch('results', []) + end + + def url + "#{BASE_URL}/search?#{query}" end end end