ruby-lol 0.9.11 → 0.9.12
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/.travis.yml +2 -1
- data/demo/demo.rb +4 -6
- data/lib/lol/request.rb +2 -2
- data/lib/lol/version.rb +1 -1
- data/spec/lol/request_spec.rb +51 -37
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b41e63342b89011c396472e3fbb587e38330d193
|
4
|
+
data.tar.gz: 7ae6f9ce17f6ca158dd64e5846f74754158db8a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab7f044aa9d234d80b24dd53fdb0d59d4fe2fdc9aeb681034086b010364535084538ef95162d31c288028dbd7694da9d5f749bbf41e9ef15048996073ca817f1
|
7
|
+
data.tar.gz: 181b8ecd33721fc0ed9b32621a185357d1fe6b7a5c2cc29b92002eec29f9772d8e8d84dc47550f636f1cb560287df637ee39e5fd1608fb6f23791e97b340748f
|
data/.travis.yml
CHANGED
data/demo/demo.rb
CHANGED
@@ -6,11 +6,9 @@ require "lol"
|
|
6
6
|
|
7
7
|
include Lol
|
8
8
|
|
9
|
-
client = Client.new "
|
10
|
-
intinig = client.summoner.by_name
|
9
|
+
client = Client.new ENV["RIOT_GAMES_API_KEY"], region: "euw", redis: "redis://localhost:6379"
|
10
|
+
intinig = client.summoner.by_name("intinig").first
|
11
11
|
leagues = client.league.get intinig.id
|
12
|
-
|
13
|
-
|
14
|
-
my_league.entries.select {|entry| entry.player_or_team_name == "intinig"}.each do |entry|
|
15
|
-
ap entry
|
12
|
+
leagues.map(&:entries).each do |league_entry|
|
13
|
+
ap league_entry
|
16
14
|
end
|
data/lib/lol/request.rb
CHANGED
@@ -40,7 +40,7 @@ module Lol
|
|
40
40
|
# @return [String] raw response of the call
|
41
41
|
def perform_request url
|
42
42
|
if cached? && result = store.get(url)
|
43
|
-
return result
|
43
|
+
return JSON.parse(result)
|
44
44
|
end
|
45
45
|
|
46
46
|
response = self.class.get(url)
|
@@ -48,7 +48,7 @@ module Lol
|
|
48
48
|
raise InvalidAPIResponse.new(response["status"]["message"]) if response.is_a?(Hash) && response["status"]
|
49
49
|
|
50
50
|
if cached?
|
51
|
-
store.set url, response
|
51
|
+
store.set url, response.to_json
|
52
52
|
store.expire url, ttl
|
53
53
|
end
|
54
54
|
|
data/lib/lol/version.rb
CHANGED
data/spec/lol/request_spec.rb
CHANGED
@@ -51,56 +51,70 @@ describe Request do
|
|
51
51
|
expect { subject.perform_request "foo"}.to raise_error(NotFound)
|
52
52
|
end
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
context "caching" do
|
55
|
+
before :all do
|
56
|
+
class FakeRedis < Redis
|
57
|
+
def initialize options = {}
|
58
|
+
@store = {}
|
59
|
+
end
|
60
|
+
|
61
|
+
def get key
|
62
|
+
@store[key]
|
63
|
+
end
|
64
|
+
|
65
|
+
def set key, val
|
66
|
+
@store[key] = val
|
67
|
+
end
|
68
|
+
|
69
|
+
def expire key, ttl
|
70
|
+
@store["#{key}:ttl"] = ttl
|
71
|
+
end
|
58
72
|
end
|
73
|
+
end
|
59
74
|
|
60
|
-
|
61
|
-
|
62
|
-
|
75
|
+
let(:fake_redis) { FakeRedis.new }
|
76
|
+
let(:request) { Request.new "api_key", "euw", {redis: fake_redis, ttl: 60, cached: true }}
|
77
|
+
before :each do
|
78
|
+
expect(request.class).to receive(:get).with("/foo").and_return({foo: "bar"})
|
79
|
+
first_result = request.perform_request "/foo"
|
80
|
+
end
|
63
81
|
|
64
|
-
|
65
|
-
|
66
|
-
|
82
|
+
it "is cached" do
|
83
|
+
expect(request.class).not_to receive(:get)
|
84
|
+
request.perform_request "/foo"
|
67
85
|
|
68
|
-
def expire key, ttl
|
69
|
-
@store["#{key}:ttl"] = ttl
|
70
|
-
end
|
71
86
|
end
|
72
87
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
expect(request.class).not_to receive(:get)
|
79
|
-
request.perform_request "/foo"
|
88
|
+
it "serializes cached responses" do
|
89
|
+
expect(JSON).to receive(:parse)
|
90
|
+
request.perform_request "/foo"
|
91
|
+
end
|
80
92
|
|
81
|
-
|
93
|
+
it "sets ttl" do
|
94
|
+
expect(fake_redis.get("/foo:ttl")).to eq(60)
|
95
|
+
end
|
82
96
|
end
|
83
97
|
end
|
84
98
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
99
|
+
describe "api_url" do
|
100
|
+
it "defaults on Request#region" do
|
101
|
+
expect(subject.api_url("bar")).to match(/\/euw\//)
|
102
|
+
end
|
89
103
|
|
90
|
-
|
91
|
-
|
92
|
-
|
104
|
+
it "defaults on Reques.api_version" do
|
105
|
+
expect(subject.api_url("bar")).to match(/\/v1.1\//)
|
106
|
+
end
|
93
107
|
|
94
|
-
|
95
|
-
|
96
|
-
|
108
|
+
it "a path" do
|
109
|
+
expect { subject.api_url }.to raise_error(ArgumentError)
|
110
|
+
end
|
97
111
|
|
98
|
-
|
99
|
-
|
100
|
-
|
112
|
+
it "returns a full fledged api url" do
|
113
|
+
expect(subject.api_url("bar")).to eq("http://prod.api.pvp.net/api/lol/euw/v1.1/bar?api_key=api_key")
|
114
|
+
end
|
101
115
|
|
102
|
-
|
103
|
-
|
116
|
+
it "optionally accept query string parameters" do
|
117
|
+
expect(subject.api_url("foo", a: 'b')).to eq("http://prod.api.pvp.net/api/lol/euw/v1.1/foo?a=b&api_key=api_key")
|
118
|
+
end
|
104
119
|
end
|
105
120
|
end
|
106
|
-
end
|