lolesports-api 0.1.0 → 0.1.2

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: 402fad071f4b0f27a2c731639413bcfb082bd079
4
- data.tar.gz: 11f981a8700e4c7094cb6e95bd89f55ce2d56dac
3
+ metadata.gz: ff0d34fadcde4f55787e960a6088b5868d710406
4
+ data.tar.gz: 1f964a69c0a67ae53a891b87a84c310c8916fa93
5
5
  SHA512:
6
- metadata.gz: 4907a696a6a1fa4ae76479431b7a737e8cefcdf1e30e7ffdf4b8a90bd1831965735cb12dbcc6a6f3bc107482a29d3badb0aa0e9782a4fed16c81a4e074f06a3b
7
- data.tar.gz: 2fc292e31cba432fad126ccaa1160204fe3b2b067a6cc731ca6fd84351139b7aaf9845bf3a857a86f9cc7cc0740c96642ee0329a4bd75dbd750fb80d1ba4402d
6
+ metadata.gz: 9988395bf799fc896af9948c2d7d0bca2827843c089e93275b939e7c01b4dab6f8750ab9e8a142cf3666ac33f4c29698ab202f6b3cd7d0531e296c5484bb213b
7
+ data.tar.gz: 5574fa601fca2e5c452ac33651abcb8a662159cdb2b65d407c8ce1ca7783b1abdf014d2bf59c2c4f2434144e05ee7629a7d5ec3dadf1e595717b33775b1cc346
@@ -1,4 +1,5 @@
1
1
  require 'lolesports-api/version'
2
+ require 'lolesports-api/error'
2
3
  require 'lolesports-api/base'
3
4
  require 'lolesports-api/player'
4
5
  require 'lolesports-api/team'
@@ -8,6 +8,7 @@ module LolesportsApi
8
8
 
9
9
  def self.find(base_id)
10
10
  response = Faraday.get("#{self::API_URL}/#{base_id}.json")
11
+ fail_by_status(response) unless response.success?
11
12
  @attributes = JSON.parse(response.body)
12
13
  @attributes['id'] = base_id
13
14
  @base_object = new(@attributes)
@@ -15,9 +16,16 @@ module LolesportsApi
15
16
 
16
17
  def reload
17
18
  response = Faraday.get("#{self.class::API_URL}/#{@id}.json")
19
+ self.class.fail_by_status(response) unless response.success?
18
20
  @attributes = JSON.parse(response.body)
19
21
  initialize(@attributes)
20
22
  self
21
23
  end
24
+
25
+ def self.fail_by_status(response)
26
+ klass =
27
+ LolesportsApi::Error::ERRORS[response.status] || LolesportsApi::Error
28
+ fail klass
29
+ end
22
30
  end
23
31
  end
@@ -0,0 +1,22 @@
1
+ module LolesportsApi
2
+ class Error < StandardError
3
+ attr_reader :code
4
+
5
+ def initialize(message = '', code = nil)
6
+ super(message)
7
+ @code = code
8
+ end
9
+
10
+ UnauthorizedAccess = Class.new(self)
11
+
12
+ InternalServerError = Class.new(self)
13
+
14
+ BadGateway = Class.new(self)
15
+
16
+ ERRORS = {
17
+ 403 => LolesportsApi::Error::UnauthorizedAccess,
18
+ 500 => LolesportsApi::Error::InternalServerError,
19
+ 502 => LolesportsApi::Error::BadGateway
20
+ }
21
+ end
22
+ end
@@ -22,8 +22,10 @@ module LolesportsApi
22
22
 
23
23
  def self.find(team_id)
24
24
  super
25
- @attributes['roster'].each_value do |player|
26
- @base_object.roster << LolesportsApi::Player.new(player)
25
+ if @attributes['roster'].any?
26
+ @attributes['roster'].each_value do |player|
27
+ @base_object.roster << LolesportsApi::Player.new(player)
28
+ end
27
29
  end
28
30
  @base_object
29
31
  end
@@ -18,7 +18,7 @@ module LolesportsApi
18
18
  @name_public = attributes['namePublic']
19
19
  @no_vods = attributes['noVods']
20
20
  @published = attributes['published']
21
- @season = attributes['season'].to_i
21
+ @season = attributes['season']
22
22
  @winner = attributes['winner'].to_i
23
23
  @round = attributes['round']
24
24
  @matches = []
@@ -1,3 +1,3 @@
1
1
  module LolesportsApi
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -0,0 +1,81 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://na.lolesports.com/api/team/4.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.1
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Date:
22
+ - Sat, 15 Aug 2015 17:42:34 GMT
23
+ Content-Type:
24
+ - application/json
25
+ Content-Length:
26
+ - '922'
27
+ Connection:
28
+ - keep-alive
29
+ Set-Cookie:
30
+ - __cfduid=dc002d92b2b9546b3cd2d5e409e782ea11439660554; expires=Sun, 14-Aug-16
31
+ 17:42:34 GMT; path=/; domain=.lolesports.com; HttpOnly
32
+ Cache-Control:
33
+ - public, max-age=1800
34
+ Etag:
35
+ - '"1439660254-1"'
36
+ Expires:
37
+ - Sat, 15 Aug 2015 18:12:34 GMT
38
+ Last-Modified:
39
+ - Sat, 15 Aug 2015 17:37:34 GMT
40
+ Vary:
41
+ - Accept-Encoding
42
+ Via:
43
+ - 1.1 varnish
44
+ X-Drupal-Cache:
45
+ - MISS
46
+ X-Varnish:
47
+ - '476039840'
48
+ X-Varnish-Cache:
49
+ - MISS
50
+ Cf-Cache-Status:
51
+ - HIT
52
+ Accept-Ranges:
53
+ - bytes
54
+ Server:
55
+ - cloudflare-nginx
56
+ Cf-Ray:
57
+ - 2166b26170010707-SJC
58
+ body:
59
+ encoding: ASCII-8BIT
60
+ string: '{"name":"Curse","bio":"Curse''s roster has fluctuated frequently since
61
+ its inception, with even NyJacky gone from the original team. Their Season
62
+ 2 performance landed them just shy of the top 3 in North America, a curse
63
+ that would continue even through present-day. After opening with an 8-0 record
64
+ to the spring split, the team began to lose steam and have been on a downward
65
+ decline that not even all-star EdwarD could stave off. EdwarD later returned
66
+ to Gambit in Europe, and Zekent was added as the starting support. Also adding
67
+ the formerly banned player, IWillDominate, both he and Curse sought to prove
68
+ that they were turning over a new leaf in the competitive scene.\r\n\r\nThe
69
+ 2014 spring split met Curse with mixed results. They rode out the split in
70
+ the middle of the pack, more consistent than the bottom teams, yet not advanced
71
+ enough to break into the top three. During the split, Curse dropped Zekent
72
+ and briefly fielded Saintvicious in the support role. While he performed well
73
+ individually, Curse didn\u2019t see marked success with this new swap, and
74
+ eventually Saintvicious returned to retirement and Curse picked up Bunny FuFuu
75
+ in the support role. Finishing the split in fourth place, Bunny FuFuu was
76
+ moved to a substitute role in favor of former TSM member, Xpecial. Curse will
77
+ look to the summer split to prove that, with enough time, they can compete
78
+ for the top spot and a trip to the World Championships. \r\n","noPlayers":"0","roster":[],"logoUrl":"http://riot-web-cdn.s3-us-west-1.amazonaws.com/lolesports/s3fs-public/CurseLogos_RGB.png","profileUrl":"http://na.lolesports.com/node/4","teamPhotoUrl":"http://na.lolesports.com/","acronym":"CRS"}'
79
+ http_version:
80
+ recorded_at: Sat, 15 Aug 2015 17:42:34 GMT
81
+ recorded_with: VCR 2.9.3
@@ -19,7 +19,7 @@ http_interactions:
19
19
  message: OK
20
20
  headers:
21
21
  Date:
22
- - Wed, 05 Aug 2015 05:13:33 GMT
22
+ - Sat, 15 Aug 2015 17:42:34 GMT
23
23
  Content-Type:
24
24
  - application/json
25
25
  Content-Length:
@@ -27,16 +27,16 @@ http_interactions:
27
27
  Connection:
28
28
  - keep-alive
29
29
  Set-Cookie:
30
- - __cfduid=de771f1db6d002794526572affea495441438751612; expires=Thu, 04-Aug-16
31
- 05:13:32 GMT; path=/; domain=.lolesports.com; HttpOnly
30
+ - __cfduid=dd637975f1af879bd9d49a1b34f96efaa1439660553; expires=Sun, 14-Aug-16
31
+ 17:42:33 GMT; path=/; domain=.lolesports.com; HttpOnly
32
32
  Cache-Control:
33
33
  - public, max-age=1800
34
34
  Etag:
35
- - '"1438751166-1"'
35
+ - '"1439660554-1"'
36
36
  Expires:
37
- - Wed, 05 Aug 2015 05:43:33 GMT
37
+ - Sat, 15 Aug 2015 18:12:34 GMT
38
38
  Last-Modified:
39
- - Wed, 05 Aug 2015 05:06:06 GMT
39
+ - Sat, 15 Aug 2015 17:42:34 GMT
40
40
  Vary:
41
41
  - Accept-Encoding
42
42
  Via:
@@ -44,9 +44,9 @@ http_interactions:
44
44
  X-Drupal-Cache:
45
45
  - MISS
46
46
  X-Varnish:
47
- - 1377982057 1377979533
47
+ - '144888865'
48
48
  X-Varnish-Cache:
49
- - HIT
49
+ - MISS
50
50
  Cf-Cache-Status:
51
51
  - EXPIRED
52
52
  Accept-Ranges:
@@ -54,7 +54,7 @@ http_interactions:
54
54
  Server:
55
55
  - cloudflare-nginx
56
56
  Cf-Ray:
57
- - 2110036c1d66286a-SJC
57
+ - 2166b25dad9c11d7-SJC
58
58
  body:
59
59
  encoding: ASCII-8BIT
60
60
  string: '{"name":"Cloud9 ","bio":null,"noPlayers":"0","roster":{"players0":{"playerId":"328","name":"Balls","role":"Top
@@ -64,5 +64,5 @@ http_interactions:
64
64
  Lane","isStarter":1},"players7":{"playerId":"1313","name":"Sheep","role":"Support","isStarter":0},"players8":{"playerId":"1353","name":"Yusui","role":"Mid
65
65
  Lane","isStarter":0},"players9":{"playerId":"2551","name":"Hard","role":"Jungler","isStarter":0}},"logoUrl":"http://riot-web-cdn.s3-us-west-1.amazonaws.com/lolesports/s3fs-public/cloud9-logo.png","profileUrl":"http://na.lolesports.com/node/304","teamPhotoUrl":"http://na.lolesports.com/","acronym":"C9"}'
66
66
  http_version:
67
- recorded_at: Wed, 05 Aug 2015 05:13:32 GMT
67
+ recorded_at: Sat, 15 Aug 2015 17:42:34 GMT
68
68
  recorded_with: VCR 2.9.3
@@ -19,7 +19,7 @@ http_interactions:
19
19
  message: OK
20
20
  headers:
21
21
  Date:
22
- - Mon, 10 Aug 2015 02:47:45 GMT
22
+ - Sat, 15 Aug 2015 19:41:38 GMT
23
23
  Content-Type:
24
24
  - application/json
25
25
  Content-Length:
@@ -27,16 +27,16 @@ http_interactions:
27
27
  Connection:
28
28
  - keep-alive
29
29
  Set-Cookie:
30
- - __cfduid=dad0c4258d5805a752f6a014b805760e51439174865; expires=Tue, 09-Aug-16
31
- 02:47:45 GMT; path=/; domain=.lolesports.com; HttpOnly
30
+ - __cfduid=db5075e6f93fd40902cd2929a95bd31eb1439667693; expires=Sun, 14-Aug-16
31
+ 19:41:33 GMT; path=/; domain=.lolesports.com; HttpOnly
32
32
  Cache-Control:
33
33
  - public, max-age=1800
34
34
  Etag:
35
- - '"1439174870-1"'
35
+ - '"1439667695-1"'
36
36
  Expires:
37
- - Mon, 10 Aug 2015 03:17:45 GMT
37
+ - Sat, 15 Aug 2015 20:11:38 GMT
38
38
  Last-Modified:
39
- - Mon, 10 Aug 2015 02:47:50 GMT
39
+ - Sat, 15 Aug 2015 19:41:35 GMT
40
40
  Vary:
41
41
  - Accept-Encoding
42
42
  Via:
@@ -44,17 +44,17 @@ http_interactions:
44
44
  X-Drupal-Cache:
45
45
  - MISS
46
46
  X-Varnish:
47
- - '975588137'
47
+ - '874393733'
48
48
  X-Varnish-Cache:
49
49
  - MISS
50
50
  Cf-Cache-Status:
51
- - EXPIRED
51
+ - MISS
52
52
  Accept-Ranges:
53
53
  - bytes
54
54
  Server:
55
55
  - cloudflare-nginx
56
56
  Cf-Ray:
57
- - 213860ba7c730d85-SJC
57
+ - 216760ae79cf1e83-SJC
58
58
  body:
59
59
  encoding: ASCII-8BIT
60
60
  string: '{"namePublic":"EU LCS Summer Split","contestants":{"contestant1":{"id":"1100","name":"Copenhagen
@@ -64,5 +64,5 @@ http_interactions:
64
64
  Gaming","acronym":"GMB"}},"isFinished":true,"dateBegin":"2014-05-20T15:00Z","dateEnd":"2014-07-31T15:00Z","noVods":0,"season":"2014","published":true,"winner":"69","name":"EU
65
65
  LCS Summer Split"}'
66
66
  http_version:
67
- recorded_at: Mon, 10 Aug 2015 02:47:45 GMT
67
+ recorded_at: Sat, 15 Aug 2015 19:41:38 GMT
68
68
  recorded_with: VCR 2.9.3
@@ -0,0 +1,61 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://na.lolesports.com/api/tournament/192.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.1
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ response:
17
+ status:
18
+ code: 403
19
+ message: ": Access denied for user anonymous"
20
+ headers:
21
+ Date:
22
+ - Sat, 15 Aug 2015 19:41:38 GMT
23
+ Content-Type:
24
+ - application/json
25
+ Content-Length:
26
+ - '56'
27
+ Connection:
28
+ - keep-alive
29
+ Set-Cookie:
30
+ - __cfduid=d29b7c65211f27eddb85f1e432836a0801439667698; expires=Sun, 14-Aug-16
31
+ 19:41:38 GMT; path=/; domain=.lolesports.com; HttpOnly
32
+ Cache-Control:
33
+ - public, max-age=600
34
+ Etag:
35
+ - '"1439667215-1"'
36
+ Expires:
37
+ - Sun, 19 Nov 1978 05:00:00 GMT
38
+ Last-Modified:
39
+ - Sat, 15 Aug 2015 19:33:35 GMT
40
+ Vary:
41
+ - Accept-Encoding
42
+ Via:
43
+ - 1.1 varnish
44
+ X-Drupal-Cache:
45
+ - MISS
46
+ X-Varnish:
47
+ - '1443692253'
48
+ X-Varnish-Cache:
49
+ - MISS
50
+ Cf-Cache-Status:
51
+ - HIT
52
+ Server:
53
+ - cloudflare-nginx
54
+ Cf-Ray:
55
+ - 216760cb1aaf1ea7-SJC
56
+ body:
57
+ encoding: ASCII-8BIT
58
+ string: '["Access denied for user anonymous"]'
59
+ http_version:
60
+ recorded_at: Sat, 15 Aug 2015 19:41:38 GMT
61
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,7 @@
1
+ describe LolesportsApi::Error do
2
+ describe '#new' do
3
+ let(:error) { LolesportsApi::Error.new('Unauthorized Access', 403) }
4
+ it { expect(error.message).to eq 'Unauthorized Access' }
5
+ it { expect(error.code).to eq 403 }
6
+ end
7
+ end
@@ -1,12 +1,20 @@
1
1
  describe LolesportsApi::Team do
2
- describe '.find', vcr: true do
3
- let(:team) { LolesportsApi::Team.find(304) }
4
- it { expect(team.class).to eq LolesportsApi::Team }
5
- it { expect(team.acronym).to eq 'C9' }
6
- it { expect(team.id).to eq 304 }
7
- it { expect(team.roster.class).to eq Array }
8
- it { expect(team.roster.first.class).to eq LolesportsApi::Player }
9
- it { expect(team.roster[4].name).to eq 'Meteos' }
10
- it { expect(team.roster[4].id).to eq 329 }
2
+ describe '.find' do
3
+ context 'when a team has players', vcr: true do
4
+ let(:team) { LolesportsApi::Team.find(304) }
5
+ it { expect(team.class).to eq LolesportsApi::Team }
6
+ it { expect(team.acronym).to eq 'C9' }
7
+ it { expect(team.id).to eq 304 }
8
+ it { expect(team.roster.class).to eq Array }
9
+ it { expect(team.roster.first.class).to eq LolesportsApi::Player }
10
+ it { expect(team.roster[4].name).to eq 'Meteos' }
11
+ it { expect(team.roster[4].id).to eq 329 }
12
+ end
13
+ context 'when a team does not have players', vcr: true do
14
+ let(:team) { LolesportsApi::Team.find(4) }
15
+ it { expect(team.class).to eq LolesportsApi::Team }
16
+ it { expect(team.name).to eq 'Curse' }
17
+ it { expect(team.roster).to eq [] }
18
+ end
11
19
  end
12
20
  end
@@ -1,10 +1,19 @@
1
1
  describe LolesportsApi::Tournament do
2
2
  describe '.find', vcr: true do
