class RiotAPI::Client

This class is what handles the requests to the API.

Constants

VERSION

API Version. Be aware that this is only a default value. It CAN be overriden within the methods.

Public Class Methods

get(region, resource, options={}) click to toggle source

Issues a GET request the the API. Pass in the region, and resource as well as optional query params. It will return a Hash of the JSON data

# File lib/riot_api/client.rb, line 11
def self.get(region, resource, options={})
        region.downcase!
        options.merge!({api_key: RiotAPI::API_KEY})
        url = "http://prod.api.pvp.net/api/lol/#{region}/#{VERSION}/#{resource}"
        response = HTTParty.get(url, query: options)
        if response.code == 200
                JSON.parse(response.body)
        else
                nil
        end
end
post(region, resource, options={}) click to toggle source

Issues a POST request the the API. Pass in the region, and resource as well as optional query params. It will return a Hash of the JSON data

# File lib/riot_api/client.rb, line 25
def self.post(region, resource, options={})
        region.downcase!
        options.merge!({api_key: RiotAPI::API_KEY})
        url = "http://prod.api.pvp.net/api/lol/#{region}/#{version}/#{resource}"
        response = HTTParty.post(url, query: options)
        if response.code == 200
                JSON.parse(response.body)
        else
                throw InvalidAPIRequest, response.message
        end
end