ruby-lol 0.9.10 → 0.9.11

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: 4bcac1b72dd226f3ef709a14ae8be712cd5fedcb
4
- data.tar.gz: cd08d35b7dc9e8b5c1df996bb08d515dee4ad1f0
3
+ metadata.gz: f96a74077c549229c2719763486c3bcd9bd8da25
4
+ data.tar.gz: 32f1aeb7a7aed7c6e0bab87f3ffeb23d286473e2
5
5
  SHA512:
6
- metadata.gz: 636209f1b3f0e8aa9f9e14321296245b56ba7cec490b42ab729a23bb3a608d63c0da62784e28fbf6e2e051be0e1f213f95b9ac69a9e4db63f62a049ede78d978
7
- data.tar.gz: 40cb048f2ab8c666badc91cd6a8c9d2f0a83c7d888d75cf4de99f16b9f920c3644758b0d34bab180049df93ffa70807f767fccc6107994b11efd84f638c529a9
6
+ metadata.gz: 4623f57302ba2cd3faf1620d138397cceaa81217713c57d0319f1298e31f752ae7ff2b4da124adf154ba73f6061b873bfd952e3e877dd79a98ee750fb62599c1
7
+ data.tar.gz: af511b335a6fe0412e53e1bc2939cdbbdd9fb8917dddc0f1717fd3b4031b1e0611d8f9c3f938a3bc7b2ea65428aec3b71c5cacdedb93dc1a37d454646ca22d62
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # ruby-lol
2
- [![Gem Version](https://badge.fury.io/rb/ruby-lol.png)](http://badge.fury.io/rb/ruby-lol) [![Coverage Status](https://coveralls.io/repos/mikamai/ruby-lol/badge.png)](https://coveralls.io/r/mikamai/ruby-lol) [![Build Status](https://travis-ci.org/mikamai/ruby-lol.png?branch=master)](https://travis-ci.org/mikamai/ruby-lol) [![Code Climate](https://codeclimate.com/repos/52a9908c56b102320a0166a4/badges/7e5d4ea4fe9e562f8e4d/gpa.png)](https://codeclimate.com/repos/52a9908c56b102320a0166a4/feed) [![Dependency Status](https://gemnasium.com/mikamai/ruby-lol.png)](https://gemnasium.com/mikamai/ruby-lol)
2
+ [![Gem Version](https://badge.fury.io/rb/ruby-lol.png)](http://badge.fury.io/rb/ruby-lol) [![Coverage Status](https://coveralls.io/repos/mikamai/ruby-lol/badge.png)](https://coveralls.io/r/mikamai/ruby-lol) [![Build Status](https://travis-ci.org/mikamai/ruby-lol.png?branch=master)](https://travis-ci.org/mikamai/ruby-lol) [![Dependency Status](https://gemnasium.com/mikamai/ruby-lol.png)](https://gemnasium.com/mikamai/ruby-lol)
3
3
 
4
4
 
5
5
  ruby-lol is a wrapper to the [Riot Games API](https://developer.riotgames.com).
@@ -25,13 +25,12 @@ Or install it yourself as:
25
25
  ```ruby
26
26
  require 'lol'
27
27
 
28
- # defaults to euw
29
- client = Lol::Client.new "my_api_key"
28
+ client = Lol::Client.new "my_api_key", "euw"
30
29
  # => <Lol::Client:0x007fd09d1abb00 @api_key="my_api_key", @region="euw">
31
30
 
32
- # na
33
- na_client = Lol::Client.new "my_api_key", :region => "na"
34
- # => <Lol::Client:0x007fd09d1abb00 @api_key="my_api_key", @region="na">
31
+ # NEW! You can cache requests using Redis now
32
+ # ttl defaults to 900
33
+ client = Lol::Client.new "my_api_key", "euw", {redis: "redis://localhost:6379", ttl: 900}
35
34
 
36
35
  # Available Requests
37
36
  client.champion
@@ -119,8 +118,11 @@ client.static.champion.get(champData: 'lore')
119
118
  5. Create new Pull Request
120
119
 
121
120
  ## Changelog
122
-
123
- - 0.9.7 Updated LeagueReqeust to API v2.3
121
+ - 0.9.11 Added caching support via REDIS
122
+ - 0.9.7 Updated LeagueRequest to API v2.3
124
123
  - 0.9.6 Updated SummonerRequest and GameRequest to API v1.3
125
124
  - 0.9.5 Fixed documentation
126
125
  - 0.9.4 Completed support for updated API
126
+
127
+
128
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/mikamai/ruby-lol/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
data/lib/lol.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'active_support/core_ext/string/inflections'
2
2
  require 'httparty'
3
3
  require 'uri'
4
+ require 'redis'
4
5
 
5
6
  module Lol
6
7
  # Takes a hash and returns a copy of it with the keys that have been underscored
data/lib/lol/client.rb CHANGED
@@ -9,39 +9,43 @@ module Lol
9
9
  # @return [String] the API key that has been used
10
10
  attr_reader :api_key
11
11
 
12
+ # @!attribute [r] ttl
13
+ # @return [Fixnum] the ttl on cached requests
14
+ attr_reader :ttl
15
+
12
16
  # @return [ChampionRequest]
13
17
  def champion
14
- @champion_request ||= ChampionRequest.new(api_key, region)
18
+ @champion_request ||= ChampionRequest.new(api_key, region, cache_store)
15
19
  end
16
20
 
17
21
  # @return [GameRequest]
18
22
  def game
19
- @game_request ||= GameRequest.new(api_key, region)
23
+ @game_request ||= GameRequest.new(api_key, region, cache_store)
20
24
  end
21
25
 
22
26
  # @return [StatsRequest]
23
27
  def stats
24
- @stats_request ||= StatsRequest.new(api_key, region)
28
+ @stats_request ||= StatsRequest.new(api_key, region, cache_store)
25
29
  end
26
30
 
27
31
  # @return [LeagueRequest]
28
32
  def league
29
- @league_request ||= LeagueRequest.new(api_key, region)
33
+ @league_request ||= LeagueRequest.new(api_key, region, cache_store)
30
34
  end
31
35
 
32
36
  # @return [TeamRequest]
33
37
  def team
34
- @team_request ||= TeamRequest.new(api_key, region)
38
+ @team_request ||= TeamRequest.new(api_key, region, cache_store)
35
39
  end
36
40
 
37
41
  # @return [SummonerRequest]
38
42
  def summoner
39
- @summoner_request ||= SummonerRequest.new(api_key, region)
43
+ @summoner_request ||= SummonerRequest.new(api_key, region, cache_store)
40
44
  end
41
45
 
42
46
  # @return [StaticRequest]
43
47
  def static
44
- @static_request ||= StaticRequest.new(api_key, region)
48
+ @static_request ||= StaticRequest.new(api_key, region, cache_store)
45
49
  end
46
50
 
47
51
  # Initializes a Lol::Client
@@ -52,7 +56,35 @@ module Lol
52
56
  def initialize api_key, options = {}
53
57
  @api_key = api_key
54
58
  @region = options.delete(:region) || "euw"
59
+ set_up_cache(options.delete(:redis), options.delete(:ttl))
55
60
  end
56
61
 
62
+ def set_up_cache(redis_url, ttl)
63
+ return @cached = false unless redis_url
64
+
65
+ @ttl = ttl || 900
66
+ @cached = true
67
+ @redis = Redis.new :url => redis_url
68
+ end
69
+
70
+ # Returns an options hash with cache keys
71
+ # @return [Hash]
72
+ def cache_store
73
+ {
74
+ redis: @redis,
75
+ ttl: @ttl,
76
+ cached: @cached,
77
+ }
78
+ end
79
+
80
+ # @return [Boolean] true if requests are cached
81
+ def cached?
82
+ @cached
83
+ end
84
+
85
+ # @return [Redis] the cache store (if available)
86
+ def redis
87
+ @redis
88
+ end
57
89
  end
58
90
  end
@@ -13,5 +13,33 @@ module Lol
13
13
  perform_request(api_url("league/by-summoner/#{summoner_id}")).map {|l| League.new l}
14
14
  end
15
15
 
16
+ # Retrieves leagues entry data for summoner, including league entries for all of summoner's teams
17
+ # @param [String]
18
+ # @return [Array]
19
+ # TODO: Change name to entries?
20
+ def get_entries summoner_id
21
+ perform_request(api_url("league/by-summoner/#{summoner_id}/entry")).map { |e| LeagueEntry.new e }
22
+ end
23
+
24
+ # Retrieves leagues data for team
25
+ # @param [String]
26
+ # @return [Array]
27
+ def by_team team_id
28
+ perform_request(api_url("league/by-team/#{team_id}")).map { |l| League.new l }
29
+ end
30
+
31
+ # Retrieves leagues entry data for team
32
+ # @param [String]
33
+ # @return [Array]
34
+ # TODO: Change name to?
35
+ def entries_by_team team_id
36
+ perform_request(api_url("league/by-team/#{team_id}/entry")).map { |e| LeagueEntry.new e }
37
+ end
38
+
39
+ # Retrieves challenger tier leagues
40
+ # @return [Array]
41
+ def challenger
42
+ perform_request(api_url('league/challenger')).map { |l| League.new l }
43
+ end
16
44
  end
17
45
  end
data/lib/lol/request.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  module Lol
2
2
  class InvalidAPIResponse < StandardError; end
3
3
  class NotFound < StandardError; end
4
+ class InvalidCacheStore < StandardError; end
4
5
 
5
6
  # Encapsulates common methods for all requests
6
7
  # Request classes inherit from this
@@ -16,6 +17,9 @@ module Lol
16
17
  # @return [String] region
17
18
  attr_accessor :region
18
19
 
20
+ # @!attribute[r] cache_store
21
+ # @return [Object] the cache_store
22
+ attr_reader :cache_store
19
23
 
20
24
  # Stub method. Each subclass should have its own api version
21
25
  # @return [String] api version
@@ -35,17 +39,50 @@ module Lol
35
39
  # @param url [String] the url to call
36
40
  # @return [String] raw response of the call
37
41
  def perform_request url
42
+ if cached? && result = store.get(url)
43
+ return result
44
+ end
45
+
38
46
  response = self.class.get(url)
39
47
  raise NotFound.new("404 Not Found") if response.respond_to?(:code) && response.not_found?
40
48
  raise InvalidAPIResponse.new(response["status"]["message"]) if response.is_a?(Hash) && response["status"]
41
49
 
50
+ if cached?
51
+ store.set url, response
52
+ store.expire url, ttl
53
+ end
54
+
42
55
  response
43
56
  end
44
57
 
45
- def initialize api_key, region
58
+ # @return [Redis] returns the cache store
59
+ def store
60
+ cache_store[:redis]
61
+ end
62
+
63
+ # @return [Boolean] true if the request should be cached
64
+ def cached?
65
+ cache_store[:cached]
66
+ end
67
+
68
+ # @return [Fixnum] the ttl to apply to cached keys
69
+ def ttl
70
+ cache_store[:ttl]
71
+ end
72
+
73
+ # Initializes a new Request
74
+ # @param api_key [String] the Riot Games API key
75
+ # @param region [String] the region you want to use in API calls
76
+ # @param cache_store [Hash]
77
+ # @option cache_store [Redis] :redis Redis instance to use
78
+ # @option cache_store [Boolean] :cached should the request be cached
79
+ # @option cacche_store [Fixnum] :ttl ttl for cache keys
80
+ # @return [Request]
81
+ def initialize api_key, region, cache_store = {}
82
+ @cache_store = cache_store
83
+ raise InvalidCacheStore if cached? && !store.is_a?(Redis)
46
84
  @api_key = api_key
47
85
  @region = region
48
86
  end
49
-
50
87
  end
51
88
  end
data/lib/lol/rune_page.rb CHANGED
@@ -16,13 +16,13 @@ module Lol
16
16
  # @!attribute [r] current
17
17
  # @return [Array] array of Lol::RuneSlot
18
18
  attr_reader :slots
19
- end
20
19
 
21
- private
20
+ private
22
21
 
23
- attr_writer :id, :name, :current
22
+ attr_writer :id, :name, :current
24
23
 
25
- def slots= *runeslots
26
- @slots = runeslots.flatten.map {|slot| RuneSlot.new slot}
24
+ def slots= *runeslots
25
+ @slots = runeslots.flatten.map {|slot| RuneSlot.new slot}
26
+ end
27
27
  end
28
28
  end
@@ -11,13 +11,13 @@ module Lol
11
11
  # @param path [String] API path to call
12
12
  # @return [String] full fledged url
13
13
  def api_url path, params = {}
14
- query_string = URI.encode_www_form params.merge api_key: api_key
15
- File.join "http://prod.api.pvp.net/api/lol/static-data/#{region}/#{self.class.api_version}/", "#{path}?#{query_string}"
14
+ super(path,params).gsub(/api\/lol/, "api/lol/static-data")
16
15
  end
17
16
 
18
17
  STANDARD_ENDPOINTS.each do |endpoint|
19
18
  define_method(endpoint) { Proxy.new self, endpoint }
20
19
  end
20
+
21
21
  def realm
22
22
  Proxy.new self, 'realm'
23
23
  end
@@ -13,5 +13,12 @@ module Lol
13
13
  Team.new team_data
14
14
  end
15
15
  end
16
+
17
+ # Retrieves the Teams for the given Team ID
18
+ # @return [Team]
19
+ def getbyid team_id
20
+ result = perform_request(api_url "team/#{team_id}")
21
+ Team.new result[team_id]
22
+ end
16
23
  end
17
24
  end
data/lib/lol/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lol
2
- VERSION = "0.9.10"
2
+ VERSION = "0.9.11"
3
3
  end
data/ruby-lol.gemspec CHANGED
@@ -35,4 +35,5 @@ Gem::Specification.new do |spec|
35
35
 
36
36
  spec.add_runtime_dependency "httparty"
37
37
  spec.add_runtime_dependency "activesupport"
38
+ spec.add_runtime_dependency "redis"
38
39
  end
@@ -19,4 +19,5 @@ describe "API Versions" do
19
19
  check_api_version(StatsRequest, "v1.2")
20
20
  check_api_version(SummonerRequest, "v1.3")
21
21
  check_api_version(TeamRequest, "v2.2")
22
+ check_api_version(StaticRequest, "v1")
22
23
  end
@@ -0,0 +1,286 @@
1
+ {
2
+ "TEAM-c80824c9-c568-42de-bdbb-271543b209e1": {
3
+ "fullId" : "TEAM-c80824c9-c568-42de-bdbb-271543b209e1",
4
+ "name" : "Digimon Tamers",
5
+ "tag" : "TagMon",
6
+ "status" : "RANKED",
7
+ "teamStatSummary" : {
8
+ "fullId" : "TEAM-c80824c9-c568-42de-bdbb-271543b209e1",
9
+ "teamStatDetails" : [ {
10
+ "fullId" : "TEAM-c80824c9-c568-42de-bdbb-271543b209e1",
11
+ "teamStatType" : "RANKED_TEAM_3x3",
12
+ "wins" : 0,
13
+ "losses" : 0,
14
+ "averageGamesPlayed" : 0
15
+ }, {
16
+ "fullId" : "TEAM-c80824c9-c568-42de-bdbb-271543b209e1",
17
+ "teamStatType" : "RANKED_TEAM_5x5",
18
+ "wins" : 0,
19
+ "losses" : 0,
20
+ "averageGamesPlayed" : 0
21
+ } ]
22
+ },
23
+ "roster" : {
24
+ "ownerId" : 592670,
25
+ "memberList" : [ {
26
+ "playerId" : 592670,
27
+ "joinDate" : 1331623605000,
28
+ "inviteDate" : 1331623605000,
29
+ "status" : "MEMBER"
30
+ }, {
31
+ "playerId" : 580668,
32
+ "joinDate" : 1331623681000,
33
+ "inviteDate" : 1331623677000,
34
+ "status" : "MEMBER"
35
+ }, {
36
+ "playerId" : 19782302,
37
+ "joinDate" : 1331625157000,
38
+ "inviteDate" : 1331624042000,
39
+ "status" : "MEMBER"
40
+ }, {
41
+ "playerId" : 5908,
42
+ "joinDate" : 1331679340000,
43
+ "inviteDate" : 1331679337000,
44
+ "status" : "MEMBER"
45
+ }, {
46
+ "playerId" : 20453497,
47
+ "joinDate" : 1351309208000,
48
+ "inviteDate" : 1351309203000,
49
+ "status" : "MEMBER"
50
+ }, {
51
+ "playerId" : 20453514,
52
+ "joinDate" : 1352095946000,
53
+ "inviteDate" : 1352095943000,
54
+ "status" : "MEMBER"
55
+ } ]
56
+ },
57
+ "matchHistory" : [ {
58
+ "kills" : 12,
59
+ "deaths" : 31,
60
+ "opposingTeamKills" : 31,
61
+ "assists" : 19,
62
+ "gameMode" : "CLASSIC",
63
+ "opposingTeamName" : "Frenetic Array",
64
+ "win" : false,
65
+ "invalid" : false,
66
+ "mapId" : 1,
67
+ "gameId" : 576575490
68
+ }, {
69
+ "kills" : 25,
70
+ "deaths" : 15,
71
+ "opposingTeamKills" : 15,
72
+ "assists" : 53,
73
+ "gameMode" : "CLASSIC",
74
+ "opposingTeamName" : "Frenetic Array",
75
+ "win" : true,
76
+ "invalid" : false,
77
+ "mapId" : 1,
78
+ "gameId" : 576566324
79
+ }, {
80
+ "kills" : 15,
81
+ "deaths" : 8,
82
+ "opposingTeamKills" : 7,
83
+ "assists" : 27,
84
+ "gameMode" : "CLASSIC",
85
+ "opposingTeamName" : "Team Stacked",
86
+ "win" : true,
87
+ "invalid" : false,
88
+ "mapId" : 1,
89
+ "gameId" : 576536749
90
+ }, {
91
+ "kills" : 15,
92
+ "deaths" : 18,
93
+ "opposingTeamKills" : 18,
94
+ "assists" : 32,
95
+ "gameMode" : "CLASSIC",
96
+ "opposingTeamName" : "Team Mundane",
97
+ "win" : true,
98
+ "invalid" : false,
99
+ "mapId" : 1,
100
+ "gameId" : 576511761
101
+ }, {
102
+ "kills" : 12,
103
+ "deaths" : 21,
104
+ "opposingTeamKills" : 21,
105
+ "assists" : 28,
106
+ "gameMode" : "CLASSIC",
107
+ "opposingTeamName" : "Curse Gaming",
108
+ "win" : false,
109
+ "invalid" : false,
110
+ "mapId" : 1,
111
+ "gameId" : 576486880
112
+ }, {
113
+ "kills" : 35,
114
+ "deaths" : 25,
115
+ "opposingTeamKills" : 25,
116
+ "assists" : 81,
117
+ "gameMode" : "CLASSIC",
118
+ "opposingTeamName" : "Team Mundane",
119
+ "win" : true,
120
+ "invalid" : false,
121
+ "mapId" : 1,
122
+ "gameId" : 576438411
123
+ }, {
124
+ "kills" : 30,
125
+ "deaths" : 31,
126
+ "opposingTeamKills" : 31,
127
+ "assists" : 70,
128
+ "gameMode" : "CLASSIC",
129
+ "opposingTeamName" : "In Lucky We Trust",
130
+ "win" : true,
131
+ "invalid" : false,
132
+ "mapId" : 1,
133
+ "gameId" : 576354607
134
+ }, {
135
+ "kills" : 17,
136
+ "deaths" : 6,
137
+ "opposingTeamKills" : 6,
138
+ "assists" : 28,
139
+ "gameMode" : "CLASSIC",
140
+ "opposingTeamName" : "TicoGamers CR",
141
+ "win" : true,
142
+ "invalid" : false,
143
+ "mapId" : 1,
144
+ "gameId" : 576326147
145
+ }, {
146
+ "kills" : 26,
147
+ "deaths" : 14,
148
+ "opposingTeamKills" : 14,
149
+ "assists" : 70,
150
+ "gameMode" : "CLASSIC",
151
+ "opposingTeamName" : "The Blinters 5",
152
+ "win" : true,
153
+ "invalid" : false,
154
+ "mapId" : 1,
155
+ "gameId" : 576266814
156
+ }, {
157
+ "kills" : 15,
158
+ "deaths" : 26,
159
+ "opposingTeamKills" : 26,
160
+ "assists" : 28,
161
+ "gameMode" : "CLASSIC",
162
+ "opposingTeamName" : "We Da Bes",
163
+ "win" : false,
164
+ "invalid" : false,
165
+ "mapId" : 1,
166
+ "gameId" : 576041138
167
+ }, {
168
+ "kills" : 22,
169
+ "deaths" : 33,
170
+ "opposingTeamKills" : 33,
171
+ "assists" : 48,
172
+ "gameMode" : "CLASSIC",
173
+ "opposingTeamName" : "From Coal to Diamond",
174
+ "win" : false,
175
+ "invalid" : false,
176
+ "mapId" : 1,
177
+ "gameId" : 575986771
178
+ }, {
179
+ "kills" : 23,
180
+ "deaths" : 7,
181
+ "opposingTeamKills" : 7,
182
+ "assists" : 45,
183
+ "gameMode" : "CLASSIC",
184
+ "opposingTeamName" : "No Fuking Around Okay",
185
+ "win" : true,
186
+ "invalid" : false,
187
+ "mapId" : 1,
188
+ "gameId" : 575961469
189
+ }, {
190
+ "kills" : 20,
191
+ "deaths" : 10,
192
+ "opposingTeamKills" : 10,
193
+ "assists" : 29,
194
+ "gameMode" : "CLASSIC",
195
+ "opposingTeamName" : "Tube88",
196
+ "win" : true,
197
+ "invalid" : false,
198
+ "mapId" : 1,
199
+ "gameId" : 575905727
200
+ }, {
201
+ "kills" : 21,
202
+ "deaths" : 11,
203
+ "opposingTeamKills" : 11,
204
+ "assists" : 37,
205
+ "gameMode" : "CLASSIC",
206
+ "opposingTeamName" : "Resonate",
207
+ "win" : true,
208
+ "invalid" : false,
209
+ "mapId" : 1,
210
+ "gameId" : 575441369
211
+ }, {
212
+ "kills" : 13,
213
+ "deaths" : 24,
214
+ "opposingTeamKills" : 24,
215
+ "assists" : 27,
216
+ "gameMode" : "CLASSIC",
217
+ "opposingTeamName" : "Nobody Important Died",
218
+ "win" : false,
219
+ "invalid" : false,
220
+ "mapId" : 1,
221
+ "gameId" : 575390058
222
+ }, {
223
+ "kills" : 33,
224
+ "deaths" : 14,
225
+ "opposingTeamKills" : 14,
226
+ "assists" : 49,
227
+ "gameMode" : "CLASSIC",
228
+ "opposingTeamName" : "DIAMON FIVES PLS",
229
+ "win" : true,
230
+ "invalid" : false,
231
+ "mapId" : 1,
232
+ "gameId" : 575349088
233
+ }, {
234
+ "kills" : 16,
235
+ "deaths" : 5,
236
+ "opposingTeamKills" : 5,
237
+ "assists" : 20,
238
+ "gameMode" : "CLASSIC",
239
+ "opposingTeamName" : "Cute Asian Girls",
240
+ "win" : true,
241
+ "invalid" : false,
242
+ "mapId" : 1,
243
+ "gameId" : 340801031
244
+ }, {
245
+ "kills" : 4,
246
+ "deaths" : 19,
247
+ "opposingTeamKills" : 18,
248
+ "assists" : 12,
249
+ "gameMode" : "CLASSIC",
250
+ "opposingTeamName" : "HeIIo Kitty",
251
+ "win" : false,
252
+ "invalid" : false,
253
+ "mapId" : 1,
254
+ "gameId" : 340775336
255
+ }, {
256
+ "kills" : 24,
257
+ "deaths" : 7,
258
+ "opposingTeamKills" : 7,
259
+ "assists" : 56,
260
+ "gameMode" : "CLASSIC",
261
+ "opposingTeamName" : "Fluid Mechanics",
262
+ "win" : true,
263
+ "invalid" : false,
264
+ "mapId" : 1,
265
+ "gameId" : 340760658
266
+ }, {
267
+ "kills" : 33,
268
+ "deaths" : 21,
269
+ "opposingTeamKills" : 21,
270
+ "assists" : 89,
271
+ "gameMode" : "CLASSIC",
272
+ "opposingTeamName" : "Xerox Tryout",
273
+ "win" : true,
274
+ "invalid" : false,
275
+ "mapId" : 1,
276
+ "gameId" : 340678263
277
+ } ],
278
+ "createDate" : 1331623605000,
279
+ "modifyDate" : 1357872802000,
280
+ "lastJoinDate" : 1352095978000,
281
+ "secondLastJoinDate" : 1352095946000,
282
+ "thirdLastJoinDate" : 1351309219000,
283
+ "lastGameDate" : 1352190417000,
284
+ "lastJoinedRankedTeamQueueDate" : 1352188085000
285
+ }
286
+ }
@@ -18,8 +18,45 @@ describe Client do
18
18
  it "defaults on EUW as a region" do
19
19
  expect(subject.region).to eq("euw")
20
20
  end
21
+
22
+ it "sets caching if redis is specified in the options" do
23
+ client = Client.new "foo", redis: "redis://dummy-url"
24
+ expect(client.cached?).to be_true
25
+ end
26
+
27
+ it "sets a default ttl of 15 * 60s" do
28
+ client = Client.new "foo", redis: "redis://dummy-url"
29
+ expect(client.ttl).to eq(15*60)
30
+ end
31
+
32
+ it "accepts a custom ttl" do
33
+ client = Client.new "foo", redis: "redis://dummy-url", ttl: 10
34
+ expect(client.ttl).to eq(10)
35
+ end
36
+
37
+ it "instantiates a redis client if redis is in the options" do
38
+ client = Client.new "foo", redis: "redis://localhost:6379"
39
+ expect(client.instance_variable_get(:@redis)).to be_a(Redis)
40
+ end
41
+
42
+ it "passes the redis_store to the request" do
43
+ client = Client.new "foo", redis: "redis://localhost:6379"
44
+ champion_request = client.champion
45
+ expect(champion_request.cache_store).to eq(client.cache_store)
46
+ end
21
47
  end
22
48
 
49
+ describe "#cached?" do
50
+ it "is true if @cached is true" do
51
+ subject.instance_variable_set(:@cached, true)
52
+ expect(subject.cached?).to be_true
53
+ end
54
+
55
+ it "is false if @cached is false" do
56
+ subject.instance_variable_set(:@cached, false)
57
+ expect(subject.cached?).to be_false
58
+ end
59
+ end
23
60
 
24
61
  describe "#champion" do
25
62
  it "returns an instance of ChampionRequest" do
@@ -27,7 +64,7 @@ describe Client do
27
64
  end
28
65
 
29
66
  it "initializes the ChampionRequest with the current API key and region" do
30
- expect(ChampionRequest).to receive(:new).with(subject.api_key, subject.region)
67
+ expect(ChampionRequest).to receive(:new).with(subject.api_key, subject.region, subject.cache_store)
31
68
 
32
69
  subject.champion
33
70
  end
@@ -39,7 +76,7 @@ describe Client do
39
76
  end
40
77
 
41
78
  it "initializes the GameRequest with the current API key and region" do
42
- expect(GameRequest).to receive(:new).with(subject.api_key, subject.region)
79
+ expect(GameRequest).to receive(:new).with(subject.api_key, subject.region, subject.cache_store)
43
80
 
44
81
  subject.game
45
82
  end
@@ -51,7 +88,7 @@ describe Client do
51
88
  end
52
89
 
53
90
  it "initializes the StatsRequest with the current API key and region" do
54
- expect(StatsRequest).to receive(:new).with(subject.api_key, subject.region)
91
+ expect(StatsRequest).to receive(:new).with(subject.api_key, subject.region, subject.cache_store)
55
92
 
56
93
  subject.stats
57
94
  end
@@ -63,7 +100,7 @@ describe Client do
63
100
  end
64
101
 
65
102
  it "initializes the TeamRequest with the current API key and region" do
66
- expect(TeamRequest).to receive(:new).with(subject.api_key, subject.region)
103
+ expect(TeamRequest).to receive(:new).with(subject.api_key, subject.region, subject.cache_store)
67
104
 
68
105
  subject.team
69
106
  end
@@ -75,7 +112,7 @@ describe Client do
75
112
  end
76
113
 
77
114
  it "initializes the LeagueRequest with the current API key and region" do
78
- expect(LeagueRequest).to receive(:new).with(subject.api_key, subject.region)
115
+ expect(LeagueRequest).to receive(:new).with(subject.api_key, subject.region, subject.cache_store)
79
116
 
80
117
  subject.league
81
118
  end
@@ -87,7 +124,7 @@ describe Client do
87
124
  end
88
125
 
89
126
  it "initializes the SummonerRequest with the current API key and region" do
90
- expect(SummonerRequest).to receive(:new).with(subject.api_key, subject.region)
127
+ expect(SummonerRequest).to receive(:new).with(subject.api_key, subject.region, subject.cache_store)
91
128
 
92
129
  subject.summoner
93
130
  end
@@ -99,7 +136,7 @@ describe Client do
99
136
  end
100
137
 
101
138
  it "initializes the StaticRequest with the current API key and region" do
102
- expect(StaticRequest).to receive(:new).with(subject.api_key, subject.region)
139
+ expect(StaticRequest).to receive(:new).with(subject.api_key, subject.region, subject.cache_store)
103
140
 
104
141
  subject.static
105
142
  end
@@ -16,6 +16,16 @@ describe Request do
16
16
  it "correctly sets api key" do
17
17
  expect(ChampionRequest.new("api_key", "euw").api_key).to eq("api_key")
18
18
  end
19
+
20
+ it "sets the cache store" do
21
+ redis_store = Redis.new
22
+ c = ChampionRequest.new("api_key", "euw", redis_store)
23
+ expect(c.cache_store).to eq(redis_store)
24
+ end
25
+
26
+ it "returns an error if the cache store is not supported" do
27
+ expect { ChampionRequest.new "api_key", "euw", {cached: true, redis: "FOO"}}.to raise_error(InvalidCacheStore)
28
+ end
19
29
  end
20
30
 
21
31
  subject { Request.new "api_key", "euw"}
@@ -40,6 +50,36 @@ describe Request do
40
50
  expect(subject.class).to receive(:get).and_return(error401)
41
51
  expect { subject.perform_request "foo"}.to raise_error(NotFound)
42
52
  end
53
+
54
+ it "is cached" do
55
+ class FakeRedis < Redis
56
+ def initialize options = {}
57
+ @store = {}
58
+ end
59
+
60
+ def get key
61
+ @store[key]
62
+ end
63
+
64
+ def set key, val
65
+ @store[key] = val
66
+ end
67
+
68
+ def expire key, ttl
69
+ @store["#{key}:ttl"] = ttl
70
+ end
71
+ end
72
+
73
+ fake_redis = FakeRedis.new
74
+ request = Request.new "api_key", "euw", {redis: fake_redis, ttl: 60, cached: true}
75
+ expect(request.class).to receive(:get).with("/foo").and_return("foo")
76
+ first_result = request.perform_request "/foo"
77
+
78
+ expect(request.class).not_to receive(:get)
79
+ request.perform_request "/foo"
80
+
81
+ expect(fake_redis.get("/foo:ttl")).to eq(60)
82
+ end
43
83
  end
44
84
 
45
85
  describe "api_url" do
@@ -36,4 +36,26 @@ describe TeamRequest do
36
36
  end
37
37
  end
38
38
 
39
+ describe "getbyid" do
40
+ let(:request) { TeamRequest.new "api_key", "euw" }
41
+ let(:fixture) { load_fixture 'team', TeamRequest.api_version, 'getbyid' }
42
+
43
+ subject do
44
+ expect(request.class).to receive(:get).with(request.api_url("team/TEAM-c80824c9-c568-42de-bdbb-271543b209e1")).and_return fixture
45
+ request.getbyid "TEAM-c80824c9-c568-42de-bdbb-271543b209e1"
46
+ end
47
+
48
+ it 'requires a summoner' do
49
+ expect { request.getbyid }.to raise_error ArgumentError
50
+ end
51
+
52
+ it 'returns a Team' do
53
+ expect(subject).to be_a Lol::Team
54
+ end
55
+
56
+ it 'fetches Team from the API' do
57
+ expect(subject.full_id).to eq "TEAM-c80824c9-c568-42de-bdbb-271543b209e1"
58
+ end
59
+ end
60
+
39
61
  end
metadata CHANGED
@@ -1,243 +1,257 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.10
4
+ version: 0.9.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giovanni Intini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-10 00:00:00.000000000 Z
11
+ date: 2014-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: yard
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: redcarpet
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: guard-rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: ZenTest
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: autotest-growl
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '>='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: autotest-fsevent
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - '>='
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - '>='
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: codeclimate-test-reporter
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - '>='
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - '>='
150
+ - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: coveralls
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - '>='
157
+ - - ">="
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - '>='
164
+ - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: vcr
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - '>='
171
+ - - ">="
172
172
  - !ruby/object:Gem::Version
173
173
  version: '0'
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - '>='
178
+ - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: webmock
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
- - - '>='
185
+ - - ">="
186
186
  - !ruby/object:Gem::Version
187
187
  version: 1.8.0
188
- - - <
188
+ - - "<"
189
189
  - !ruby/object:Gem::Version
190
190
  version: '1.16'
191
191
  type: :development
192
192
  prerelease: false
193
193
  version_requirements: !ruby/object:Gem::Requirement
194
194
  requirements:
195
- - - '>='
195
+ - - ">="
196
196
  - !ruby/object:Gem::Version
197
197
  version: 1.8.0
198
- - - <
198
+ - - "<"
199
199
  - !ruby/object:Gem::Version
200
200
  version: '1.16'
201
201
  - !ruby/object:Gem::Dependency
202
202
  name: awesome_print
203
203
  requirement: !ruby/object:Gem::Requirement
204
204
  requirements:
205
- - - '>='
205
+ - - ">="
206
206
  - !ruby/object:Gem::Version
207
207
  version: '0'
208
208
  type: :development
209
209
  prerelease: false
210
210
  version_requirements: !ruby/object:Gem::Requirement
211
211
  requirements:
212
- - - '>='
212
+ - - ">="
213
213
  - !ruby/object:Gem::Version
214
214
  version: '0'
215
215
  - !ruby/object:Gem::Dependency
216
216
  name: httparty
217
217
  requirement: !ruby/object:Gem::Requirement
218
218
  requirements:
219
- - - '>='
219
+ - - ">="
220
220
  - !ruby/object:Gem::Version
221
221
  version: '0'
222
222
  type: :runtime
223
223
  prerelease: false
224
224
  version_requirements: !ruby/object:Gem::Requirement
225
225
  requirements:
226
- - - '>='
226
+ - - ">="
227
227
  - !ruby/object:Gem::Version
228
228
  version: '0'
229
229
  - !ruby/object:Gem::Dependency
230
230
  name: activesupport
231
231
  requirement: !ruby/object:Gem::Requirement
232
232
  requirements:
233
- - - '>='
233
+ - - ">="
234
234
  - !ruby/object:Gem::Version
235
235
  version: '0'
236
236
  type: :runtime
237
237
  prerelease: false
238
238
  version_requirements: !ruby/object:Gem::Requirement
239
239
  requirements:
240
- - - '>='
240
+ - - ">="
241
+ - !ruby/object:Gem::Version
242
+ version: '0'
243
+ - !ruby/object:Gem::Dependency
244
+ name: redis
245
+ requirement: !ruby/object:Gem::Requirement
246
+ requirements:
247
+ - - ">="
248
+ - !ruby/object:Gem::Version
249
+ version: '0'
250
+ type: :runtime
251
+ prerelease: false
252
+ version_requirements: !ruby/object:Gem::Requirement
253
+ requirements:
254
+ - - ">="
241
255
  - !ruby/object:Gem::Version
242
256
  version: '0'
243
257
  description: Ruby wrapper to Riot Games API. Maps results to full blown ruby objects.
@@ -247,10 +261,10 @@ executables: []
247
261
  extensions: []
248
262
  extra_rdoc_files: []
249
263
  files:
250
- - .autotest
251
- - .gitignore
252
- - .rspec
253
- - .travis.yml
264
+ - ".autotest"
265
+ - ".gitignore"
266
+ - ".rspec"
267
+ - ".travis.yml"
254
268
  - Gemfile
255
269
  - Guardfile
256
270
  - LICENSE.txt
@@ -315,6 +329,7 @@ files:
315
329
  - spec/fixtures/v1/get-summoner-spell-by-id.json
316
330
  - spec/fixtures/v1/get-summoner-spell.json
317
331
  - spec/fixtures/v2.2/get-team.json
332
+ - spec/fixtures/v2.2/getbyid-team.json
318
333
  - spec/fixtures/v2.3/get-league.json
319
334
  - spec/lol/champion_request_spec.rb
320
335
  - spec/lol/champion_spec.rb
@@ -358,17 +373,17 @@ require_paths:
358
373
  - lib
359
374
  required_ruby_version: !ruby/object:Gem::Requirement
360
375
  requirements:
361
- - - '>='
376
+ - - ">="
362
377
  - !ruby/object:Gem::Version
363
378
  version: '0'
364
379
  required_rubygems_version: !ruby/object:Gem::Requirement
365
380
  requirements:
366
- - - '>='
381
+ - - ">="
367
382
  - !ruby/object:Gem::Version
368
383
  version: '0'
369
384
  requirements: []
370
385
  rubyforge_project:
371
- rubygems_version: 2.2.0
386
+ rubygems_version: 2.2.2
372
387
  signing_key:
373
388
  specification_version: 4
374
389
  summary: Ruby wrapper to Riot Games API
@@ -396,6 +411,7 @@ test_files:
396
411
  - spec/fixtures/v1/get-summoner-spell-by-id.json
397
412
  - spec/fixtures/v1/get-summoner-spell.json
398
413
  - spec/fixtures/v2.2/get-team.json
414
+ - spec/fixtures/v2.2/getbyid-team.json
399
415
  - spec/fixtures/v2.3/get-league.json
400
416
  - spec/lol/champion_request_spec.rb
401
417
  - spec/lol/champion_spec.rb