lolbase 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a49ed32c4c1ccd4718531f24d30f594c52df75d
4
- data.tar.gz: 9bbe4fcafbbc4a328f657cf5a3284c4174e13b17
3
+ metadata.gz: 8e807ada0b5d0d9dae9521bebf7c2ddb3f1f84c2
4
+ data.tar.gz: 9e0f746491d28099308a09fa79501c606eb2deab
5
5
  SHA512:
6
- metadata.gz: d878ba2e3a051d84c832c479354dfbd8c8c7149d0dbf7bf50ce1de12dd50ee27d2d2ec5cd2a26ef4007cdc5456f96e5df63ef20dee3e95b2a6f29426632150f3
7
- data.tar.gz: 2bfefaf72317eea4cc9ebc1adb53445413bec405b915cb6b2ddb84e367b0d6f1d2de6963ba6735c87eb2b349bcf0b85386bc4b35d82ab3931af070fff17b7286
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
- # JSON data from the API is returned, parsed as a Ruby object
74
- summary["playerStatSummaries"]
75
- ranked["champions"]
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
 
@@ -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
- JSON.parse response
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
- JSON.parse response
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
- def stats
48
- return @stats || Stats.new(self, @connection)
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
@@ -1,3 +1,3 @@
1
1
  module LoLBase
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -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
- summary = @connection.summoner("illianthe").stats.summary
10
- expect(summary["playerStatSummaries"].count).to eq(7)
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 when requested" do
14
- ranked = @connection.summoner("illianthe").stats.ranked
15
- expect(ranked["modifyDate"]).to eq(1384212356000)
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
@@ -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 when requested" do
9
- illianthe = @connection.summoner("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
- expect(illianthe.id).to eq(19578577)
12
- expect(illianthe.name).to eq("Illianthe")
13
- expect(illianthe.region).to eq("na")
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.2.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-20 00:00:00.000000000 Z
11
+ date: 2013-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler