lib/lol/request.rb in ruby-lol-0.9.12 vs lib/lol/request.rb in ruby-lol-0.9.13

- old
+ new

@@ -1,5 +1,7 @@ +require "uri" + module Lol class InvalidAPIResponse < StandardError; end class NotFound < StandardError; end class InvalidCacheStore < StandardError; end @@ -33,23 +35,29 @@ def api_url path, params = {} query_string = URI.encode_www_form params.merge api_key: api_key File.join "http://prod.api.pvp.net/api/lol/#{region}/#{self.class.api_version}/", "#{path}?#{query_string}" end + # Returns just a path from a full api url + # @return [String] + def clean_url(url) + URI.parse(url).path + end + # Calls the API via HTTParty and handles errors # @param url [String] the url to call # @return [String] raw response of the call def perform_request url - if cached? && result = store.get(url) + if cached? && result = store.get(clean_url(url)) return JSON.parse(result) end response = self.class.get(url) raise NotFound.new("404 Not Found") if response.respond_to?(:code) && response.not_found? raise InvalidAPIResponse.new(response["status"]["message"]) if response.is_a?(Hash) && response["status"] if cached? - store.set url, response.to_json + store.set clean_url(url), response.to_json store.expire url, ttl end response end