lolesports-api 0.1.0
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 +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.rubocop.yml +11 -0
- data/Gemfile +4 -0
- data/Guardfile +25 -0
- data/LICENSE.txt +22 -0
- data/README.md +78 -0
- data/Rakefile +1 -0
- data/lib/lolesports-api.rb +14 -0
- data/lib/lolesports-api/base.rb +23 -0
- data/lib/lolesports-api/game.rb +50 -0
- data/lib/lolesports-api/league.rb +66 -0
- data/lib/lolesports-api/match.rb +52 -0
- data/lib/lolesports-api/play.rb +47 -0
- data/lib/lolesports-api/player.rb +31 -0
- data/lib/lolesports-api/series.rb +35 -0
- data/lib/lolesports-api/team.rb +31 -0
- data/lib/lolesports-api/tournament.rb +46 -0
- data/lib/lolesports-api/version.rb +3 -0
- data/lolesports-api.gemspec +33 -0
- data/spec/fixtures/vcr/cassettes/LolesportsApi_Game/_find/.yml +66 -0
- data/spec/fixtures/vcr/cassettes/LolesportsApi_League/_all/.yml +226 -0
- data/spec/fixtures/vcr/cassettes/LolesportsApi_League/_find/.yml +92 -0
- data/spec/fixtures/vcr/cassettes/LolesportsApi_Match/_find/.yml +66 -0
- data/spec/fixtures/vcr/cassettes/LolesportsApi_Player/_find/.yml +69 -0
- data/spec/fixtures/vcr/cassettes/LolesportsApi_Player/_reload/.yml +69 -0
- data/spec/fixtures/vcr/cassettes/LolesportsApi_Series/_all/.yml +87 -0
- data/spec/fixtures/vcr/cassettes/LolesportsApi_Series/_find/.yml +63 -0
- data/spec/fixtures/vcr/cassettes/LolesportsApi_Team/_find/.yml +68 -0
- data/spec/fixtures/vcr/cassettes/LolesportsApi_Tournament/_find/.yml +68 -0
- data/spec/fixtures/vcr/cassettes/LolesportsApi_Tournament/_find_matches/.yml +84 -0
- data/spec/lolesports-api/game_spec.rb +14 -0
- data/spec/lolesports-api/league_spec.rb +20 -0
- data/spec/lolesports-api/match_spec.rb +14 -0
- data/spec/lolesports-api/play_spec.rb +33 -0
- data/spec/lolesports-api/player_spec.rb +25 -0
- data/spec/lolesports-api/series_spec.rb +17 -0
- data/spec/lolesports-api/team_spec.rb +12 -0
- data/spec/lolesports-api/tournament_spec.rb +17 -0
- data/spec/spec_helper.rb +108 -0
- metadata +258 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 402fad071f4b0f27a2c731639413bcfb082bd079
|
4
|
+
data.tar.gz: 11f981a8700e4c7094cb6e95bd89f55ce2d56dac
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4907a696a6a1fa4ae76479431b7a737e8cefcdf1e30e7ffdf4b8a90bd1831965735cb12dbcc6a6f3bc107482a29d3badb0aa0e9782a4fed16c81a4e074f06a3b
|
7
|
+
data.tar.gz: 2fc292e31cba432fad126ccaa1160204fe3b2b067a6cc731ca6fd84351139b7aaf9845bf3a857a86f9cc7cc0740c96642ee0329a4bd75dbd750fb80d1ba4402d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
5
|
+
require 'guard/rspec/dsl'
|
6
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
7
|
+
|
8
|
+
# Feel free to open issues for suggestions and improvements
|
9
|
+
|
10
|
+
# RSpec files
|
11
|
+
rspec = dsl.rspec
|
12
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
13
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
14
|
+
watch(rspec.spec_files)
|
15
|
+
|
16
|
+
# Ruby files
|
17
|
+
ruby = dsl.ruby
|
18
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
19
|
+
end
|
20
|
+
|
21
|
+
guard :rubocop, all_on_start: false do
|
22
|
+
watch(/.+\.rb$/)
|
23
|
+
watch(/lolesports-api\.gemspec$/)
|
24
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
25
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Jake Mays
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# Lolesports::Api
|
2
|
+
|
3
|
+
An easier API wrapper for the [lolesports.com](http://na.lolesports.com) API.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'lolesports-api'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install lolesports-api
|
21
|
+
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
Remember, anywhere you'd like to use it:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require 'lolesports-api'
|
28
|
+
```
|
29
|
+
### Base Methods
|
30
|
+
|
31
|
+
A common rule throughout the API to keep in mind, is that no single command does multiple API calls.
|
32
|
+
|
33
|
+
#### .find(id)
|
34
|
+
|
35
|
+
Any given `LolesportsApi` class(apart from `LolesportsApi::Play`) has the find method. It returns a new instance of that class, with all related properties and objects.
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
hai = LolesportsApi::Player.find(330)
|
39
|
+
# => #<LolesportsApi::Player:0x007f9fb3509998 @name="Hai"...>
|
40
|
+
```
|
41
|
+
|
42
|
+
#### #reload
|
43
|
+
From any given API object with an `@id` attribute, you can use reload to either update the object or load it with all of its endpoint data.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
hai.reload
|
47
|
+
# => #<LolesportsApi::Player:0x007f9fb3509998 @name="Hai"...>
|
48
|
+
```
|
49
|
+
|
50
|
+
### Object Specific Methods
|
51
|
+
|
52
|
+
#### .all
|
53
|
+
|
54
|
+
This only exists for Leagues and Series. Returns an array of all instances of the object.
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
leagues = LolesportsApi::League.all
|
58
|
+
# => [#<LolesportsApi::League:0x007fd152dfe7f8>, #<LolesportsApi::League:0x00...]
|
59
|
+
```
|
60
|
+
|
61
|
+
## TODO
|
62
|
+
* `LolesportsApi::Tournament.all`, since the API doesn't currently actually return all tournaments. [API Link](http://na.lolesports.com/api/swagger#!/api/getTournaments)
|
63
|
+
* `LolesportsApi::Team` list of games. [API Link](http://na.lolesports.com/api/swagger#!/api/getSchedule)
|
64
|
+
* Other less useful API objects.
|
65
|
+
|
66
|
+
## Special Thanks
|
67
|
+
* Thanks [@levi](https://twitter.com/levi) for [this](https://gist.github.com/levi/e7e5e808ac0119e154ce) documentation.
|
68
|
+
* And obviously, thanks Riot. <3
|
69
|
+
|
70
|
+
|
71
|
+
## Contributing
|
72
|
+
|
73
|
+
1. Fork it ( https://github.com/[my-github-username]/lolesports-api/fork )
|
74
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
75
|
+
3. Write tests.
|
76
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
77
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
78
|
+
6. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'lolesports-api/version'
|
2
|
+
require 'lolesports-api/base'
|
3
|
+
require 'lolesports-api/player'
|
4
|
+
require 'lolesports-api/team'
|
5
|
+
require 'lolesports-api/game'
|
6
|
+
require 'lolesports-api/play'
|
7
|
+
require 'lolesports-api/match'
|
8
|
+
require 'lolesports-api/tournament'
|
9
|
+
require 'lolesports-api/league'
|
10
|
+
require 'lolesports-api/series'
|
11
|
+
|
12
|
+
module LolesportsApi
|
13
|
+
# Your code goes here...
|
14
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
module LolesportsApi
|
6
|
+
class BaseApiObject
|
7
|
+
SCHEDULE_URL = 'http://na.lolesports.com/api/schedule.json'
|
8
|
+
|
9
|
+
def self.find(base_id)
|
10
|
+
response = Faraday.get("#{self::API_URL}/#{base_id}.json")
|
11
|
+
@attributes = JSON.parse(response.body)
|
12
|
+
@attributes['id'] = base_id
|
13
|
+
@base_object = new(@attributes)
|
14
|
+
end
|
15
|
+
|
16
|
+
def reload
|
17
|
+
response = Faraday.get("#{self.class::API_URL}/#{@id}.json")
|
18
|
+
@attributes = JSON.parse(response.body)
|
19
|
+
initialize(@attributes)
|
20
|
+
self
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module LolesportsApi
|
2
|
+
class Game < LolesportsApi::BaseApiObject
|
3
|
+
attr_reader :id, :date_time, :game_length, :game_number,
|
4
|
+
:legs_url, :match_id, :max_games, :no_vods,
|
5
|
+
:platform_game_id, :platform_id, :players,
|
6
|
+
:tournament, :vods, :winner_id, :has_vod
|
7
|
+
|
8
|
+
attr_accessor :blue_team, :red_team
|
9
|
+
|
10
|
+
API_URL = 'http://na.lolesports.com/api/game'
|
11
|
+
|
12
|
+
def initialize(attributes = {})
|
13
|
+
@id = attributes['id'].to_i
|
14
|
+
@game_length = attributes['gameLength'].to_i
|
15
|
+
@game_number = attributes['gameNumber'].to_i
|
16
|
+
@legs_url = attributes['legsUrl']
|
17
|
+
@match_id = attributes['matchId'].to_i
|
18
|
+
@max_games = attributes['maxGames'].to_i
|
19
|
+
@no_vods = attributes['noVods']
|
20
|
+
@platform_game_id = attributes['platformGameId']
|
21
|
+
@platform_id = attributes['platformId']
|
22
|
+
@players = []
|
23
|
+
@tournament = attributes['tournament'] || {}
|
24
|
+
@vods = attributes['vods'] || {}
|
25
|
+
@winner_id = attributes['winnerId'].to_i
|
26
|
+
@has_vod = attributes['hasVod']
|
27
|
+
@date_time =
|
28
|
+
DateTime.parse(attributes['dateTime']) if attributes['dateTime']
|
29
|
+
|
30
|
+
prepare_teams(attributes)
|
31
|
+
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.find(game_id)
|
36
|
+
super
|
37
|
+
@attributes['players'].each_value do |player|
|
38
|
+
@base_object.players << LolesportsApi::Play.new(player)
|
39
|
+
end
|
40
|
+
@base_object.prepare_teams(@attributes)
|
41
|
+
@base_object
|
42
|
+
end
|
43
|
+
|
44
|
+
def prepare_teams(attrs)
|
45
|
+
return unless attrs['contestants']
|
46
|
+
@blue_team = LolesportsApi::Team.new(attrs['contestants']['blue'])
|
47
|
+
@red_team = LolesportsApi::Team.new(attrs['contestants']['red'])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module LolesportsApi
|
2
|
+
class League < LolesportsApi::BaseApiObject
|
3
|
+
attr_reader :id, :color, :default_series_id,
|
4
|
+
:default_tournament_id, :international_live_stream,
|
5
|
+
:label, :league_image, :league_series,
|
6
|
+
:league_tournaments, :menu_weight, :no_vods,
|
7
|
+
:published, :short_name, :url
|
8
|
+
|
9
|
+
API_URL = 'http://na.lolesports.com/api/league'
|
10
|
+
|
11
|
+
def initialize(attributes)
|
12
|
+
@id = attributes['id'].to_i
|
13
|
+
@color = attributes['color']
|
14
|
+
@default_series_id = attributes['defaultSeriesId'].to_i
|
15
|
+
@default_tournament_id = attributes['defaultTournamentId'].to_i
|
16
|
+
# International Live Stream is one giant cluster, watch out.
|
17
|
+
@international_live_stream = attributes['internationalLiveStream']
|
18
|
+
@label = attributes['label']
|
19
|
+
@league_image = attributes['leagueImage']
|
20
|
+
@league_series = []
|
21
|
+
@league_tournaments = []
|
22
|
+
@menu_weight = attributes['menuWeight']
|
23
|
+
@no_vods = attributes['noVods']
|
24
|
+
@published = attributes['published']
|
25
|
+
@short_name = attributes['shortName']
|
26
|
+
@url = attributes['url']
|
27
|
+
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.find(league_id)
|
32
|
+
super
|
33
|
+
@attributes['leagueTournaments'].each do |tournament|
|
34
|
+
@base_object.league_tournaments <<
|
35
|
+
LolesportsApi::Tournament.new('id' => tournament)
|
36
|
+
end
|
37
|
+
@attributes['leagueSeries'].each do |series|
|
38
|
+
@base_object.league_series <<
|
39
|
+
LolesportsApi::Series.new('id' => series)
|
40
|
+
end
|
41
|
+
@base_object
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.all
|
45
|
+
response = Faraday.get("#{API_URL}.json?parameters%5Bmethod%5D=all")
|
46
|
+
leagues_json = JSON.parse(response.body)
|
47
|
+
leagues = []
|
48
|
+
leagues_json['leagues'].each do |league|
|
49
|
+
leagues << new(league)
|
50
|
+
end
|
51
|
+
leagues
|
52
|
+
end
|
53
|
+
|
54
|
+
def name
|
55
|
+
@label
|
56
|
+
end
|
57
|
+
|
58
|
+
def series
|
59
|
+
@league_series
|
60
|
+
end
|
61
|
+
|
62
|
+
def tournaments
|
63
|
+
@league_tournaments
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module LolesportsApi
|
2
|
+
class Match < LolesportsApi::BaseApiObject
|
3
|
+
attr_reader :id, :blue_team, :red_team, :date_time, :games,
|
4
|
+
:is_finished, :is_live, :live_streams,
|
5
|
+
:max_games, :name, :polldaddy_id, :url,
|
6
|
+
:winner_id
|
7
|
+
|
8
|
+
attr_accessor :tournament
|
9
|
+
|
10
|
+
API_URL = 'http://na.lolesports.com/api/match'
|
11
|
+
|
12
|
+
def initialize(attributes = {})
|
13
|
+
@id = (attributes['id'] || attributes['matchId']).to_i
|
14
|
+
@date_time =
|
15
|
+
DateTime.parse(attributes['dateTime']) if attributes['dateTime']
|
16
|
+
@is_finished = attributes['isFinished']
|
17
|
+
@is_live = attributes['isLive']
|
18
|
+
@live_streams = attributes['liveStreams']
|
19
|
+
@max_games = attributes['maxGames']
|
20
|
+
@name = attributes['name']
|
21
|
+
@polldaddy_id = attributes['polldaddyId']
|
22
|
+
@tournament = LolesportsApi::Tournament.new(attributes['tournament'])
|
23
|
+
@url = attributes['url']
|
24
|
+
@winner_id = attributes['winnerId']
|
25
|
+
|
26
|
+
prepare_teams(attributes)
|
27
|
+
prepare_games(attributes)
|
28
|
+
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.find(match_id)
|
33
|
+
super
|
34
|
+
@base_object.prepare_games(@attributes)
|
35
|
+
@base_object
|
36
|
+
end
|
37
|
+
|
38
|
+
def prepare_games(attrs)
|
39
|
+
return unless attrs['games']
|
40
|
+
@games = []
|
41
|
+
attrs['games'].each_value do |game|
|
42
|
+
@games << LolesportsApi::Game.new(game)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def prepare_teams(attrs)
|
47
|
+
return unless attrs['contestants']
|
48
|
+
@blue_team = LolesportsApi::Team.new(attrs['contestants']['blue'])
|
49
|
+
@red_team = LolesportsApi::Team.new(attrs['contestants']['red'])
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module LolesportsApi
|
2
|
+
class Play
|
3
|
+
attr_reader :assists, :champion_id, :deaths, :end_level,
|
4
|
+
:player_id, :items, :kda, :kills, :minions_killed,
|
5
|
+
:name, :photo_url, :spell0, :spell1, :team_id,
|
6
|
+
:total_gold, :player
|
7
|
+
|
8
|
+
def initialize(attributes = {})
|
9
|
+
@assists = attributes['assists']
|
10
|
+
@champion_id = attributes['championId']
|
11
|
+
@deaths = attributes['deaths']
|
12
|
+
@end_level = attributes['endLevel']
|
13
|
+
@player_id = attributes['id']
|
14
|
+
@items = processed_items(attributes)
|
15
|
+
@kda = attributes['kda']
|
16
|
+
@kills = attributes['kills']
|
17
|
+
@minions_killed = attributes['minionsKilled']
|
18
|
+
@name = attributes['name']
|
19
|
+
@photo_url = attributes['photoURL']
|
20
|
+
@spell0 = attributes['spell0'].to_i
|
21
|
+
@spell1 = attributes['spell1'].to_i
|
22
|
+
@team_id = attributes['teamId']
|
23
|
+
@total_gold = attributes['totalGold']
|
24
|
+
|
25
|
+
@player = prepare_player
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def processed_items(attrs)
|
31
|
+
collected_items = []
|
32
|
+
attrs.each do |key, value|
|
33
|
+
collected_items << value.to_i if key.match(/^items\d$/)
|
34
|
+
end
|
35
|
+
collected_items
|
36
|
+
end
|
37
|
+
|
38
|
+
def prepare_player
|
39
|
+
LolesportsApi::Player.new(
|
40
|
+
'id' => @player_id,
|
41
|
+
'name' => @name,
|
42
|
+
'photoUrl' => @photo_url,
|
43
|
+
'teamId' => @team_id
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module LolesportsApi
|
2
|
+
class Player < LolesportsApi::BaseApiObject
|
3
|
+
attr_reader :id, :name, :bio, :first_name, :last_name,
|
4
|
+
:team_id, :role, :role_id, :is_starter,
|
5
|
+
:hometown, :contract_expiration, :photo_url,
|
6
|
+
:profile_url, :residency, :api_url
|
7
|
+
|
8
|
+
API_URL = 'http://na.lolesports.com/api/player'
|
9
|
+
|
10
|
+
def initialize(attributes = {})
|
11
|
+
@id = attributes['id'] || attributes['playerId'].to_i
|
12
|
+
@name = attributes['name']
|
13
|
+
@bio = attributes['bio']
|
14
|
+
@first_name = attributes['firstname']
|
15
|
+
@last_name = attributes['lastname']
|
16
|
+
@team_id = attributes['teamId']
|
17
|
+
@role = attributes['role']
|
18
|
+
@role_id = attributes['roleId']
|
19
|
+
@is_starter = attributes['isStarter']
|
20
|
+
@hometown = attributes['hometown']
|
21
|
+
@contract_expiration = attributes['contractExpiration']
|
22
|
+
@photo_url = attributes['photoUrl']
|
23
|
+
@profile_url = attributes['profileUrl']
|
24
|
+
@residency = attributes['residency']
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.all
|
28
|
+
fail StandardError, 'No API endpoint available.'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|