added leagues call
This commit is contained in:
29
.gitignore
vendored
29
.gitignore
vendored
@@ -6,6 +6,35 @@ spec/reports
|
|||||||
test/tmp
|
test/tmp
|
||||||
test/version_tmp
|
test/version_tmp
|
||||||
tmp
|
tmp
|
||||||
|
*.gem
|
||||||
|
*.rbc
|
||||||
|
/.config
|
||||||
|
/coverage/
|
||||||
|
/InstalledFiles
|
||||||
|
/pkg/
|
||||||
|
/spec/reports/
|
||||||
|
/test/tmp/
|
||||||
|
/test/version_tmp/
|
||||||
|
/tmp/
|
||||||
|
|
||||||
|
## Documentation cache and generated files:
|
||||||
|
/.yardoc/
|
||||||
|
/_yardoc/
|
||||||
|
/doc/
|
||||||
|
/rdoc/
|
||||||
|
|
||||||
|
## Environment normalisation:
|
||||||
|
/.bundle/
|
||||||
|
/lib/bundler/man/
|
||||||
|
|
||||||
|
# for a library or gem, you might want to ignore these files since the code is
|
||||||
|
# intended to run in multiple environments; otherwise, check them in:
|
||||||
|
# Gemfile.lock
|
||||||
|
# .ruby-version
|
||||||
|
# .ruby-gemset
|
||||||
|
|
||||||
|
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
||||||
|
.rvmrc
|
||||||
|
|
||||||
# YARD artifacts
|
# YARD artifacts
|
||||||
.yardoc
|
.yardoc
|
||||||
|
|||||||
@@ -3,10 +3,11 @@ require 'JSON'
|
|||||||
require 'sightstone/modules/champion_module'
|
require 'sightstone/modules/champion_module'
|
||||||
require 'sightstone/modules/summoner_module'
|
require 'sightstone/modules/summoner_module'
|
||||||
require 'sightstone/modules/game_module'
|
require 'sightstone/modules/game_module'
|
||||||
|
require 'sightstone/modules/league_module'
|
||||||
|
|
||||||
class Sightstone
|
class Sightstone
|
||||||
attr_accessor :region, :api_key
|
attr_accessor :region, :api_key
|
||||||
attr_accessor :summoner, :champion, :game
|
attr_accessor :summoner, :champion, :game, :league
|
||||||
|
|
||||||
def initialize(api_key, region)
|
def initialize(api_key, region)
|
||||||
@api_key = api_key
|
@api_key = api_key
|
||||||
@@ -15,6 +16,7 @@ class Sightstone
|
|||||||
@summoner = SummonerModule.new(self)
|
@summoner = SummonerModule.new(self)
|
||||||
@champion = ChampionModule.new(self)
|
@champion = ChampionModule.new(self)
|
||||||
@game = GameModule.new(self)
|
@game = GameModule.new(self)
|
||||||
|
@league = LeagueModule.new(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
48
lib/sightstone/league.rb
Normal file
48
lib/sightstone/league.rb
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
class League
|
||||||
|
attr_accessor :entries, :name, :queue, :tier, :timestamp
|
||||||
|
|
||||||
|
def initialize(data)
|
||||||
|
@name = data['name']
|
||||||
|
@queue = data['queue']
|
||||||
|
@tier = data['tier']
|
||||||
|
@timestamp = data['timestamp']
|
||||||
|
@entries = []
|
||||||
|
data['entries'].each do |entry|
|
||||||
|
@entries << LeagueItem.new(entry)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class LeagueItem
|
||||||
|
attr_accessor :isFreshBlood, :isHotStreak, :isActive, :isVeteran, :lastPlayed, :leagueName, :leaguePoints, :losses, :miniSeries, :playerOrTeamId, :playerOrTeamName, :queueType, :rank, :tier, :timeUntilDecay, :wins
|
||||||
|
|
||||||
|
def initialize(data)
|
||||||
|
@isFreshBlood=data['isFreshBlood']
|
||||||
|
@isHotStreak=data['isHotStreak']
|
||||||
|
@isActive=data['isActive']
|
||||||
|
@isVeteran=data['isVeteran']
|
||||||
|
@lastPlayed=data['lastPlayed']
|
||||||
|
@leagueName=data['leageuName']
|
||||||
|
@leaguePoints=data['leaguePoints']
|
||||||
|
@losses=data['losses']
|
||||||
|
@miniSeries= MiniSeries.new(data['miniSeries']) if data.has_key? 'miniSeries'
|
||||||
|
@playerOrTeamId=data['playerOrTeamId']
|
||||||
|
@playerOrTeamName=data['playerOrTeamName']
|
||||||
|
@queueType=data['queueType']
|
||||||
|
@rank=data['rank']
|
||||||
|
@tier=data['tier']
|
||||||
|
@timeUntilDecay=data['timeUntilDecay']
|
||||||
|
@wins=data['wins']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class MiniSeries
|
||||||
|
attr_accessor :losses, :wins, :target, :progress, :timeLeftToPlayMillis
|
||||||
|
def initialize(data)
|
||||||
|
@losses = data['losses']
|
||||||
|
@wins = data['wins']
|
||||||
|
@target = data['target']
|
||||||
|
@progress = data['progress']
|
||||||
|
@timeLeftToPlayMillis = data['timeLeftToPlayMillies']
|
||||||
|
end
|
||||||
|
end
|
||||||
53
lib/sightstone/modules/league_module.rb
Normal file
53
lib/sightstone/modules/league_module.rb
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
require 'sightstone/summoner'
|
||||||
|
require 'sightstone/league'
|
||||||
|
|
||||||
|
class LeagueModule
|
||||||
|
def initialize(sightstone)
|
||||||
|
@sightstone = sightstone
|
||||||
|
end
|
||||||
|
|
||||||
|
def league(summoner)
|
||||||
|
id = if summoner.is_a? Summoner
|
||||||
|
summoner.id
|
||||||
|
else
|
||||||
|
summoner
|
||||||
|
end
|
||||||
|
|
||||||
|
uri = "http://prod.api.pvp.net/api/#{@sightstone.region}/v2.1/league/by-summoner/#{id}"
|
||||||
|
response = _get_api_response(uri)
|
||||||
|
_parse_response(response) { |resp|
|
||||||
|
data = JSON.parse(resp)
|
||||||
|
leagueKeys = data.keys
|
||||||
|
leagues = []
|
||||||
|
leagueKeys.each do |key|
|
||||||
|
leagues << League.new(data[key])
|
||||||
|
end
|
||||||
|
return leagues
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def _get_api_response(uri)
|
||||||
|
params = {'api_key' => @sightstone.api_key}
|
||||||
|
RestClient.get(uri, headers={:params => params}) {|response, request, result| response }
|
||||||
|
rescue SocketError => e
|
||||||
|
nil
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def _parse_response(response, &block)
|
||||||
|
response_code = if response.nil?
|
||||||
|
500
|
||||||
|
else
|
||||||
|
response.code
|
||||||
|
end
|
||||||
|
if response_code == 200
|
||||||
|
block.call(response.body)
|
||||||
|
elsif response_code == 404
|
||||||
|
raise Sightstone::SummonerNotFoundException
|
||||||
|
elsif response_code == 500
|
||||||
|
raise Sightstone::SightstoneConnectionException
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user