class HearthstoneCardApi::Caller
Attributes
api_key[RW]
api_url[RW]
collectible[RW]
filters[RW]
Public Class Methods
new(args={})
click to toggle source
# File lib/hearthstone_card_api/caller.rb, line 6 def initialize(args={}) @api_key = HearthstoneCardApi.api_key @api_url = "https://omgvamp-hearthstone-v1.p.mashape.com/" @collectible = "1" @filters = {cost: nil, attack: nil, health: nil, durability: nil} end
Public Instance Methods
return_cards(args={})
click to toggle source
# File lib/hearthstone_card_api/caller.rb, line 14 def return_cards(args={}) url = add_filters_to_url(args) api_response(endpoint(url)) end
return_info(url)
click to toggle source
# File lib/hearthstone_card_api/caller.rb, line 19 def return_info(url) api_response(endpoint(url)) end
Private Instance Methods
add_filters_to_url(args={})
click to toggle source
# File lib/hearthstone_card_api/caller.rb, line 24 def add_filters_to_url(args={}) url = args[:url] arg_filters = args[:filters] || {} arg_collectible = args[:collectible] || "1" url += "?" url += "&collectible=#{arg_collectible}" arg_filters.each do |key, value| if !value.nil? url += "&#{key}=#{value}" end end return url end
api_response(url_param)
click to toggle source
# File lib/hearthstone_card_api/caller.rb, line 38 def api_response(url_param) url = url_param response = Unirest.get url, headers:{ "X-Mashape-Key" => api_key} data = HearthstoneCardApi::Data.new(response) return data.formatted end
endpoint(url_param)
click to toggle source
# File lib/hearthstone_card_api/caller.rb, line 47 def endpoint(url_param) api_url + url_param end