ruby-lol 0.9.11 → 0.9.12

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: f96a74077c549229c2719763486c3bcd9bd8da25
4
- data.tar.gz: 32f1aeb7a7aed7c6e0bab87f3ffeb23d286473e2
3
+ metadata.gz: b41e63342b89011c396472e3fbb587e38330d193
4
+ data.tar.gz: 7ae6f9ce17f6ca158dd64e5846f74754158db8a2
5
5
  SHA512:
6
- metadata.gz: 4623f57302ba2cd3faf1620d138397cceaa81217713c57d0319f1298e31f752ae7ff2b4da124adf154ba73f6061b873bfd952e3e877dd79a98ee750fb62599c1
7
- data.tar.gz: af511b335a6fe0412e53e1bc2939cdbbdd9fb8917dddc0f1717fd3b4031b1e0611d8f9c3f938a3bc7b2ea65428aec3b71c5cacdedb93dc1a37d454646ca22d62
6
+ metadata.gz: ab7f044aa9d234d80b24dd53fdb0d59d4fe2fdc9aeb681034086b010364535084538ef95162d31c288028dbd7694da9d5f749bbf41e9ef15048996073ca817f1
7
+ data.tar.gz: 181b8ecd33721fc0ed9b32621a185357d1fe6b7a5c2cc29b92002eec29f9772d8e8d84dc47550f636f1cb560287df637ee39e5fd1608fb6f23791e97b340748f
data/.travis.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  rvm: 2.0.0
2
+ services: redis-server
2
3
  addons:
3
4
  code_climate:
4
- repo_token: c98576197ae22bdd3bede9cd3cdfdad33fac26bfdddb1e5f2bbc4fb535812185
5
+ repo_token: c98576197ae22bdd3bede9cd3cdfdad33fac26bfdddb1e5f2bbc4fb535812185
data/demo/demo.rb CHANGED
@@ -6,11 +6,9 @@ require "lol"
6
6
 
7
7
  include Lol
8
8
 
9
- client = Client.new "18b7c486-0d5a-459f-9d60-cf8776b154c6"
10
- intinig = client.summoner.by_name "intinig"
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
- my_league = leagues.first
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
@@ -1,3 +1,3 @@
1
1
  module Lol
2
- VERSION = "0.9.11"
2
+ VERSION = "0.9.12"
3
3
  end
@@ -51,56 +51,70 @@ describe Request do
51
51
  expect { subject.perform_request "foo"}.to raise_error(NotFound)
52
52
  end
53
53
 
54
- it "is cached" do
55
- class FakeRedis < Redis
56
- def initialize options = {}
57
- @store = {}
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
- def get key
61
- @store[key]
62
- end
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
- def set key, val
65
- @store[key] = val
66
- end
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
- 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"
88
+ it "serializes cached responses" do
89
+ expect(JSON).to receive(:parse)
90
+ request.perform_request "/foo"
91
+ end
80
92
 
81
- expect(fake_redis.get("/foo:ttl")).to eq(60)
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
- describe "api_url" do
86
- it "defaults on Request#region" do
87
- expect(subject.api_url("bar")).to match(/\/euw\//)
88
- end
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
- it "defaults on Reques.api_version" do
91
- expect(subject.api_url("bar")).to match(/\/v1.1\//)
92
- end
104
+ it "defaults on Reques.api_version" do
105
+ expect(subject.api_url("bar")).to match(/\/v1.1\//)
106
+ end
93
107
 
94
- it "a path" do
95
- expect { subject.api_url }.to raise_error(ArgumentError)
96
- end
108
+ it "a path" do
109
+ expect { subject.api_url }.to raise_error(ArgumentError)
110
+ end
97
111
 
98
- it "returns a full fledged api url" do
99
- expect(subject.api_url("bar")).to eq("http://prod.api.pvp.net/api/lol/euw/v1.1/bar?api_key=api_key")
100
- end
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
- it "optionally accept query string parameters" do
103
- 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")
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.11
4
+ version: 0.9.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giovanni Intini