Last active
August 29, 2015 14:18
-
-
Save elle/715ec38238bf0877543a to your computer and use it in GitHub Desktop.
cipher-movies-sugestions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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