Skip to content

Instantly share code, notes, and snippets.

@nblackburn87
Created January 24, 2016 21:42
Show Gist options
  • Save nblackburn87/917c00a6b306bfc83b1d to your computer and use it in GitHub Desktop.
Save nblackburn87/917c00a6b306bfc83b1d to your computer and use it in GitHub Desktop.
class RiotApi
require 'logger'
include HTTParty
base_uri "https://na.api.pvp.net/api/lol"
logger ::Logger.new("httparty.log"), :debug, :curl
attr_accessor :id, :name, :profileIconId, :summonerLevel, :revisionDate, :pages, :summonerId
def initialize(id, name, profileIconId, summonerLevel, revisionDate, pages, summonerId)
self.id = id
self.name = name
self.profileIconId = profileIconId
self.summonerLevel = summonerLevel
self.revisionDate = revisionDate
self.pages = pages
self.summonerId = summonerId
end
def self.find(name)
response = get("/na/v1.4/summoner/by-name/#{name}?api_key=#{Rails.application.secrets.riot_api_key}")
if response.success?
self.new(response[name]["id"], response[name]["name"], response[name]["profileIconId"],
response[name]["summonerLevel"], response[name]["revisionDate"])
else
raise response.response.code + " " + response.response.message
end
end
def self.masteries(name)
page_names = []
page_masteries = []
summoner = self.find(name)
response = get("/na/v1.4/summoner/#{summoner.id}/masteries?api_key=#{Rails.application.secrets.riot_api_key}")
if response.success?
self.new(response.parsed_response[summoner.id.to_s]["pages"],
response.parsed_response[summoner.id.to_s]["summonerId"])
else
rails response.response.code + " " + response.response.message
end
# mastery_pages.each do |page|
# page_names << page["name"]
# page["masteries"].each do |mastery|
# masteries << mastery
# page_masteries << masteries
# end
# end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment