Skip to content

Instantly share code, notes, and snippets.

@elle
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elle/715ec38238bf0877543a to your computer and use it in GitHub Desktop.
Save elle/715ec38238bf0877543a to your computer and use it in GitHub Desktop.
cipher-movies-sugestions
require "json"
require "net/http"
class DataRetriever
include ActiveModel::Model
attr_reader :search_param, :search_by_id
def get_data(search_param, options = {})
@search_by_id = options.fetch([:search_by_id], false)
@search_info = search_info
response
end
private
def response
JSON.parse(net_http_call).with_indifferent_access
end
def net_http_call
Net::HTTP.get URI(url)
end
def url
if search_by_id?
search_by_id_url
else
search_movies_url
end
end
def search_movies_url
"https://itunes.apple.com/search?term=#{search_words}&entity=movie"
end
def search_by_id_url
"https://itunes.apple.com/lookup?id=#{search_param}"
end
def search_words
search_param.strip.gsub(" ", "+")
end
def search_by_id?
search_by_id
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment