sightstone 1.4.3 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/sightstone.rb +60 -60
- data/lib/sightstone/champion.rb +31 -31
- data/lib/sightstone/league.rb +74 -74
- data/lib/sightstone/masterybook.rb +49 -49
- data/lib/sightstone/match_history.rb +76 -76
- data/lib/sightstone/modules/champion_module.rb +33 -33
- data/lib/sightstone/modules/datadragon_module.rb +25 -25
- data/lib/sightstone/modules/game_module.rb +38 -38
- data/lib/sightstone/modules/league_module.rb +68 -40
- data/lib/sightstone/modules/sightstone_base_module.rb +39 -39
- data/lib/sightstone/modules/stats_module.rb +75 -75
- data/lib/sightstone/modules/summoner_module.rb +205 -205
- data/lib/sightstone/modules/team_module.rb +42 -42
- data/lib/sightstone/player_stats_summary.rb +38 -38
- data/lib/sightstone/ranked_stats.rb +24 -24
- data/lib/sightstone/runebook.rb +51 -51
- data/lib/sightstone/summoner.rb +22 -22
- data/lib/sightstone/team.rb +116 -116
- metadata +5 -4
@@ -1,34 +1,34 @@
|
|
1
|
-
require 'sightstone/champion'
|
2
|
-
require 'sightstone/modules/sightstone_base_module'
|
3
|
-
module Sightstone
|
4
|
-
# Module to provide calls to the summoner api
|
5
|
-
class ChampionModule < SightstoneBaseModule
|
6
|
-
|
7
|
-
def initialize(sightstone)
|
8
|
-
@sightstone = sightstone
|
9
|
-
end
|
10
|
-
|
11
|
-
# call to get champions
|
12
|
-
# @param optional [Hash] optional arguments: :region => replaces default region, :free_to_play => boolean (only free to play champs if true)
|
13
|
-
# @return [Array<Champion>] array of champs
|
14
|
-
def champions(optional={})
|
15
|
-
region = optional[:region] || @sightstone.region
|
16
|
-
free_to_play = optional[:free_to_play]
|
17
|
-
uri = "https://prod.api.pvp.net/api/lol/#{region}/v1.1/champion"
|
18
|
-
response = _get_api_response(uri, {'freeToPlay' => free_to_play})
|
19
|
-
|
20
|
-
_parse_response(response) { |resp|
|
21
|
-
data = JSON.parse(resp)
|
22
|
-
champions = []
|
23
|
-
data['champions'].each do |champ|
|
24
|
-
champions << Champion.new(champ)
|
25
|
-
end
|
26
|
-
if block_given?
|
27
|
-
yield champions
|
28
|
-
else
|
29
|
-
return champions
|
30
|
-
end
|
31
|
-
}
|
32
|
-
end
|
33
|
-
end
|
1
|
+
require 'sightstone/champion'
|
2
|
+
require 'sightstone/modules/sightstone_base_module'
|
3
|
+
module Sightstone
|
4
|
+
# Module to provide calls to the summoner api
|
5
|
+
class ChampionModule < SightstoneBaseModule
|
6
|
+
|
7
|
+
def initialize(sightstone)
|
8
|
+
@sightstone = sightstone
|
9
|
+
end
|
10
|
+
|
11
|
+
# call to get champions
|
12
|
+
# @param optional [Hash] optional arguments: :region => replaces default region, :free_to_play => boolean (only free to play champs if true)
|
13
|
+
# @return [Array<Champion>] array of champs
|
14
|
+
def champions(optional={})
|
15
|
+
region = optional[:region] || @sightstone.region
|
16
|
+
free_to_play = optional[:free_to_play]
|
17
|
+
uri = "https://prod.api.pvp.net/api/lol/#{region}/v1.1/champion"
|
18
|
+
response = _get_api_response(uri, {'freeToPlay' => free_to_play})
|
19
|
+
|
20
|
+
_parse_response(response) { |resp|
|
21
|
+
data = JSON.parse(resp)
|
22
|
+
champions = []
|
23
|
+
data['champions'].each do |champ|
|
24
|
+
champions << Champion.new(champ)
|
25
|
+
end
|
26
|
+
if block_given?
|
27
|
+
yield champions
|
28
|
+
else
|
29
|
+
return champions
|
30
|
+
end
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
34
|
end
|
@@ -1,26 +1,26 @@
|
|
1
|
-
require 'sightstone/modules/sightstone_base_module'
|
2
|
-
module Sightstone
|
3
|
-
class DatadragonModule < SightstoneBaseModule
|
4
|
-
|
5
|
-
def initialize(sightstone)
|
6
|
-
@sightstone = sightstone
|
7
|
-
end
|
8
|
-
|
9
|
-
def version(optional={})
|
10
|
-
region = optional[:region] || @sightstone.region
|
11
|
-
uri = "https://ddragon.leagueoflegends.com/realms/#{region}.json"
|
12
|
-
|
13
|
-
response = _get_api_response(uri)
|
14
|
-
_parse_response(response) { |resp|
|
15
|
-
data = JSON.parse(resp)
|
16
|
-
if block_given?
|
17
|
-
yield data['v']
|
18
|
-
else
|
19
|
-
return data['v']
|
20
|
-
end
|
21
|
-
}
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
end
|
1
|
+
require 'sightstone/modules/sightstone_base_module'
|
2
|
+
module Sightstone
|
3
|
+
class DatadragonModule < SightstoneBaseModule
|
4
|
+
|
5
|
+
def initialize(sightstone)
|
6
|
+
@sightstone = sightstone
|
7
|
+
end
|
8
|
+
|
9
|
+
def version(optional={})
|
10
|
+
region = optional[:region] || @sightstone.region
|
11
|
+
uri = "https://ddragon.leagueoflegends.com/realms/#{region}.json"
|
12
|
+
|
13
|
+
response = _get_api_response(uri)
|
14
|
+
_parse_response(response) { |resp|
|
15
|
+
data = JSON.parse(resp)
|
16
|
+
if block_given?
|
17
|
+
yield data['v']
|
18
|
+
else
|
19
|
+
return data['v']
|
20
|
+
end
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
end
|
26
26
|
end
|
@@ -1,39 +1,39 @@
|
|
1
|
-
require 'sightstone/modules/sightstone_base_module'
|
2
|
-
require 'sightstone/summoner'
|
3
|
-
require 'sightstone/match_history'
|
4
|
-
module Sightstone
|
5
|
-
# module to access the game api
|
6
|
-
class GameModule < SightstoneBaseModule
|
7
|
-
|
8
|
-
def initialize(sightstone)
|
9
|
-
@sightstone = sightstone
|
10
|
-
end
|
11
|
-
|
12
|
-
# returns the match history of a summoner
|
13
|
-
# @param [Summoner, Fixnum] summoner summoner object or id of a summoner
|
14
|
-
# @param optional [Hash] optional arguments: :region => replaces default region
|
15
|
-
# @return [MatchHistory] match history of the summoner
|
16
|
-
def recent(summoner, optional={})
|
17
|
-
region = optional[:region] || @sightstone.region
|
18
|
-
id = if summoner.is_a? Summoner
|
19
|
-
summoner.id
|
20
|
-
else
|
21
|
-
summoner
|
22
|
-
end
|
23
|
-
uri = "https://prod.api.pvp.net/api/lol/#{region}/v1.3/game/by-summoner/#{id}/recent"
|
24
|
-
|
25
|
-
response = _get_api_response(uri)
|
26
|
-
_parse_response(response) { |resp|
|
27
|
-
data = JSON.parse(resp)
|
28
|
-
history = MatchHistory.new(data)
|
29
|
-
if block_given?
|
30
|
-
yield history
|
31
|
-
else
|
32
|
-
return history
|
33
|
-
end
|
34
|
-
}
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
end
|
1
|
+
require 'sightstone/modules/sightstone_base_module'
|
2
|
+
require 'sightstone/summoner'
|
3
|
+
require 'sightstone/match_history'
|
4
|
+
module Sightstone
|
5
|
+
# module to access the game api
|
6
|
+
class GameModule < SightstoneBaseModule
|
7
|
+
|
8
|
+
def initialize(sightstone)
|
9
|
+
@sightstone = sightstone
|
10
|
+
end
|
11
|
+
|
12
|
+
# returns the match history of a summoner
|
13
|
+
# @param [Summoner, Fixnum] summoner summoner object or id of a summoner
|
14
|
+
# @param optional [Hash] optional arguments: :region => replaces default region
|
15
|
+
# @return [MatchHistory] match history of the summoner
|
16
|
+
def recent(summoner, optional={})
|
17
|
+
region = optional[:region] || @sightstone.region
|
18
|
+
id = if summoner.is_a? Summoner
|
19
|
+
summoner.id
|
20
|
+
else
|
21
|
+
summoner
|
22
|
+
end
|
23
|
+
uri = "https://prod.api.pvp.net/api/lol/#{region}/v1.3/game/by-summoner/#{id}/recent"
|
24
|
+
|
25
|
+
response = _get_api_response(uri)
|
26
|
+
_parse_response(response) { |resp|
|
27
|
+
data = JSON.parse(resp)
|
28
|
+
history = MatchHistory.new(data)
|
29
|
+
if block_given?
|
30
|
+
yield history
|
31
|
+
else
|
32
|
+
return history
|
33
|
+
end
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
end
|
39
39
|
end
|
@@ -1,41 +1,69 @@
|
|
1
|
-
require 'sightstone/modules/sightstone_base_module'
|
2
|
-
require 'sightstone/summoner'
|
3
|
-
require 'sightstone/league'
|
4
|
-
|
5
|
-
module Sightstone
|
6
|
-
# module to provide calls to the league api
|
7
|
-
class LeagueModule < SightstoneBaseModule
|
8
|
-
def initialize(sightstone)
|
9
|
-
@sightstone = sightstone
|
10
|
-
end
|
11
|
-
|
12
|
-
# Provides league information of a summoner
|
13
|
-
# @param [Summoner, Integer] summoner
|
14
|
-
# @param optional [Hash] optional arguments: :region => replaces default region
|
15
|
-
# @return [Array<League>] an array of all leagues the summoner and his teams are in
|
16
|
-
def leagues(summoner, optional={})
|
17
|
-
region = optional[:region] || @sightstone.region
|
18
|
-
id = if summoner.is_a? Summoner
|
19
|
-
summoner.id
|
20
|
-
else
|
21
|
-
summoner
|
22
|
-
end
|
23
|
-
|
24
|
-
uri = "https://prod.api.pvp.net/api/lol/#{region}/v2.3/league/by-summoner/#{id}"
|
25
|
-
response = _get_api_response(uri)
|
26
|
-
_parse_response(response) { |resp|
|
27
|
-
data = JSON.parse(resp)
|
28
|
-
leagues = []
|
29
|
-
data.each do |league|
|
30
|
-
leagues << League.new(league)
|
31
|
-
end
|
32
|
-
if block_given?
|
33
|
-
yield leagues
|
34
|
-
else
|
35
|
-
return leagues
|
36
|
-
end
|
37
|
-
}
|
38
|
-
end
|
39
|
-
|
40
|
-
|
1
|
+
require 'sightstone/modules/sightstone_base_module'
|
2
|
+
require 'sightstone/summoner'
|
3
|
+
require 'sightstone/league'
|
4
|
+
|
5
|
+
module Sightstone
|
6
|
+
# module to provide calls to the league api
|
7
|
+
class LeagueModule < SightstoneBaseModule
|
8
|
+
def initialize(sightstone)
|
9
|
+
@sightstone = sightstone
|
10
|
+
end
|
11
|
+
|
12
|
+
# Provides league information of a summoner
|
13
|
+
# @param [Summoner, Integer] summoner
|
14
|
+
# @param optional [Hash] optional arguments: :region => replaces default region
|
15
|
+
# @return [Array<League>] an array of all leagues the summoner and his teams are in
|
16
|
+
def leagues(summoner, optional={})
|
17
|
+
region = optional[:region] || @sightstone.region
|
18
|
+
id = if summoner.is_a? Summoner
|
19
|
+
summoner.id
|
20
|
+
else
|
21
|
+
summoner
|
22
|
+
end
|
23
|
+
|
24
|
+
uri = "https://prod.api.pvp.net/api/lol/#{region}/v2.3/league/by-summoner/#{id}"
|
25
|
+
response = _get_api_response(uri)
|
26
|
+
_parse_response(response) { |resp|
|
27
|
+
data = JSON.parse(resp)
|
28
|
+
leagues = []
|
29
|
+
data.each do |league|
|
30
|
+
leagues << League.new(league)
|
31
|
+
end
|
32
|
+
if block_given?
|
33
|
+
yield leagues
|
34
|
+
else
|
35
|
+
return leagues
|
36
|
+
end
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
# Get all entries for the given summoner
|
41
|
+
# @param [Summoner, Integer] summoner or summoner id
|
42
|
+
# @param optional [Hash] optional arguments: :region => replaces default region
|
43
|
+
# @return [Array<LeagueItem>] an array of all entries for that given summoner
|
44
|
+
def league_entries(summoner, optional={})
|
45
|
+
region = optional[:region] || @sightstone.region
|
46
|
+
id = if summoner.is_a? Summoner
|
47
|
+
summoner.id
|
48
|
+
else
|
49
|
+
summoner
|
50
|
+
end
|
51
|
+
|
52
|
+
uri = "https://prod.api.pvp.net/api/lol/#{region}/v2.3/league/by-summoner/#{id}/entry"
|
53
|
+
response = _get_api_response(uri)
|
54
|
+
_parse_response(response) { |resp|
|
55
|
+
data = JSON.parse(resp)
|
56
|
+
entries = []
|
57
|
+
data.each do |entry|
|
58
|
+
entries << LeagueItem.new(entry)
|
59
|
+
end
|
60
|
+
if block_given?
|
61
|
+
yield entries
|
62
|
+
else
|
63
|
+
return entries
|
64
|
+
end
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
41
69
|
end
|
@@ -1,40 +1,40 @@
|
|
1
|
-
require 'open-uri'
|
2
|
-
module Sightstone
|
3
|
-
# Base class of the api modules
|
4
|
-
# @abstract
|
5
|
-
class SightstoneBaseModule
|
6
|
-
|
7
|
-
protected
|
8
|
-
def _get_api_response(uri, header={})
|
9
|
-
params = {'api_key' => @sightstone.api_key}.merge header
|
10
|
-
RestClient.get(uri, headers={:params => params}) {|response, request, result| response }
|
11
|
-
rescue SocketError => e
|
12
|
-
nil
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
def _parse_response(response, &block)
|
17
|
-
response_code = if response.nil?
|
18
|
-
500
|
19
|
-
else
|
20
|
-
response.code
|
21
|
-
end
|
22
|
-
|
23
|
-
if response_code == 200
|
24
|
-
block.call(response.body)
|
25
|
-
elsif response_code == 404
|
26
|
-
raise SummonerNotFoundException
|
27
|
-
elsif response_code == 500
|
28
|
-
raise SightstoneConnectionException
|
29
|
-
elsif response_code == 429
|
30
|
-
raise RateLimitExceededException
|
31
|
-
elsif response_code == 401
|
32
|
-
raise InvalidApiKeyException
|
33
|
-
else
|
34
|
-
raise SightstoneApiException
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
1
|
+
require 'open-uri'
|
2
|
+
module Sightstone
|
3
|
+
# Base class of the api modules
|
4
|
+
# @abstract
|
5
|
+
class SightstoneBaseModule
|
6
|
+
|
7
|
+
protected
|
8
|
+
def _get_api_response(uri, header={})
|
9
|
+
params = {'api_key' => @sightstone.api_key}.merge header
|
10
|
+
RestClient.get(uri, headers={:params => params}) {|response, request, result| response }
|
11
|
+
rescue SocketError => e
|
12
|
+
nil
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def _parse_response(response, &block)
|
17
|
+
response_code = if response.nil?
|
18
|
+
500
|
19
|
+
else
|
20
|
+
response.code
|
21
|
+
end
|
22
|
+
|
23
|
+
if response_code == 200
|
24
|
+
block.call(response.body)
|
25
|
+
elsif response_code == 404
|
26
|
+
raise SummonerNotFoundException
|
27
|
+
elsif response_code == 500
|
28
|
+
raise SightstoneConnectionException
|
29
|
+
elsif response_code == 429
|
30
|
+
raise RateLimitExceededException
|
31
|
+
elsif response_code == 401
|
32
|
+
raise InvalidApiKeyException
|
33
|
+
else
|
34
|
+
raise SightstoneApiException
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
40
|
end
|
@@ -1,76 +1,76 @@
|
|
1
|
-
|
2
|
-
require 'sightstone/modules/sightstone_base_module'
|
3
|
-
require 'sightstone/summoner'
|
4
|
-
require 'sightstone/player_stats_summary'
|
5
|
-
require 'sightstone/ranked_stats'
|
6
|
-
module Sightstone
|
7
|
-
# Module to receive stats
|
8
|
-
class StatsModule < SightstoneBaseModule
|
9
|
-
def initialize(sightstone)
|
10
|
-
@sightstone = sightstone
|
11
|
-
end
|
12
|
-
|
13
|
-
# get a summary of stats for a summoner
|
14
|
-
# @param [Summoner, Fixnum] summoner summoner object of name
|
15
|
-
# @param optional [Hash] optional arguments: :region => replaces default region
|
16
|
-
# @ return [PlayerStatsSummaryList] of the summoner
|
17
|
-
def summary(summoner, optional={})
|
18
|
-
region = optional[:region] || @sightstone.region
|
19
|
-
season = optional[:season]
|
20
|
-
|
21
|
-
id = if summoner.is_a? Summoner
|
22
|
-
summoner.id
|
23
|
-
else
|
24
|
-
summoner
|
25
|
-
end
|
26
|
-
uri = "https://prod.api.pvp.net/api/lol/#{region}/v1.2/stats/by-summoner/#{id}/summary"
|
27
|
-
response = if season.nil?
|
28
|
-
_get_api_response(uri)
|
29
|
-
else
|
30
|
-
_get_api_response(uri, {'season' => season})
|
31
|
-
end
|
32
|
-
|
33
|
-
_parse_response(response) { |resp|
|
34
|
-
data = JSON.parse(resp)
|
35
|
-
statList = PlayerStatsSummaryList.new(data)
|
36
|
-
if block_given?
|
37
|
-
yield statList
|
38
|
-
else
|
39
|
-
return statList
|
40
|
-
end
|
41
|
-
}
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
# get a summary of stats for a summoner
|
46
|
-
# @param [Summoner, Fixnum] summoner summoner object of name
|
47
|
-
# @param optional [Hash] optional arguments: :region => replaces default region
|
48
|
-
# @ return [RankedStats] of the summoner
|
49
|
-
def ranked(summoner, optional={})
|
50
|
-
region = optional[:region] || @sightstone.region
|
51
|
-
season = optional[:season]
|
52
|
-
id = if summoner.is_a? Summoner
|
53
|
-
summoner.id
|
54
|
-
else
|
55
|
-
summoner
|
56
|
-
end
|
57
|
-
uri = "https://prod.api.pvp.net/api/lol/#{region}/v1.2/stats/by-summoner/#{id}/ranked"
|
58
|
-
response = if season.nil?
|
59
|
-
_get_api_response(uri)
|
60
|
-
else
|
61
|
-
_get_api_response(uri, {'season' => season})
|
62
|
-
end
|
63
|
-
|
64
|
-
_parse_response(response) { |resp|
|
65
|
-
data = JSON.parse(resp)
|
66
|
-
stats = RankedStats.new(data)
|
67
|
-
if block_given?
|
68
|
-
yield stats
|
69
|
-
else
|
70
|
-
return stats
|
71
|
-
end
|
72
|
-
}
|
73
|
-
|
74
|
-
end
|
75
|
-
end
|
1
|
+
|
2
|
+
require 'sightstone/modules/sightstone_base_module'
|
3
|
+
require 'sightstone/summoner'
|
4
|
+
require 'sightstone/player_stats_summary'
|
5
|
+
require 'sightstone/ranked_stats'
|
6
|
+
module Sightstone
|
7
|
+
# Module to receive stats
|
8
|
+
class StatsModule < SightstoneBaseModule
|
9
|
+
def initialize(sightstone)
|
10
|
+
@sightstone = sightstone
|
11
|
+
end
|
12
|
+
|
13
|
+
# get a summary of stats for a summoner
|
14
|
+
# @param [Summoner, Fixnum] summoner summoner object of name
|
15
|
+
# @param optional [Hash] optional arguments: :region => replaces default region
|
16
|
+
# @ return [PlayerStatsSummaryList] of the summoner
|
17
|
+
def summary(summoner, optional={})
|
18
|
+
region = optional[:region] || @sightstone.region
|
19
|
+
season = optional[:season]
|
20
|
+
|
21
|
+
id = if summoner.is_a? Summoner
|
22
|
+
summoner.id
|
23
|
+
else
|
24
|
+
summoner
|
25
|
+
end
|
26
|
+
uri = "https://prod.api.pvp.net/api/lol/#{region}/v1.2/stats/by-summoner/#{id}/summary"
|
27
|
+
response = if season.nil?
|
28
|
+
_get_api_response(uri)
|
29
|
+
else
|
30
|
+
_get_api_response(uri, {'season' => season})
|
31
|
+
end
|
32
|
+
|
33
|
+
_parse_response(response) { |resp|
|
34
|
+
data = JSON.parse(resp)
|
35
|
+
statList = PlayerStatsSummaryList.new(data)
|
36
|
+
if block_given?
|
37
|
+
yield statList
|
38
|
+
else
|
39
|
+
return statList
|
40
|
+
end
|
41
|
+
}
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
# get a summary of stats for a summoner
|
46
|
+
# @param [Summoner, Fixnum] summoner summoner object of name
|
47
|
+
# @param optional [Hash] optional arguments: :region => replaces default region
|
48
|
+
# @ return [RankedStats] of the summoner
|
49
|
+
def ranked(summoner, optional={})
|
50
|
+
region = optional[:region] || @sightstone.region
|
51
|
+
season = optional[:season]
|
52
|
+
id = if summoner.is_a? Summoner
|
53
|
+
summoner.id
|
54
|
+
else
|
55
|
+
summoner
|
56
|
+
end
|
57
|
+
uri = "https://prod.api.pvp.net/api/lol/#{region}/v1.2/stats/by-summoner/#{id}/ranked"
|
58
|
+
response = if season.nil?
|
59
|
+
_get_api_response(uri)
|
60
|
+
else
|
61
|
+
_get_api_response(uri, {'season' => season})
|
62
|
+
end
|
63
|
+
|
64
|
+
_parse_response(response) { |resp|
|
65
|
+
data = JSON.parse(resp)
|
66
|
+
stats = RankedStats.new(data)
|
67
|
+
if block_given?
|
68
|
+
yield stats
|
69
|
+
else
|
70
|
+
return stats
|
71
|
+
end
|
72
|
+
}
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
76
|
end
|