ruby-lol 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+ require "lol"
3
+
4
+ include Lol
5
+
6
+ describe Champion do
7
+ it_behaves_like 'Lol model' do
8
+ let(:valid_attributes) { { id: 1 } }
9
+ end
10
+
11
+ %w(id name active attack_rank defense_rank magic_rank difficulty_rank bot_enabled free_to_play bot_mm_enabled ranked_play_enabled).each do |attribute|
12
+ describe "#{attribute} attribute" do
13
+ it_behaves_like 'plain attribute' do
14
+ let(:attribute) { attribute }
15
+ let(:attribute_value) { 'asd' }
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,159 @@
1
+ require "spec_helper"
2
+ require "lol"
3
+
4
+ include Lol
5
+
6
+ describe Client do
7
+ subject { Client.new "foo" }
8
+
9
+ describe "#new" do
10
+ it "requires an API key argument" do
11
+ expect { Client.new }.to raise_error(ArgumentError)
12
+ end
13
+
14
+ it "accepts a region argument" do
15
+ expect { Client.new("foo", :region => "na") }.not_to raise_error
16
+ end
17
+
18
+ it "defaults on EUW as a region" do
19
+ expect(subject.region).to eq("euw")
20
+ end
21
+ end
22
+
23
+ describe "#get" do
24
+ it "calls HTTParty get" do
25
+ expect(Client).to receive(:get).and_return(error_401)
26
+ expect { subject.get "foo"}.to raise_error(InvalidAPIResponse)
27
+ end
28
+
29
+ it "handles 401" do
30
+ expect(Client).to receive(:get).and_return(error_401)
31
+ expect { subject.champion }.to raise_error(InvalidAPIResponse)
32
+ end
33
+ end
34
+
35
+ describe "#champion" do
36
+ it "defaults to v1.1" do
37
+ expect(subject).to receive(:champion11)
38
+ subject.champion
39
+ end
40
+ end
41
+
42
+ describe "#champion11" do
43
+ let(:client) { Client.new "foo" }
44
+
45
+ subject do
46
+ expect(client).to receive(:get).with(client.api_url("v1.1", "champion")).and_return(load_fixture("champion", "v1.1", "get"))
47
+
48
+ client.champion11
49
+ end
50
+
51
+ it "returns an array" do
52
+ expect(subject).to be_a(Array)
53
+ end
54
+
55
+ it "returns an array of champions" do
56
+ expect(subject.map {|e| e.class}.uniq).to eq([Champion])
57
+ end
58
+
59
+ it "fetches champions from the API" do
60
+ expect(subject.size).to eq(load_fixture("champion", "v1.1", "get")["champions"].size)
61
+ end
62
+ end
63
+
64
+ describe '#game' do
65
+ it 'requires a summoner id' do
66
+ expect { subject.game }.to raise_error ArgumentError
67
+ end
68
+
69
+ it 'defaults to v1.1' do
70
+ expect(subject).to receive(:game11).with 'foo'
71
+ subject.game 'foo'
72
+ end
73
+ end
74
+
75
+ describe '#game11' do
76
+ let(:client) { Client.new 'foo' }
77
+
78
+ subject do
79
+ expect(Client).to receive(:get).with(client.api_url('v1.1', "game/by-summoner/1/recent")).and_return load_fixture('game', 'v1.1', 'get')
80
+ client.game11 1
81
+ end
82
+
83
+ it 'returns an array' do
84
+ expect(subject).to be_a Array
85
+ end
86
+
87
+ it 'returns an array of Games' do
88
+ expect(subject.map(&:class).uniq).to eq [Game]
89
+ end
90
+
91
+ it 'fetches games from the API' do
92
+ expect(subject.size).to eq load_fixture('game', 'v1.1', 'get')['games'].size
93
+ end
94
+ end
95
+
96
+ describe "#region" do
97
+ it "returns current region" do
98
+ expect(subject.region).to eq("euw")
99
+ end
100
+
101
+ it "can be set to a new region" do
102
+ subject.region = "NA"
103
+ expect(subject.region).to eq("NA")
104
+ end
105
+ end
106
+
107
+ describe "#api_key" do
108
+ it "returns an api key" do
109
+ expect(subject.api_key).to eq("foo")
110
+ end
111
+
112
+ it "is read_only" do
113
+ expect { subject.api_key = "bar" }.to raise_error(NoMethodError)
114
+ end
115
+ end
116
+
117
+ describe "api_url" do
118
+ it "defaults on Client#region" do
119
+ expect(subject.api_url("foo", "bar")).to match(/\/euw\//)
120
+ end
121
+
122
+ it "requires a version and a path" do
123
+ expect { subject.api_url("foo") }.to raise_error(ArgumentError)
124
+ end
125
+
126
+ it "returns a full fledged api url" do
127
+ expect(subject.api_url("foo", "bar")).to eq("http://prod.api.pvp.net/api/euw/foo/bar?api_key=foo")
128
+ end
129
+
130
+ it "has lol if url is v1.1" do
131
+ expect(subject.api_url("v1.1", "foo")).to eq("http://prod.api.pvp.net/api/lol/euw/v1.1/foo?api_key=foo")
132
+ end
133
+
134
+ it "does not have lol if url is v2.1 or greater" do
135
+ expect(subject.api_url("v2.1", "foo")).to eq("http://prod.api.pvp.net/api/euw/v2.1/foo?api_key=foo")
136
+ end
137
+ end
138
+
139
+ describe "league" do
140
+ it "calls latest version of league" do
141
+ expect(subject).to receive(:league21)
142
+ subject.league("foo")
143
+ end
144
+ end
145
+
146
+ describe "league21" do
147
+ let(:client) { Client.new "foo" }
148
+
149
+ subject do
150
+ expect(client).to receive(:get).with(client.api_url("v2.1", "league/by-summoner/foo")).and_return(load_fixture("league", "v2.1", "get"))
151
+
152
+ client.league21("foo")
153
+ end
154
+
155
+ it "returns an array of Leagues" do
156
+ expect(subject.map(&:class).uniq).to eq([League])
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,44 @@
1
+ require "spec_helper"
2
+ require "lol"
3
+
4
+ include Lol
5
+
6
+ describe Game do
7
+ it_behaves_like 'Lol model' do
8
+ let(:valid_attributes) { { game_id: 1 } }
9
+ end
10
+
11
+ %w(champion_id create_date_str game_id game_mode game_type invalid level map_id spell1 spell2 sub_type team_id).each do |attribute|
12
+ describe "#{attribute} attribute" do
13
+ it_behaves_like 'plain attribute' do
14
+ let(:attribute) { attribute }
15
+ let(:attribute_value) { 'asd' }
16
+ end
17
+ end
18
+ end
19
+
20
+ describe 'fellow_players attribute' do
21
+ it_behaves_like 'collection attribute' do
22
+ let(:attribute) { 'fellow_players' }
23
+ let(:attribute_class) { Player }
24
+ end
25
+ end
26
+
27
+ describe 'statistics attribute' do
28
+ it_behaves_like 'collection attribute' do
29
+ let(:attribute) { 'statistics' }
30
+ let(:attribute_class) { Statistic }
31
+ end
32
+ end
33
+
34
+ describe 'create_date attribute' do
35
+ it_behaves_like 'plain attribute' do
36
+ let(:attribute) { 'create_date' }
37
+ let(:attribute_value) { DateTime.now }
38
+ end
39
+
40
+ it "parses the value is it's not a DateTime object" do
41
+ expect(Game.new(:create_date => Time.now.to_i).create_date).to be_a DateTime
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,2 @@
1
+ require "spec_helper"
2
+ require "lol"
@@ -0,0 +1,19 @@
1
+ require "lol"
2
+ require "spec_helper"
3
+
4
+ include Lol
5
+
6
+ describe Player do
7
+ it_behaves_like 'Lol model' do
8
+ let(:valid_attributes) { { team_id: 1 } }
9
+ end
10
+
11
+ %w(champion_id summoner_id team_id).each do |attribute|
12
+ describe "#{attribute} attribute" do
13
+ it_behaves_like 'plain attribute' do
14
+ let(:attribute) { attribute }
15
+ let(:attribute_value) { 'asd' }
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require "lol"
2
+ require "spec_helper"
3
+
4
+ include Lol
5
+
6
+ describe Statistic do
7
+ it_behaves_like 'Lol model' do
8
+ let(:valid_attributes) { { id: 1 } }
9
+ end
10
+
11
+ %w(id name value).each do |attribute|
12
+ describe "#{attribute} attribute" do
13
+ it_behaves_like 'plain attribute' do
14
+ let(:attribute) { attribute }
15
+ let(:attribute_value) { 'asd' }
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,45 @@
1
+ require "rspec"
2
+ require "simplecov"
3
+ require "coveralls"
4
+ require "codeclimate-test-reporter"
5
+ require "vcr"
6
+
7
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
8
+
9
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
10
+ Coveralls::SimpleCov::Formatter,
11
+ SimpleCov::Formatter::HTMLFormatter,
12
+ ]
13
+
14
+ SimpleCov.start
15
+
16
+ VCR.configure do |c|
17
+ c.cassette_library_dir = __dir__ + '/../fixtures/vcr_cassettes'
18
+ c.hook_into :webmock
19
+ c.ignore_hosts 'codeclimate.com'
20
+ c.configure_rspec_metadata!
21
+ end
22
+
23
+ def underscore s
24
+ s.to_s.scan(/[A-Z][a-z]*/).join("_").downcase
25
+ end
26
+
27
+ def camelize s
28
+ s[0] + s.to_s.split("_").each {|s| s.capitalize! }.join("")[1..-1]
29
+ end
30
+
31
+ def load_fixture subject, version, method
32
+ JSON.parse(File.read(__dir__ + "/fixtures/#{version}/#{method}-#{subject}.json", :encoding => "utf-8"))
33
+ end
34
+
35
+ def expect_init_attribute subject, attribute
36
+ expect(subject.new(camelize(attribute) => "foo").send(attribute)).to eq("foo")
37
+ end
38
+
39
+ def expect_read_only_attribute subject, attribute
40
+ expect { subject.new.send("#{attribute}=".to_sym, "bar") }.to raise_error(NoMethodError)
41
+ end
42
+
43
+ def error_401
44
+ {"status" => {"message" => "Foo", "status_code" => 401}}
45
+ end
@@ -0,0 +1,91 @@
1
+ shared_examples 'attribute' do
2
+ let(:setter) { "#{attribute}=" }
3
+
4
+ it 'is read only' do
5
+ expect(subject).to_not respond_to setter
6
+ end
7
+ end
8
+
9
+ shared_examples 'Lol model' do
10
+ let(:subject_class) { subject.class }
11
+
12
+ describe '#new' do
13
+ it "takes an option hash as argument" do
14
+ expect { subject_class.new valid_attributes }.not_to raise_error
15
+ end
16
+
17
+ it 'raises an error if an attribute is not allowed' do
18
+ expect { subject_class.new({ :foo => :bar }) }.to raise_error NoMethodError
19
+ end
20
+
21
+ it 'sets the given option hash as #raw' do
22
+ expect(subject_class.new(valid_attributes).raw).to eq valid_attributes
23
+ end
24
+ end
25
+
26
+ describe '#raw' do
27
+ it_behaves_like 'attribute' do
28
+ let(:attribute) { 'raw' }
29
+ end
30
+ end
31
+ end
32
+
33
+ shared_examples 'plain attribute' do
34
+ let(:subject_class) { subject.class }
35
+ let(:setter) { "#{attribute}=" }
36
+
37
+ it_behaves_like 'attribute'
38
+
39
+ context 'during #new' do
40
+ it 'is set if the hash contains the attribute name "underscored"' do
41
+ model = subject_class.new attribute => attribute_value
42
+ expect(model.send attribute).to eq attribute_value
43
+ end
44
+
45
+ it 'is set if the hash contains the attribute name "camelized"' do
46
+ model = subject_class.new camelize(attribute) => attribute_value
47
+ expect(model.send attribute).to eq attribute_value
48
+ end
49
+ end
50
+ end
51
+
52
+ shared_examples 'collection attribute' do
53
+ let(:subject_class) { subject.class }
54
+ let(:setter) { "#{attribute}=" }
55
+
56
+ it_behaves_like 'attribute'
57
+
58
+ it 'is sets if the hash contains the attribute name "underscored"' do
59
+ model = subject_class.new({ attribute => [{}, {}] })
60
+ expect(model.send(attribute).size).to eq 2
61
+ end
62
+
63
+ it 'is set if the hash contains the attribute name "camelized"' do
64
+ model = subject_class.new({ camelize(attribute) => [{}, {}] })
65
+ expect(model.send(attribute).size).to eq 2
66
+ end
67
+
68
+ context 'if the value is not enumerable' do
69
+ it 'raises an error' do
70
+ expect {
71
+ subject_class.new({ attribute => 'asd' })
72
+ }.to raise_error NoMethodError
73
+ end
74
+ end
75
+
76
+ context 'if the value is enumerable' do
77
+ context 'and contains items as Hash' do
78
+ it 'parses the item' do
79
+ model = subject_class.new attribute => [{}]
80
+ expect(model.send(attribute).map(&:class).uniq).to eq [attribute_class]
81
+ end
82
+ end
83
+
84
+ context 'and contains items as non-Hash' do
85
+ it 'does not parse the item' do
86
+ model = subject_class.new attribute => [attribute_class.new, Object.new]
87
+ expect(model.send(attribute).map(&:class).uniq).to eq [attribute_class, Object]
88
+ end
89
+ end
90
+ end
91
+ end
metadata ADDED
@@ -0,0 +1,301 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-lol
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Giovanni Intini
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: yard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: redcarpet
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: ZenTest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: autotest-growl
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: autotest-fsevent
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: codeclimate-test-reporter
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: coveralls
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: vcr
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: webmock
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - '>='
172
+ - !ruby/object:Gem::Version
173
+ version: 1.8.0
174
+ - - <
175
+ - !ruby/object:Gem::Version
176
+ version: '1.16'
177
+ type: :development
178
+ prerelease: false
179
+ version_requirements: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - '>='
182
+ - !ruby/object:Gem::Version
183
+ version: 1.8.0
184
+ - - <
185
+ - !ruby/object:Gem::Version
186
+ version: '1.16'
187
+ - !ruby/object:Gem::Dependency
188
+ name: awesome_print
189
+ requirement: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - '>='
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ type: :development
195
+ prerelease: false
196
+ version_requirements: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - '>='
199
+ - !ruby/object:Gem::Version
200
+ version: '0'
201
+ - !ruby/object:Gem::Dependency
202
+ name: httparty
203
+ requirement: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - '>='
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ type: :runtime
209
+ prerelease: false
210
+ version_requirements: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - '>='
213
+ - !ruby/object:Gem::Version
214
+ version: '0'
215
+ - !ruby/object:Gem::Dependency
216
+ name: activesupport
217
+ requirement: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - '>='
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ type: :runtime
223
+ prerelease: false
224
+ version_requirements: !ruby/object:Gem::Requirement
225
+ requirements:
226
+ - - '>='
227
+ - !ruby/object:Gem::Version
228
+ version: '0'
229
+ description: Ruby wrapper to Riot Games API. Maps results to full blown ruby objects.
230
+ email:
231
+ - giovanni@mikamai.com
232
+ executables: []
233
+ extensions: []
234
+ extra_rdoc_files: []
235
+ files:
236
+ - .autotest
237
+ - .gitignore
238
+ - .rspec
239
+ - .travis.yml
240
+ - Gemfile
241
+ - LICENSE.txt
242
+ - README.md
243
+ - Rakefile
244
+ - lib/lol.rb
245
+ - lib/lol/champion.rb
246
+ - lib/lol/client.rb
247
+ - lib/lol/game.rb
248
+ - lib/lol/league.rb
249
+ - lib/lol/model.rb
250
+ - lib/lol/player.rb
251
+ - lib/lol/statistic.rb
252
+ - lib/lol/version.rb
253
+ - ruby-lol.gemspec
254
+ - spec/fixtures/v1.1/get-champion.json
255
+ - spec/fixtures/v1.1/get-game.json
256
+ - spec/fixtures/v2.1/get-league.json
257
+ - spec/lol/champion_spec.rb
258
+ - spec/lol/client_spec.rb
259
+ - spec/lol/game_spec.rb
260
+ - spec/lol/league_spec.rb
261
+ - spec/lol/player_spec.rb
262
+ - spec/lol/statistic_spec.rb
263
+ - spec/spec_helper.rb
264
+ - spec/support/model_helpers.rb
265
+ homepage: https://github.com/mikamai/ruby-lol
266
+ licenses:
267
+ - MIT
268
+ metadata: {}
269
+ post_install_message:
270
+ rdoc_options: []
271
+ require_paths:
272
+ - lib
273
+ required_ruby_version: !ruby/object:Gem::Requirement
274
+ requirements:
275
+ - - '>='
276
+ - !ruby/object:Gem::Version
277
+ version: '0'
278
+ required_rubygems_version: !ruby/object:Gem::Requirement
279
+ requirements:
280
+ - - '>='
281
+ - !ruby/object:Gem::Version
282
+ version: '0'
283
+ requirements: []
284
+ rubyforge_project:
285
+ rubygems_version: 2.0.6
286
+ signing_key:
287
+ specification_version: 4
288
+ summary: Ruby wrapper to Riot Games API
289
+ test_files:
290
+ - spec/fixtures/v1.1/get-champion.json
291
+ - spec/fixtures/v1.1/get-game.json
292
+ - spec/fixtures/v2.1/get-league.json
293
+ - spec/lol/champion_spec.rb
294
+ - spec/lol/client_spec.rb
295
+ - spec/lol/game_spec.rb
296
+ - spec/lol/league_spec.rb
297
+ - spec/lol/player_spec.rb
298
+ - spec/lol/statistic_spec.rb
299
+ - spec/spec_helper.rb
300
+ - spec/support/model_helpers.rb
301
+ has_rdoc: