vainglory-api 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,246 @@
1
+ require 'spec_helper'
2
+
3
+ describe VaingloryAPI::Client, vcr: true do
4
+ subject(:klass) { Object.const_get(self.class.top_level_description) }
5
+ let(:valid_api_key) { 'valid_api_key' }
6
+ let(:client) { klass.new(valid_api_key) }
7
+ let(:cached_matches) { let_cassette('matches') { client.matches } }
8
+ let(:cached_players) { cached_matches.included.select { |i| i.type == 'player' }}
9
+
10
+ context 'metadata' do
11
+ it 'returns an error with an invalid API key' do
12
+ VCR.use_cassette('api_key', record: :new_episodes) do
13
+ response = klass.new('invalid-api-key').samples
14
+ expects_error_response(response, 401)
15
+ end
16
+ end
17
+
18
+ it 'returns success and API rate limit information' do
19
+ VCR.use_cassette('samples', record: :new_episodes) do
20
+ response = client.samples
21
+
22
+ expects_success_response(response)
23
+ expects_presence(response, :data)
24
+ expect(response.rate_limit).to be_a(Integer)
25
+ expect(response.rate_remaining).to be_a(Integer)
26
+ expect(response.rate_reset).to be_a(Integer)
27
+ end
28
+ end
29
+
30
+ it 'supports multiple regions' do
31
+ VCR.use_cassette('samples', record: :new_episodes) do
32
+ %w(eu sa ea sg).each do |region|
33
+ response = klass.new(valid_api_key, region).samples
34
+ expects_success_response(response)
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ context '#status' do
41
+ it 'returns a status object' do
42
+ VCR.use_cassette('status') do
43
+ response = client.status
44
+
45
+ expects_success_response(response)
46
+ expects_presence(response, :data)
47
+ expect(response.data.type).to be_a(String)
48
+ expect(response.data.id).to be_a(String)
49
+ expect(response.data.attributes.releasedAt).to be_a(String)
50
+ expect(response.data.attributes.version).to be_a(String)
51
+ end
52
+ end
53
+ end
54
+
55
+ context '#players' do
56
+ it 'returns an array of players with a valid name' do
57
+ VCR.use_cassette('players', record: :new_episodes) do
58
+ valid_names = cached_players[0, 2].map { |p| p.attributes.name }
59
+ response = client.players(*valid_names)
60
+
61
+ expects_success_response(response)
62
+ expects_presence(response, :data, :links, :meta)
63
+ expect(response.data).to be_a(Array)
64
+ expect(response.data.length).to be > 0
65
+ end
66
+ end
67
+
68
+ it 'returns error with an valid name' do
69
+ VCR.use_cassette('players', record: :new_episodes) do
70
+ response = client.players('TheRealKrul')
71
+ expects_error_response(response)
72
+ end
73
+ end
74
+ end
75
+
76
+ context '#player' do
77
+ it 'returns a player with a valid ID' do
78
+ VCR.use_cassette('player', record: :new_episodes) do
79
+ cached_player_id = cached_players.first.id
80
+ response = client.player(cached_player_id)
81
+
82
+ player = response.data
83
+
84
+ expects_success_response(response)
85
+ expects_presence(response, :data, :links, :meta)
86
+
87
+ expect(player.type).to eq 'player'
88
+ expect(player.id).to eq cached_player_id
89
+ expect(player.attributes.createdAt).to be_a(String)
90
+ expect(player.attributes.name).to be_a(String)
91
+ expect(player.attributes.shardId).to be_a(String)
92
+ expect(player.attributes.stats.level).to be_a(Integer)
93
+ expect(player.attributes.stats.lifetimeGold).to be_a(Float)
94
+ expect(player.attributes.stats.lossStreak).to be_a(Integer)
95
+ expect(player.attributes.stats.played).to be_a(Integer)
96
+ expect(player.attributes.stats.played_ranked).to be_a(Integer)
97
+ expect(player.attributes.stats.winStreak).to be_a(Integer)
98
+ expect(player.attributes.stats.wins).to be_a(Integer)
99
+ expect(player.attributes.stats.xp).to be_a(Integer)
100
+ expect(player.attributes.titleId).to be_a(String)
101
+ end
102
+ end
103
+
104
+ it 'returns an error with an invalid ID' do
105
+ VCR.use_cassette('players', record: :new_episodes) do
106
+ response = client.player('invalid-id')
107
+ expects_error_response(response)
108
+ end
109
+ end
110
+ end
111
+
112
+ context '#matches' do
113
+ it 'returns an array of matches' do
114
+ VCR.use_cassette('matches', record: :new_episodes) do
115
+ response = client.matches
116
+
117
+ expects_success_response(response)
118
+ expects_presence(response, :data, :included, :links, :meta)
119
+ expect(response.data).to be_a(Array)
120
+ expect(response.data.length).to be > 0
121
+ end
122
+ end
123
+
124
+ it 'returns the number of matches specified by a filter' do
125
+ VCR.use_cassette('matches', record: :new_episodes) do
126
+ response = client.matches('page[limit]' => 1)
127
+
128
+ expects_success_response(response)
129
+ expects_presence(response, :data, :included, :links, :meta)
130
+ expect(response.data).to be_a(Array)
131
+ expect(response.data.length).to eq 1
132
+ end
133
+ end
134
+
135
+ it 'returns an array of matches with valid player name filter' do
136
+ player_name = cached_players.first.attributes.name
137
+ VCR.use_cassette('matches', record: :new_episodes) do
138
+ response = client.matches('filter[playerNames]' => player_name)
139
+
140
+ expects_success_response(response)
141
+ expects_presence(response, :data, :included, :links, :meta)
142
+ expect(response.data).to be_a(Array)
143
+ expect(response.data.length).to be > 0
144
+ end
145
+ end
146
+
147
+ it 'returns an error with invalid player name filter' do
148
+ VCR.use_cassette('matches', record: :new_episodes) do
149
+ response = client.matches('filter[playerNames]' => 'TheRealKrul')
150
+ expects_error_response(response)
151
+ end
152
+ end
153
+ end
154
+
155
+ context '#match' do
156
+ it 'returns a match with a valid ID' do
157
+ VCR.use_cassette('match', record: :new_episodes) do
158
+ cached_match_id = cached_matches.data.first.id
159
+ response = client.match(cached_match_id)
160
+ game_match = response.data
161
+
162
+ expects_success_response(response)
163
+ expects_presence(response, :data, :included, :links, :meta)
164
+ expect(game_match.type).to eq 'match'
165
+ expect(game_match.id).to eq cached_match_id
166
+ expect(game_match.attributes.createdAt).to be_a(String)
167
+ expect(game_match.attributes.duration).to be_a(Integer)
168
+ expect(game_match.attributes.gameMode).to be_a(String)
169
+ expect(game_match.attributes.patchVersion).to be_a(String)
170
+ expect(game_match.attributes.shardId).to be_a(String)
171
+ expect(game_match.attributes.stats.endGameReason).to be_a(String)
172
+ expect(game_match.attributes.stats.queue).to be_a(String)
173
+ expect(game_match.attributes.titleId).to be_a(String)
174
+ expect(game_match.relationships.assets.data).to be_a(Array)
175
+ expect(game_match.relationships.assets.data[0].type).to be_a(String)
176
+ expect(game_match.relationships.assets.data[0].id).to be_a(String)
177
+ expect(game_match.relationships.rosters.data).to be_a(Array)
178
+ expect(game_match.relationships.rosters.data.length).to be_a(Integer)
179
+ expect(game_match.relationships.rounds.data).to be_a(Array)
180
+ expect(game_match.relationships.rounds.data.length).to be_a(Integer)
181
+ end
182
+ end
183
+
184
+ it 'returns an error with an invalid ID' do
185
+ VCR.use_cassette('match', record: :new_episodes) do
186
+ response = client.match('invalid-id')
187
+ expects_error_response(response)
188
+ end
189
+ end
190
+ end
191
+
192
+ context 'telemetry' do
193
+ it 'returns telemetry data for a valid URL' do
194
+ VCR.use_cassette('telemetry', record: :new_episodes) do
195
+ response = client.telemetry('https://gl-prod-us-east-1.s3.amazonaws.com/assets/semc-vainglory/na/2017/03/28/03/07/b0bb7faf-1363-11e7-b11e-0242ac110006-telemetry.json')
196
+
197
+ expects_success_response(response)
198
+ expect(response.data).to be_a Array
199
+ expect(response.data[0].time).to be_a(String)
200
+ expect(response.data[0].type).to be_a(String)
201
+ expect(response.data[0].payload.Team).to be_a(String)
202
+ expect(response.data[0].payload.Actor).to be_a(String)
203
+ end
204
+ end
205
+ end
206
+
207
+ context '#teams' do
208
+ it 'raises error' do
209
+ expect { client.teams }.to raise_error(NotImplementedError)
210
+ end
211
+ end
212
+
213
+ context '#team' do
214
+ it 'raises error' do
215
+ expect { client.team('team_id') }.to raise_error(NotImplementedError)
216
+ end
217
+ end
218
+
219
+ context '#link' do
220
+ it 'raises error' do
221
+ expect { client.link('link_id') }.to raise_error(NotImplementedError)
222
+ end
223
+ end
224
+
225
+ def expects_presence(obj, *attrs)
226
+ attrs.each do |attr_name|
227
+ expect(obj.send(attr_name)).to_not be_nil
228
+ end
229
+ end
230
+
231
+ def expects_success_response(response)
232
+ expect(response.code).to eq 200
233
+ expect(response.success?).to be true
234
+ end
235
+
236
+ def expects_error_response(response, response_code = 404)
237
+ expect(response.code).to eq response_code
238
+ expect(response.success?).to be false
239
+ end
240
+
241
+ def let_cassette(cassette_name)
242
+ VCR.use_cassette(cassette_name, record: :new_episodes) do
243
+ yield
244
+ end
245
+ end
246
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe VaingloryAPI do
4
+ subject(:klass) { Object.const_get(self.class.top_level_description) }
5
+
6
+ it 'allows instantiation of a Client' do
7
+ client = klass.new('API_KEY')
8
+ expect(client).to be_an_instance_of(klass::Client)
9
+ end
10
+ end
@@ -0,0 +1,116 @@
1
+ require 'webmock/rspec'
2
+ require 'vcr'
3
+ require 'rspec'
4
+ require 'simplecov'
5
+ require 'vainglory_api'
6
+
7
+ VCR.configure do |config|
8
+ config.cassette_library_dir = "spec/cassettes"
9
+ config.hook_into :webmock
10
+ end
11
+
12
+ SimpleCov.start
13
+
14
+ # This file was generated by the `rspec --init` command. Conventionally, all
15
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
16
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
17
+ # this file to always be loaded, without a need to explicitly require it in any
18
+ # files.
19
+ #
20
+ # Given that it is always loaded, you are encouraged to keep this file as
21
+ # light-weight as possible. Requiring heavyweight dependencies from this file
22
+ # will add to the boot time of your test suite on EVERY test run, even for an
23
+ # individual file that may not need all of that loaded. Instead, consider making
24
+ # a separate helper file that requires the additional dependencies and performs
25
+ # the additional setup, and require it from the spec files that actually need
26
+ # it.
27
+ #
28
+ # The `.rspec` file also contains a few flags that are not defaults but that
29
+ # users commonly want.
30
+ #
31
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
32
+ RSpec.configure do |config|
33
+ # rspec-expectations config goes here. You can use an alternate
34
+ # assertion/expectation library such as wrong or the stdlib/minitest
35
+ # assertions if you prefer.
36
+ config.expect_with :rspec do |expectations|
37
+ # This option will default to `true` in RSpec 4. It makes the `description`
38
+ # and `failure_message` of custom matchers include text for helper methods
39
+ # defined using `chain`, e.g.:
40
+ # be_bigger_than(2).and_smaller_than(4).description
41
+ # # => "be bigger than 2 and smaller than 4"
42
+ # ...rather than:
43
+ # # => "be bigger than 2"
44
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
45
+ end
46
+
47
+ # rspec-mocks config goes here. You can use an alternate test double
48
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
49
+ config.mock_with :rspec do |mocks|
50
+ # Prevents you from mocking or stubbing a method that does not exist on
51
+ # a real object. This is generally recommended, and will default to
52
+ # `true` in RSpec 4.
53
+ mocks.verify_partial_doubles = true
54
+ end
55
+
56
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
57
+ # have no way to turn it off -- the option exists only for backwards
58
+ # compatibility in RSpec 3). It causes shared context metadata to be
59
+ # inherited by the metadata hash of host groups and examples, rather than
60
+ # triggering implicit auto-inclusion in groups with matching metadata.
61
+ config.shared_context_metadata_behavior = :apply_to_host_groups
62
+
63
+ # The settings below are suggested to provide a good initial experience
64
+ # with RSpec, but feel free to customize to your heart's content.
65
+ =begin
66
+ # This allows you to limit a spec run to individual examples or groups
67
+ # you care about by tagging them with `:focus` metadata. When nothing
68
+ # is tagged with `:focus`, all examples get run. RSpec also provides
69
+ # aliases for `it`, `describe`, and `context` that include `:focus`
70
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
71
+ config.filter_run_when_matching :focus
72
+
73
+ # Allows RSpec to persist some state between runs in order to support
74
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
75
+ # you configure your source control system to ignore this file.
76
+ config.example_status_persistence_file_path = "spec/examples.txt"
77
+
78
+ # Limits the available syntax to the non-monkey patched syntax that is
79
+ # recommended. For more details, see:
80
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
81
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
82
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
83
+ config.disable_monkey_patching!
84
+
85
+ # This setting enables warnings. It's recommended, but in some cases may
86
+ # be too noisy due to issues in dependencies.
87
+ config.warnings = true
88
+
89
+ # Many RSpec users commonly either run the entire suite or an individual
90
+ # file, and it's useful to allow more verbose output when running an
91
+ # individual spec file.
92
+ if config.files_to_run.one?
93
+ # Use the documentation formatter for detailed output,
94
+ # unless a formatter has already been configured
95
+ # (e.g. via a command-line flag).
96
+ config.default_formatter = 'doc'
97
+ end
98
+
99
+ # Print the 10 slowest examples and example groups at the
100
+ # end of the spec run, to help surface which specs are running
101
+ # particularly slow.
102
+ config.profile_examples = 10
103
+
104
+ # Run specs in random order to surface order dependencies. If you find an
105
+ # order dependency and want to debug it, you can fix the order by providing
106
+ # the seed, which is printed after each run.
107
+ # --seed 1234
108
+ config.order = :random
109
+
110
+ # Seed global randomization in this process using the `--seed` CLI option.
111
+ # Setting this allows you to use `--seed` to deterministically reproduce
112
+ # test failures related to randomization by passing the same `--seed` value
113
+ # as the one that triggered the failure.
114
+ Kernel.srand config.seed
115
+ =end
116
+ end
@@ -0,0 +1,25 @@
1
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
2
+ require 'vainglory_api/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'vainglory-api'
6
+ s.version = VaingloryAPI::VERSION.dup
7
+ s.platform = Gem::Platform::RUBY
8
+ s.date = '2017-03-28'
9
+ s.summary = 'Vainglory API'
10
+ s.description = 'A Ruby libary wrapper for the Vainglory API'
11
+ s.authors = ['Chet Bortz']
12
+ s.homepage = 'https://github.com/cbortz/vainglory-api-ruby'
13
+ s.license = 'MIT'
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- spec/*`.split("\n")
17
+ s.require_paths = ['lib']
18
+ s.required_ruby_version = '>= 2.0'
19
+
20
+ s.add_development_dependency 'webmock', '~> 2.3'
21
+ s.add_development_dependency 'vcr', '~> 3.0'
22
+ s.add_development_dependency 'rspec', '~> 3.5'
23
+ s.add_development_dependency 'simplecov', '~> 0.14'
24
+ s.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
25
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vainglory-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chet Bortz
@@ -86,8 +86,30 @@ executables: []
86
86
  extensions: []
87
87
  extra_rdoc_files: []
88
88
  files:
89
+ - ".gitignore"
90
+ - ".rspec"
91
+ - ".rubocop.yml"
92
+ - ".travis.yml"
93
+ - CHANGELOG.md
94
+ - Gemfile
95
+ - LICENSE
96
+ - README.md
89
97
  - lib/vainglory_api.rb
90
- homepage:
98
+ - lib/vainglory_api/client.rb
99
+ - lib/vainglory_api/version.rb
100
+ - spec/cassettes/api_key.yml
101
+ - spec/cassettes/match.yml
102
+ - spec/cassettes/matches.yml
103
+ - spec/cassettes/player.yml
104
+ - spec/cassettes/players.yml
105
+ - spec/cassettes/samples.yml
106
+ - spec/cassettes/status.yml
107
+ - spec/cassettes/telemetry.yml
108
+ - spec/lib/vainglory_api/client_spec.rb
109
+ - spec/lib/vainglory_api_spec.rb
110
+ - spec/spec_helper.rb
111
+ - vainglory_api.gemspec
112
+ homepage: https://github.com/cbortz/vainglory-api-ruby
91
113
  licenses:
92
114
  - MIT
93
115
  metadata: {}
@@ -111,4 +133,15 @@ rubygems_version: 2.4.8
111
133
  signing_key:
112
134
  specification_version: 4
113
135
  summary: Vainglory API
114
- test_files: []
136
+ test_files:
137
+ - spec/cassettes/api_key.yml
138
+ - spec/cassettes/match.yml
139
+ - spec/cassettes/matches.yml
140
+ - spec/cassettes/player.yml
141
+ - spec/cassettes/players.yml
142
+ - spec/cassettes/samples.yml
143
+ - spec/cassettes/status.yml
144
+ - spec/cassettes/telemetry.yml
145
+ - spec/lib/vainglory_api/client_spec.rb
146
+ - spec/lib/vainglory_api_spec.rb
147
+ - spec/spec_helper.rb