added ratelimit exception
This commit is contained in:
@@ -30,3 +30,5 @@ class SightstoneApiException < Exception; end
|
|||||||
class SummonerNotFoundException < SightstoneApiException; end
|
class SummonerNotFoundException < SightstoneApiException; end
|
||||||
|
|
||||||
class SightstoneConnectionException < SightstoneApiException; end
|
class SightstoneConnectionException < SightstoneApiException; end
|
||||||
|
|
||||||
|
class RateLimitExceededException < SightstoneApiException; end
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
require 'sightstone/champion'
|
require 'sightstone/champion'
|
||||||
|
require 'sightstone/modules/sightstone_base_module'
|
||||||
|
|
||||||
class ChampionModule
|
class ChampionModule < SightstoneBaseModule
|
||||||
|
|
||||||
def initialize(sightstone)
|
def initialize(sightstone)
|
||||||
@sightstone = sightstone
|
@sightstone = sightstone
|
||||||
@@ -20,28 +21,4 @@ class ChampionModule
|
|||||||
return champions
|
return champions
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
def _get_api_response(uri, headers={})
|
|
||||||
params = {'api_key' => @sightstone.api_key}.merge headers
|
|
||||||
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 == 500
|
|
||||||
raise Sightstone::SightstoneConnectionException
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
|
require 'sightstone/modules/sightstone_base_module'
|
||||||
require 'sightstone/summoner'
|
require 'sightstone/summoner'
|
||||||
require 'sightstone/match_history'
|
require 'sightstone/match_history'
|
||||||
|
|
||||||
class GameModule
|
class GameModule < SightstoneBaseModule
|
||||||
|
|
||||||
def initialize(sightstone)
|
def initialize(sightstone)
|
||||||
@sightstone = sightstone
|
@sightstone = sightstone
|
||||||
@@ -22,29 +23,5 @@ class GameModule
|
|||||||
}
|
}
|
||||||
end
|
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
|
end
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
|
require 'sightstone/modules/sightstone_base_module'
|
||||||
require 'sightstone/summoner'
|
require 'sightstone/summoner'
|
||||||
require 'sightstone/league'
|
require 'sightstone/league'
|
||||||
|
|
||||||
class LeagueModule
|
class LeagueModule < SightstoneBaseModule
|
||||||
def initialize(sightstone)
|
def initialize(sightstone)
|
||||||
@sightstone = sightstone
|
@sightstone = sightstone
|
||||||
end
|
end
|
||||||
@@ -26,28 +27,4 @@ class LeagueModule
|
|||||||
}
|
}
|
||||||
end
|
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
|
end
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
|
require 'sightstone/modules/sightstone_base_module'
|
||||||
require 'sightstone/summoner'
|
require 'sightstone/summoner'
|
||||||
require 'sightstone/player_stats_summary'
|
require 'sightstone/player_stats_summary'
|
||||||
require 'sightstone/ranked_stats'
|
require 'sightstone/ranked_stats'
|
||||||
|
|
||||||
class StatsModule
|
class StatsModule < SightstoneBaseModule
|
||||||
def initialize(sightstone)
|
def initialize(sightstone)
|
||||||
@sightstone = sightstone
|
@sightstone = sightstone
|
||||||
end
|
end
|
||||||
@@ -46,29 +47,4 @@ class StatsModule
|
|||||||
}
|
}
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def _get_api_response(uri, header={})
|
|
||||||
params = {'api_key' => @sightstone.api_key}.merge header
|
|
||||||
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
|
end
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
|
require 'sightstone/modules/sightstone_base_module'
|
||||||
require 'sightstone/summoner'
|
require 'sightstone/summoner'
|
||||||
require 'sightstone/masterybook'
|
require 'sightstone/masterybook'
|
||||||
require 'sightstone/runebook'
|
require 'sightstone/runebook'
|
||||||
|
|
||||||
class SummonerModule
|
class SummonerModule < SightstoneBaseModule
|
||||||
def initialize(sightstone)
|
def initialize(sightstone)
|
||||||
@sightstone = sightstone
|
@sightstone = sightstone
|
||||||
end
|
end
|
||||||
@@ -59,30 +60,4 @@ class SummonerModule
|
|||||||
return MasteryBook.new(data)
|
return MasteryBook.new(data)
|
||||||
}
|
}
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
require 'sightstone/modules/sightstone_base_module'
|
||||||
require 'sightstone/summoner'
|
require 'sightstone/summoner'
|
||||||
require 'sightstone/team'
|
require 'sightstone/team'
|
||||||
|
|
||||||
class TeamModule
|
class TeamModule < SightstoneBaseModule
|
||||||
def initialize(sightstone)
|
def initialize(sightstone)
|
||||||
@sightstone = sightstone
|
@sightstone = sightstone
|
||||||
end
|
end
|
||||||
@@ -26,31 +27,4 @@ class TeamModule
|
|||||||
}
|
}
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user