lolbase 0.2.0 → 0.3.0
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/README.md +18 -3
- data/lib/lolbase/data/stats.rb +109 -2
- data/lib/lolbase/data/summoner.rb +12 -2
- data/lib/lolbase/version.rb +1 -1
- data/spec/stats_data_spec.rb +30 -6
- data/spec/summoner_data_spec.rb +25 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e807ada0b5d0d9dae9521bebf7c2ddb3f1f84c2
|
4
|
+
data.tar.gz: 9e0f746491d28099308a09fa79501c606eb2deab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3f1d2dbc553fc233bec59792d258ea7e352be4aa14d456b7969de5265e9006ee4a925ef4c131fa0ec6a9d26bc53d4ba74b746fc4798e905008fbd5d3742d61a
|
7
|
+
data.tar.gz: cbc5e9d83024e3f549e24ab1afd165d5f4b36307b0214965d3a4b379df8d03ef686e2d3be3404b8d3bbf99be8222af69a38730fed0909f6bf3d51f5d1dd5844c
|
data/README.md
CHANGED
@@ -70,9 +70,24 @@ All connections begin by calling *LoLBase::new* which takes an API key as an arg
|
|
70
70
|
summary = summoner.stats.summary(3)
|
71
71
|
ranked = summoner.stats.ranked(3)
|
72
72
|
|
73
|
-
#
|
74
|
-
summary
|
75
|
-
|
73
|
+
# Retrieve the stats summary for a particular queue type
|
74
|
+
aram = summary.find(name: "AramUnranked5x5")
|
75
|
+
aram.stats["wins"]
|
76
|
+
aram.last_modified
|
77
|
+
|
78
|
+
# Retrieve all recorded stats summaries
|
79
|
+
summary.all
|
80
|
+
|
81
|
+
# Retrieve the ranked stats for a particular champion
|
82
|
+
lux = ranked.find(champion_id: 99)
|
83
|
+
games_played = lux.stats["totalSessionsPlayed"]
|
84
|
+
|
85
|
+
# Retrieve the ranked stats for all champions
|
86
|
+
ranked.all
|
87
|
+
|
88
|
+
# Aggregated stats for ranked play
|
89
|
+
ranked.overall
|
90
|
+
ranked.last_modified
|
76
91
|
|
77
92
|
## Resources
|
78
93
|
|
data/lib/lolbase/data/stats.rb
CHANGED
@@ -18,7 +18,7 @@ module LoLBase
|
|
18
18
|
"/api/lol/#{@summoner.region}/v#{LoLBase.config.version_stats}/stats/by-summoner/#{@summoner.id}/summary",
|
19
19
|
{ query: { season: "SEASON#{season}" } }
|
20
20
|
)
|
21
|
-
|
21
|
+
SummaryStats.new response
|
22
22
|
end
|
23
23
|
|
24
24
|
def ranked(season = LoLBase.config.current_season)
|
@@ -26,7 +26,114 @@ module LoLBase
|
|
26
26
|
"/api/lol/#{@summoner.region}/v#{LoLBase.config.version_stats}/stats/by-summoner/#{@summoner.id}/ranked",
|
27
27
|
{ query: { season: "SEASON#{season}" } }
|
28
28
|
)
|
29
|
-
|
29
|
+
RankedStats.new response
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class SummaryStats
|
34
|
+
class Summary
|
35
|
+
attr_reader :name, :last_modified, :stats
|
36
|
+
|
37
|
+
def initialize(params)
|
38
|
+
@name = params[:name]
|
39
|
+
@last_modified = params[:last_modified]
|
40
|
+
@stats = params[:stats]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def initialize(data)
|
45
|
+
@data = data
|
46
|
+
parse data
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
def raw_json
|
51
|
+
@data
|
52
|
+
end
|
53
|
+
|
54
|
+
def find(criteria = {})
|
55
|
+
if criteria[:name].nil?
|
56
|
+
@parsed_data
|
57
|
+
else
|
58
|
+
@parsed_data.select { |item| item.name == criteria[:name] }.first
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def all
|
63
|
+
return @parsed_data
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def parse(data)
|
69
|
+
@parsed_data = []
|
70
|
+
|
71
|
+
data = JSON.parse data
|
72
|
+
data["playerStatSummaries"].each do |s|
|
73
|
+
@parsed_data <<
|
74
|
+
Summary.new({
|
75
|
+
name: s["playerStatSummaryType"],
|
76
|
+
last_modified: Time.at(s["modifyDate"] / 1000),
|
77
|
+
stats: s["aggregatedStats"].merge!({ "wins" => s["wins"], "losses" => s["losses"] })
|
78
|
+
})
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class RankedStats
|
84
|
+
attr_reader :last_modified, :overall
|
85
|
+
|
86
|
+
class Champion
|
87
|
+
attr_reader :id, :stats
|
88
|
+
|
89
|
+
def initialize(params)
|
90
|
+
@id = params[:id]
|
91
|
+
@stats = params[:stats]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def initialize(data)
|
96
|
+
@data = data
|
97
|
+
parse data
|
98
|
+
self
|
99
|
+
end
|
100
|
+
|
101
|
+
def raw_json
|
102
|
+
@data
|
103
|
+
end
|
104
|
+
|
105
|
+
def find(criteria = {})
|
106
|
+
if criteria[:champion_id].nil?
|
107
|
+
@parsed_data
|
108
|
+
else
|
109
|
+
@parsed_data.select { |item| item.id == criteria[:champion_id] }.first
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def all
|
114
|
+
return @parsed_data
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
def parse(data)
|
120
|
+
@parsed_data = []
|
121
|
+
|
122
|
+
data = JSON.parse data
|
123
|
+
@last_modified = Time.at(data["modifyDate"] / 1000)
|
124
|
+
data["champions"].each do |c|
|
125
|
+
# Overall stats are combined with champion stats in the raw JSON data -
|
126
|
+
# split it out
|
127
|
+
if c["id"] == 0
|
128
|
+
@overall = c["stats"]
|
129
|
+
else
|
130
|
+
@parsed_data <<
|
131
|
+
Champion.new({
|
132
|
+
id: c["id"],
|
133
|
+
stats: c["stats"]
|
134
|
+
})
|
135
|
+
end
|
136
|
+
end
|
30
137
|
end
|
31
138
|
end
|
32
139
|
end
|
@@ -44,8 +44,18 @@ module LoLBase
|
|
44
44
|
return @profile_icon || ProfileIcon.new(nil, self)
|
45
45
|
end
|
46
46
|
|
47
|
-
|
48
|
-
|
47
|
+
# Return stats for the given summoner. Syntactic sugar for retrieving summary
|
48
|
+
# or ranked stats.
|
49
|
+
def stats(type = nil)
|
50
|
+
@stats ||= Stats.new(self, @connection)
|
51
|
+
|
52
|
+
if type == :summary
|
53
|
+
return @stats.summary
|
54
|
+
elsif type == :ranked
|
55
|
+
return @stats.ranked
|
56
|
+
else
|
57
|
+
return @stats
|
58
|
+
end
|
49
59
|
end
|
50
60
|
end
|
51
61
|
end
|
data/lib/lolbase/version.rb
CHANGED
data/spec/stats_data_spec.rb
CHANGED
@@ -3,15 +3,39 @@ require "spec_helper"
|
|
3
3
|
describe LoLBase::Stats do
|
4
4
|
before do
|
5
5
|
@connection = LoLBase.new "random-key"
|
6
|
+
@illianthe = @connection.summoner("illianthe")
|
6
7
|
end
|
7
8
|
|
8
|
-
it "should return a summoner's stats summary when requested" do
|
9
|
-
|
10
|
-
expect(
|
9
|
+
it "should return a summoner's stats summary for a given game type when requested" do
|
10
|
+
coop = @illianthe.stats.summary.find(name: "CoopVsAI")
|
11
|
+
expect(coop.stats["wins"]).to eq(1177)
|
12
|
+
expect(coop.last_modified).to eq(Time.at(1302601118))
|
13
|
+
|
14
|
+
aram = @illianthe.stats.summary.find(name: "AramUnranked5x5")
|
15
|
+
expect(aram.stats["wins"]).to eq(209)
|
16
|
+
expect(aram.last_modified).to eq(Time.at(1387446729))
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return a summoner's stats summary for all game types when requested" do
|
20
|
+
summary = @illianthe.stats.summary.all
|
21
|
+
expect(summary.count).to eq(7)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return a summoner's ranked stats for a given champion when requested" do
|
25
|
+
ranked = @illianthe.stats.ranked
|
26
|
+
expect(ranked.last_modified).to eq(Time.at(1384212356))
|
27
|
+
|
28
|
+
lux = ranked.find(champion_id: 99)
|
29
|
+
expect(lux.stats["totalSessionsPlayed"]).to eq(17)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return a summoner's ranked stats for all champions when requested" do
|
33
|
+
ranked = @illianthe.stats.ranked.all
|
34
|
+
expect(ranked.count).to eq(11)
|
11
35
|
end
|
12
36
|
|
13
|
-
it "should return a summoner's ranked stats
|
14
|
-
|
15
|
-
expect(
|
37
|
+
it "should return a summoner's overall ranked stats" do
|
38
|
+
overall = @illianthe.stats.ranked.overall
|
39
|
+
expect(overall["totalDamageTaken"]).to eq(583858)
|
16
40
|
end
|
17
41
|
end
|
data/spec/summoner_data_spec.rb
CHANGED
@@ -3,17 +3,33 @@ require "spec_helper"
|
|
3
3
|
describe LoLBase::Summoner do
|
4
4
|
before do
|
5
5
|
@connection = LoLBase.new "random-key"
|
6
|
+
@illianthe = @connection.summoner("illianthe")
|
6
7
|
end
|
7
8
|
|
8
|
-
it "should return basic summoner data
|
9
|
-
illianthe
|
9
|
+
it "should return basic summoner data" do
|
10
|
+
expect(@illianthe.id).to eq(19578577)
|
11
|
+
expect(@illianthe.name).to eq("Illianthe")
|
12
|
+
expect(@illianthe.region).to eq("na")
|
13
|
+
expect(@illianthe.level).to eq(30)
|
14
|
+
expect(@illianthe.last_modified).to eq(Time.at(1387446729))
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return profile icon data" do
|
18
|
+
expect(@illianthe.profile_icon.class).to eq(LoLBase::ProfileIcon)
|
19
|
+
expect(@illianthe.profile_icon.id).to eq(539)
|
20
|
+
end
|
21
|
+
|
22
|
+
context "Stats" do
|
23
|
+
it "should return a generic Stats object when called without arguments" do
|
24
|
+
expect(@illianthe.stats.class).to eq(LoLBase::Stats)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return SummaryStats when called with :summary" do
|
28
|
+
expect(@illianthe.stats(:summary).class).to eq(LoLBase::SummaryStats)
|
29
|
+
end
|
10
30
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
expect(illianthe.level).to eq(30)
|
15
|
-
expect(illianthe.last_modified).to eq(Time.at(1387446729))
|
16
|
-
|
17
|
-
expect(illianthe.profile_icon.id).to eq(539)
|
31
|
+
it "should return RankedStats when called with :rank" do
|
32
|
+
expect(@illianthe.stats(:ranked).class).to eq(LoLBase::RankedStats)
|
33
|
+
end
|
18
34
|
end
|
19
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lolbase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Regan Chan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|