class Nashville::Client
Attributes
country[RW]
search_url[RW]
Public Class Methods
new()
click to toggle source
# File lib/nashville/client.rb, line 12 def initialize @search_url = ENV['ITUNES_SEARCH_ENDPOINT'] || ITUNES_SEARCH_ENDPOINT @country = 'US' end
Public Instance Methods
lookup(params = {})
click to toggle source
# File lib/nashville/client.rb, line 26 def lookup(params = {}) uri = URI.join(@search_url, "lookup") uri.query = URI.encode_www_form(params) json_response_from_uri(uri)["results"] end
search(params = {})
click to toggle source
# File lib/nashville/client.rb, line 17 def search(params = {}) params[:country] ||= @country uri = URI.join(@search_url, "search") uri.query = URI.encode_www_form(params) json_response_from_uri(uri)["results"] end
Private Instance Methods
json_response_from_uri(uri)
click to toggle source
# File lib/nashville/client.rb, line 35 def json_response_from_uri(uri) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_PEER request = Net::HTTP::Get.new(uri.request_uri) request['Accept'] = "application/json" response = http.request(request) JSON.parse(response.body) rescue nil end