3
- let(:tournament) { LolesportsApi::Tournament.find(102) }
4
- it { expect(tournament.class).to eq LolesportsApi::Tournament }
5
- it { expect(tournament.name).to eq 'EU LCS Summer Split' }
6
- it { expect(tournament.id).to eq 102 }
7
- it { expect(tournament.contestants[0].id).to eq 1100 }
3
+ context 'when the Tournament is available' do
4
+ let(:tournament) { LolesportsApi::Tournament.find(102) }
5
+ it { expect(tournament.class).to eq LolesportsApi::Tournament }
6
+ it { expect(tournament.name).to eq 'EU LCS Summer Split' }
7
+ it { expect(tournament.id).to eq 102 }
8
+ it { expect(tournament.contestants[0].id).to eq 1100 }
9
+ end
10
+ context 'when the Tournament is only for authorized accounts' do
11
+ it 'raises LolesportsApi::Error::UnauthorizedAccess' do
12
+ expect do
13
+ LolesportsApi::Tournament.find(192)
14
+ end.to raise_error LolesportsApi::Error::UnauthorizedAccess
15
+ end
16
+ end
8
17
  end
9
18
 
10
19
  describe '#find_matches', vcr: true do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lolesports-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Mays
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-12 00:00:00.000000000 Z
11
+ date: 2015-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -181,6 +181,7 @@ files:
181
181
  - Rakefile
182
182
  - lib/lolesports-api.rb
183
183
  - lib/lolesports-api/base.rb
184
+ - lib/lolesports-api/error.rb
184
185
  - lib/lolesports-api/game.rb
185
186
  - lib/lolesports-api/league.rb
186
187
  - lib/lolesports-api/match.rb
@@ -199,9 +200,12 @@ files:
199
200
  - spec/fixtures/vcr/cassettes/LolesportsApi_Player/_reload/.yml
200
201
  - spec/fixtures/vcr/cassettes/LolesportsApi_Series/_all/.yml
201
202
  - spec/fixtures/vcr/cassettes/LolesportsApi_Series/_find/.yml
202
- - spec/fixtures/vcr/cassettes/LolesportsApi_Team/_find/.yml
203
- - spec/fixtures/vcr/cassettes/LolesportsApi_Tournament/_find/.yml
203
+ - spec/fixtures/vcr/cassettes/LolesportsApi_Team/_find/when_a_team_does_not_have_players/.yml
204
+ - spec/fixtures/vcr/cassettes/LolesportsApi_Team/_find/when_a_team_has_players/.yml
205
+ - spec/fixtures/vcr/cassettes/LolesportsApi_Tournament/_find/when_the_Tournament_is_available/.yml
206
+ - spec/fixtures/vcr/cassettes/LolesportsApi_Tournament/_find/when_the_Tournament_is_only_for_authorized_accounts/raises_LolesportsApi_Error_UnauthorizedAccess.yml
204
207
  - spec/fixtures/vcr/cassettes/LolesportsApi_Tournament/_find_matches/.yml
208
+ - spec/lolesports-api/error_spec.rb
205
209
  - spec/lolesports-api/game_spec.rb
206
210
  - spec/lolesports-api/league_spec.rb
207
211
  - spec/lolesports-api/match_spec.rb
@@ -244,9 +248,12 @@ test_files:
244
248
  - spec/fixtures/vcr/cassettes/LolesportsApi_Player/_reload/.yml
245
249
  - spec/fixtures/vcr/cassettes/LolesportsApi_Series/_all/.yml
246
250
  - spec/fixtures/vcr/cassettes/LolesportsApi_Series/_find/.yml
247
- - spec/fixtures/vcr/cassettes/LolesportsApi_Team/_find/.yml
248
- - spec/fixtures/vcr/cassettes/LolesportsApi_Tournament/_find/.yml
251
+ - spec/fixtures/vcr/cassettes/LolesportsApi_Team/_find/when_a_team_does_not_have_players/.yml
252
+ - spec/fixtures/vcr/cassettes/LolesportsApi_Team/_find/when_a_team_has_players/.yml
253
+ - spec/fixtures/vcr/cassettes/LolesportsApi_Tournament/_find/when_the_Tournament_is_available/.yml
254
+ - spec/fixtures/vcr/cassettes/LolesportsApi_Tournament/_find/when_the_Tournament_is_only_for_authorized_accounts/raises_LolesportsApi_Error_UnauthorizedAccess.yml
249
255
  - spec/fixtures/vcr/cassettes/LolesportsApi_Tournament/_find_matches/.yml
256
+ - spec/lolesports-api/error_spec.rb
250
257
  - spec/lolesports-api/game_spec.rb
251
258
  - spec/lolesports-api/league_spec.rb
252
259
  - spec/lolesports-api/match_spec.rb