master_league 0.0.1
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 +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +97 -0
- data/Rakefile +6 -0
- data/bin/console +8 -0
- data/bin/setup +8 -0
- data/lib/master_league.rb +60 -0
- data/lib/master_league/cache.rb +52 -0
- data/lib/master_league/draft.rb +20 -0
- data/lib/master_league/event.rb +10 -0
- data/lib/master_league/event_repository.rb +19 -0
- data/lib/master_league/fetcher.rb +44 -0
- data/lib/master_league/hero.rb +28 -0
- data/lib/master_league/hero_repository.rb +20 -0
- data/lib/master_league/map.rb +9 -0
- data/lib/master_league/map_repository.rb +31 -0
- data/lib/master_league/match.rb +29 -0
- data/lib/master_league/match_repository.rb +30 -0
- data/lib/master_league/patch.rb +10 -0
- data/lib/master_league/patch_repository.rb +19 -0
- data/lib/master_league/pick.rb +16 -0
- data/lib/master_league/player.rb +27 -0
- data/lib/master_league/player_repository.rb +22 -0
- data/lib/master_league/region.rb +8 -0
- data/lib/master_league/region_repository.rb +19 -0
- data/lib/master_league/repository.rb +113 -0
- data/lib/master_league/stage.rb +8 -0
- data/lib/master_league/talent.rb +11 -0
- data/lib/master_league/team.rb +15 -0
- data/lib/master_league/team_repository.rb +16 -0
- data/lib/master_league/tournament.rb +17 -0
- data/lib/master_league/tournament_repository.rb +20 -0
- data/lib/master_league/version.rb +3 -0
- data/master_league.gemspec +27 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9a67fdf70581fea6431ba9193d9e502aec531458
|
4
|
+
data.tar.gz: 9e372bbbbb3a6b362e7585610a9630b55d89c2f3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d4d974ac114a3ac03878dec41b908e3661b28db52fb8cb3fe7a92be12f8eab3d5a22d5e4d5ef1621bf462a2e4e99f700693a63fac51316ac9cbe393791113c21
|
7
|
+
data.tar.gz: df19692d375009c51d26ae901ec4877a7f5883dcf00a2db75858f7e3e88881a95cab3eb4f5b169bf1993e980d701588ea5eb795353e5aa328826357d05b24c0d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 tbuehlmann
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# MasterLeague
|
2
|
+
|
3
|
+
The MasterLeague Gem is a Client that consumes the [Master League API](https://api.masterleague.net/).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'master_league'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install master_league
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Each record that is available through an API endpoint can be retrieved by a repository. Example:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
repository = MasterLeague::HeroRepository.new
|
27
|
+
|
28
|
+
repository.each do |hero|
|
29
|
+
puts "#{hero.name} (#{hero.role})"
|
30
|
+
end
|
31
|
+
|
32
|
+
# Abathur (Specialist)
|
33
|
+
# Alarak (Assassin)
|
34
|
+
# Anub'arak (Warrior)
|
35
|
+
# ...
|
36
|
+
```
|
37
|
+
|
38
|
+
You can also retrieve single records by their id:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
hero = repository.find(33)
|
42
|
+
hero.name # => 'Tassadar'
|
43
|
+
```
|
44
|
+
|
45
|
+
When retrieving multiple Heroes from the API, some information are missing. You can reload a Hero's information by calling `hero.reload`.
|
46
|
+
|
47
|
+
## Filtering
|
48
|
+
|
49
|
+
Depending on what API endpoint you're working with, there are some filters:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
repository.limit(10) # returns at most 10 records
|
53
|
+
repository.page(2) # returns the second page of records
|
54
|
+
repository.order('date') # orders the records by date (ascending)
|
55
|
+
repository.order('-date') # orders the records by date (descending)
|
56
|
+
repository.where(hero: 33) # filters to the records having `hero` set to 33
|
57
|
+
```
|
58
|
+
|
59
|
+
You can also chain filters, as in:
|
60
|
+
|
61
|
+
```
|
62
|
+
repository.limit(15).page(2)
|
63
|
+
```
|
64
|
+
|
65
|
+
Not all API endpoints are open to every filter, here's a matrix for you:
|
66
|
+
|
67
|
+
| / | default limit | max limit | paginatable | orderable by | where/filterable by |
|
68
|
+
|:-----------:|:-------------:|:-------------:|:-----------:|:------------:|:-------------------------------------------------:|
|
69
|
+
| Heroes | 20 | 60 | yes | nothing | role |
|
70
|
+
| Maps | not limitable | not limitable | no | nothing | nothing |
|
71
|
+
| Regions | not limitable | not limitable | no | nothing | nothing |
|
72
|
+
| Patches | not limitable | not limitable | no | nothing | nothing |
|
73
|
+
| Teams | 20 | 100 | yes | nothing | region |
|
74
|
+
| Players | 20 | 100 | yes | nothing | team, region |
|
75
|
+
| Tournaments | 20 | 30 | yes | nothing | region |
|
76
|
+
| Matches | 10 | 25 | yes | id, date | map, patch, tournament, stage, team, hero, player |
|
77
|
+
| Events | unknown | unknown | unknown | nothing | is_live |
|
78
|
+
|
79
|
+
When filtering with `#where`, use the corresponding id of a role, a region, a team, …, not the corresponding name.
|
80
|
+
|
81
|
+
## Caching
|
82
|
+
|
83
|
+
As you're restricted in numbers of requests to the API, there's a simple caching mechanism built-in. In order to enable caching, call `MasterLeague.enable_caching`. This will cache every HTTP request/response you send against the API in ~/.config/master_league_cache.yml. When you try to query the API with an already made request, you get the cached response and don't actually query the API.
|
84
|
+
|
85
|
+
If you want disable caching after enabling it, call `MasterLeague.disable_caching`. If you want to clear the cache, call `MasterLeague.cache.clear`.
|
86
|
+
|
87
|
+
## Authentication
|
88
|
+
|
89
|
+
As I don't have a valid premium access, authentication is missing.
|
90
|
+
|
91
|
+
## Contributing
|
92
|
+
|
93
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tbuehlmann/master_league.
|
94
|
+
|
95
|
+
## License
|
96
|
+
|
97
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'virtus'
|
2
|
+
|
3
|
+
require 'master_league/cache'
|
4
|
+
require 'master_league/fetcher'
|
5
|
+
require 'master_league/version'
|
6
|
+
|
7
|
+
require 'master_league/repository'
|
8
|
+
require 'master_league/event_repository'
|
9
|
+
require 'master_league/hero_repository'
|
10
|
+
require 'master_league/map_repository'
|
11
|
+
require 'master_league/match_repository'
|
12
|
+
require 'master_league/patch_repository'
|
13
|
+
require 'master_league/player_repository'
|
14
|
+
require 'master_league/region_repository'
|
15
|
+
require 'master_league/team_repository'
|
16
|
+
require 'master_league/tournament_repository'
|
17
|
+
|
18
|
+
require 'master_league/pick'
|
19
|
+
require 'master_league/draft'
|
20
|
+
require 'master_league/event'
|
21
|
+
require 'master_league/patch'
|
22
|
+
require 'master_league/player'
|
23
|
+
require 'master_league/region'
|
24
|
+
require 'master_league/stage'
|
25
|
+
require 'master_league/talent'
|
26
|
+
require 'master_league/team'
|
27
|
+
require 'master_league/tournament'
|
28
|
+
require 'master_league/hero'
|
29
|
+
require 'master_league/map'
|
30
|
+
require 'master_league/match'
|
31
|
+
|
32
|
+
Virtus.finalize
|
33
|
+
|
34
|
+
module MasterLeague
|
35
|
+
class << self
|
36
|
+
def fetcher
|
37
|
+
@fetcher ||= Fetcher.new
|
38
|
+
end
|
39
|
+
|
40
|
+
def fetch(path, params = {})
|
41
|
+
fetcher.fetch(path, params)
|
42
|
+
end
|
43
|
+
|
44
|
+
def enable_caching
|
45
|
+
@caching_enabled = true
|
46
|
+
end
|
47
|
+
|
48
|
+
def disable_caching
|
49
|
+
@caching_enabled = false
|
50
|
+
end
|
51
|
+
|
52
|
+
def caching_enabled?
|
53
|
+
!!@caching_enabled
|
54
|
+
end
|
55
|
+
|
56
|
+
def cache
|
57
|
+
@cache ||= Cache.new
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'yaml/store'
|
3
|
+
|
4
|
+
module MasterLeague
|
5
|
+
class Cache
|
6
|
+
def initialize(path: '~/.config/master_league_cache.yml')
|
7
|
+
path = Pathname.new(path).expand_path
|
8
|
+
|
9
|
+
if path.file? || path.parent.directory?
|
10
|
+
@store = YAML::Store.new(path)
|
11
|
+
else
|
12
|
+
raise "#{path} is not a valid path for the Cache"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def write(key, value)
|
17
|
+
@store.transaction do
|
18
|
+
@store[key] = value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def read(key)
|
23
|
+
@store.transaction do
|
24
|
+
@store[key]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def fetch(key, &block)
|
29
|
+
@store.transaction do
|
30
|
+
value = @store[key]
|
31
|
+
|
32
|
+
if value
|
33
|
+
value
|
34
|
+
else
|
35
|
+
@store[key] = yield
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete(key)
|
41
|
+
@store.transaction do
|
42
|
+
@store.delete(key)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def clear
|
47
|
+
@store.transaction do
|
48
|
+
@store.path.delete
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module MasterLeague
|
2
|
+
class Draft
|
3
|
+
include Virtus.model(finalize: false)
|
4
|
+
|
5
|
+
attribute :team_id, Integer
|
6
|
+
attribute :winner, Boolean
|
7
|
+
attribute :ban_ids, Array[Integer]
|
8
|
+
attribute :picks, Array[Pick]
|
9
|
+
|
10
|
+
def team
|
11
|
+
@team ||= TeamRepository.new.find(team_id) if team_id
|
12
|
+
end
|
13
|
+
|
14
|
+
def bans
|
15
|
+
@bans ||= ban_ids.map do |hero_id|
|
16
|
+
HeroRepository.new.find(hero_id)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module MasterLeague
|
2
|
+
class EventRepository < Repository
|
3
|
+
self.path = 'calendar/'
|
4
|
+
|
5
|
+
def order(order)
|
6
|
+
raise 'The Events endpoint does not allow ordering'
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def instantiate_records(events_json)
|
12
|
+
events_json['results'].map { |event_json| instantiate_record(event_json) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def instantiate_record(event_json)
|
16
|
+
Event.new(event_json)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'http'
|
2
|
+
|
3
|
+
module MasterLeague
|
4
|
+
class Fetcher
|
5
|
+
attr_reader :last_response
|
6
|
+
|
7
|
+
def fetch(path, params = {})
|
8
|
+
if MasterLeague.caching_enabled?
|
9
|
+
cache_key = [path, params].join('.')
|
10
|
+
cached_response = MasterLeague.cache.read(cache_key)
|
11
|
+
|
12
|
+
if cached_response
|
13
|
+
cached_response
|
14
|
+
else
|
15
|
+
response = HTTP.get("#{base_url}/#{path}", params: params.merge(format: 'json'))
|
16
|
+
handle_response(response, cache_key: cache_key)
|
17
|
+
end
|
18
|
+
else
|
19
|
+
response = HTTP.get("#{base_url}/#{path}", params: params.merge(format: 'json'))
|
20
|
+
handle_response(response)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def handle_response(response, cache_key: nil)
|
27
|
+
@last_response = response
|
28
|
+
|
29
|
+
if response.status.ok?
|
30
|
+
if cache_key
|
31
|
+
MasterLeague.cache.write(cache_key, response.parse)
|
32
|
+
else
|
33
|
+
response.parse
|
34
|
+
end
|
35
|
+
else
|
36
|
+
raise "Something went wrong. #{response.status}: #{response}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def base_url
|
41
|
+
'https://api.masterleague.net'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module MasterLeague
|
2
|
+
class Hero
|
3
|
+
include Virtus.model(finalize: false)
|
4
|
+
|
5
|
+
ROLES = {
|
6
|
+
1 => 'Warrior',
|
7
|
+
2 => 'Support',
|
8
|
+
3 => 'Assassin',
|
9
|
+
4 => 'Specialist'
|
10
|
+
}
|
11
|
+
|
12
|
+
attribute :id, Integer
|
13
|
+
attribute :name, String
|
14
|
+
attribute :role_id, Integer
|
15
|
+
attribute :url, String
|
16
|
+
attribute :portrait, Hash
|
17
|
+
attribute :talents, Array[Talent]
|
18
|
+
|
19
|
+
def role
|
20
|
+
ROLES[role_id]
|
21
|
+
end
|
22
|
+
|
23
|
+
def reload
|
24
|
+
self.attributes = HeroRepository.new.find(id).attributes
|
25
|
+
self
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module MasterLeague
|
2
|
+
class HeroRepository < Repository
|
3
|
+
self.path = 'heroes/'
|
4
|
+
|
5
|
+
def order(order)
|
6
|
+
raise 'The Heroes endpoint does not allow ordering'
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def instantiate_records(heroes_json)
|
12
|
+
heroes_json['results'].map { |hero_json| instantiate_record(hero_json) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def instantiate_record(hero_json)
|
16
|
+
hero_json[:role_id] = hero_json.delete('role')
|
17
|
+
Hero.new(hero_json)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module MasterLeague
|
2
|
+
class MapRepository < Repository
|
3
|
+
self.path = 'maps/'
|
4
|
+
|
5
|
+
def order(order)
|
6
|
+
raise 'The Maps endpoint does not allow ordering'
|
7
|
+
end
|
8
|
+
|
9
|
+
def page(page)
|
10
|
+
raise 'The Maps endpoint does not allow pagination'
|
11
|
+
end
|
12
|
+
|
13
|
+
def limit(limit)
|
14
|
+
raise 'The Maps endpoint does not allow limiting'
|
15
|
+
end
|
16
|
+
|
17
|
+
def where(filters)
|
18
|
+
raise 'The Maps endpoint does not allow filtering'
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def instantiate_records(maps_json)
|
24
|
+
maps_json.map { |map_json| instantiate_record(map_json) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def instantiate_record(map_json)
|
28
|
+
Map.new(map_json)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module MasterLeague
|
2
|
+
class Match
|
3
|
+
include Virtus.model(finalize: false)
|
4
|
+
|
5
|
+
attribute :id, Integer
|
6
|
+
attribute :date, Date
|
7
|
+
attribute :patch_id, Integer
|
8
|
+
attribute :tournament_id, Integer
|
9
|
+
attribute :stage, Integer
|
10
|
+
attribute :round, String
|
11
|
+
attribute :series, Integer
|
12
|
+
attribute :game, Integer
|
13
|
+
attribute :map_id, Integer
|
14
|
+
attribute :url, String
|
15
|
+
attribute :drafts, Array[Draft]
|
16
|
+
|
17
|
+
def patch
|
18
|
+
@patch ||= PatchRepository.new.find(patch_id) if patch_id
|
19
|
+
end
|
20
|
+
|
21
|
+
def tournament
|
22
|
+
@tournament ||= TournamentRepository.new.find(tournament_id) if tournament_id
|
23
|
+
end
|
24
|
+
|
25
|
+
def map
|
26
|
+
@map ||= MapRepository.new.find(map_id) if map_id
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module MasterLeague
|
2
|
+
class MatchRepository < Repository
|
3
|
+
self.path = 'matches/'
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def instantiate_records(matches_json)
|
8
|
+
matches_json['results'].map { |match_json| instantiate_record(match_json) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def instantiate_record(match_json)
|
12
|
+
match_json[:patch_id] = match_json.delete('patch')
|
13
|
+
match_json[:tournament_id] = match_json.delete('tournament')
|
14
|
+
match_json[:map_id] = match_json.delete('map')
|
15
|
+
|
16
|
+
match_json['drafts'].each do |draft_json|
|
17
|
+
draft_json[:winner] = draft_json.delete('is_winner')
|
18
|
+
draft_json[:team_id] = draft_json.delete('team')
|
19
|
+
draft_json[:ban_ids] = draft_json.delete('bans')
|
20
|
+
|
21
|
+
draft_json['picks'].each do |pick_json|
|
22
|
+
pick_json[:hero_id] = pick_json['hero']
|
23
|
+
pick_json[:player_id] = pick_json['player']
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
Match.new(match_json)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module MasterLeague
|
2
|
+
class PatchRepository < Repository
|
3
|
+
self.path = 'patches/'
|
4
|
+
|
5
|
+
def order(order)
|
6
|
+
raise 'The Patches endpoint does not allow ordering'
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def instantiate_records(patches_json)
|
12
|
+
patches_json.map { |patch_json| instantiate_record(patch_json) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def instantiate_record(patch_json)
|
16
|
+
Patch.new(patch_json)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module MasterLeague
|
2
|
+
class Pick
|
3
|
+
include Virtus.model(finalize: false)
|
4
|
+
|
5
|
+
attribute :hero_id, Integer
|
6
|
+
attribute :player_id, Integer
|
7
|
+
|
8
|
+
def hero
|
9
|
+
@hero ||= HeroRepository.new.find(hero_id) if hero_id
|
10
|
+
end
|
11
|
+
|
12
|
+
def player
|
13
|
+
@player ||= PlayerRepository.new.find(player_id) if player_id
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module MasterLeague
|
2
|
+
class Player
|
3
|
+
include Virtus.model(finalize: false)
|
4
|
+
|
5
|
+
attribute :id, Integer
|
6
|
+
attribute :team_id, Integer
|
7
|
+
attribute :region_id, Integer
|
8
|
+
attribute :nickname, String
|
9
|
+
attribute :realname, String
|
10
|
+
attribute :country, String
|
11
|
+
attribute :role_id, Integer
|
12
|
+
attribute :url, String
|
13
|
+
attribute :photo, Hash
|
14
|
+
|
15
|
+
def team
|
16
|
+
@team ||= TeamRepository.new.find(team_id) if team_id
|
17
|
+
end
|
18
|
+
|
19
|
+
def region
|
20
|
+
@region ||= RegionRepository.new.find(region_id) if region_id
|
21
|
+
end
|
22
|
+
|
23
|
+
def role
|
24
|
+
Hero::ROLES[role_id]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module MasterLeague
|
2
|
+
class PlayerRepository < Repository
|
3
|
+
self.path = 'players/'
|
4
|
+
|
5
|
+
def order(order)
|
6
|
+
raise 'The Players endpoint does not allow ordering'
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def instantiate_records(players_json)
|
12
|
+
players_json['results'].map { |player_json| instantiate_record(player_json) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def instantiate_record(player_json)
|
16
|
+
player_json[:team_id] = player_json.delete('team')
|
17
|
+
player_json[:role_id] = player_json.delete('role')
|
18
|
+
|
19
|
+
Player.new(player_json)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module MasterLeague
|
2
|
+
class RegionRepository < Repository
|
3
|
+
self.path = 'regions/'
|
4
|
+
|
5
|
+
def order(order)
|
6
|
+
raise 'The Regions endpoint does not allow ordering'
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def instantiate_records(regions_json)
|
12
|
+
regions_json.map { |region_json| instantiate_record(region_json) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def instantiate_record(region_json)
|
16
|
+
Region.new(region_json)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
module MasterLeague
|
2
|
+
class Repository
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
class << self
|
6
|
+
attr_accessor :path
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_accessor :order_value, :page_value, :limit_value
|
10
|
+
|
11
|
+
def each(&block)
|
12
|
+
records.each(&block)
|
13
|
+
end
|
14
|
+
|
15
|
+
def last
|
16
|
+
records.last
|
17
|
+
end
|
18
|
+
|
19
|
+
def find(id)
|
20
|
+
response = MasterLeague.fetch("#{self.class.path}#{id}/")
|
21
|
+
instantiate_record(response)
|
22
|
+
end
|
23
|
+
|
24
|
+
def all
|
25
|
+
clone
|
26
|
+
end
|
27
|
+
|
28
|
+
def order(order)
|
29
|
+
clone.tap do |repository|
|
30
|
+
unload
|
31
|
+
repository.order_value = order
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def page(page)
|
36
|
+
clone.tap do |repository|
|
37
|
+
unload
|
38
|
+
repository.page_value = page
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def limit(limit)
|
43
|
+
clone.tap do |repository|
|
44
|
+
unload
|
45
|
+
repository.limit_value = limit
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def where(filters)
|
50
|
+
clone.tap do |repository|
|
51
|
+
unload
|
52
|
+
repository.where_values.merge!(filters)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def inspect
|
57
|
+
entries = records.first(11).map!(&:inspect)
|
58
|
+
entries[10] = '...' if entries.size == 11
|
59
|
+
|
60
|
+
"#<#{self.class.name} [#{entries.join(', ')}]>"
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def where_values
|
66
|
+
@where_values ||= {}
|
67
|
+
end
|
68
|
+
|
69
|
+
def load
|
70
|
+
unless loaded?
|
71
|
+
@records = fetch
|
72
|
+
@loaded = true
|
73
|
+
end
|
74
|
+
|
75
|
+
self
|
76
|
+
end
|
77
|
+
|
78
|
+
def unload
|
79
|
+
@loaded = false
|
80
|
+
@records = nil
|
81
|
+
end
|
82
|
+
|
83
|
+
def loaded?
|
84
|
+
!!@loaded
|
85
|
+
end
|
86
|
+
|
87
|
+
def fetch
|
88
|
+
response = MasterLeague.fetch(self.class.path, where_values.merge(params))
|
89
|
+
instantiate_records(response)
|
90
|
+
end
|
91
|
+
|
92
|
+
def instantiate_records(records_json)
|
93
|
+
raise NotImplementedError
|
94
|
+
end
|
95
|
+
|
96
|
+
def instantiate_record(record_json)
|
97
|
+
raise NotImplementedError
|
98
|
+
end
|
99
|
+
|
100
|
+
def params
|
101
|
+
{}.tap do |params|
|
102
|
+
params[:ordering] = @order_value if @order_value
|
103
|
+
params[:page] = @page_value if @page_value
|
104
|
+
params[:page_size] = @limit_value if @limit_value
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def records
|
109
|
+
load
|
110
|
+
@records
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module MasterLeague
|
2
|
+
class Team
|
3
|
+
include Virtus.model(finalize: false)
|
4
|
+
|
5
|
+
attribute :id, Integer
|
6
|
+
attribute :name, String
|
7
|
+
attribute :region_id, Integer
|
8
|
+
attribute :url, String
|
9
|
+
attribute :logo, Hash
|
10
|
+
|
11
|
+
def region
|
12
|
+
@region ||= RegionRepository.new.find(region_id) if region_id
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module MasterLeague
|
2
|
+
class TeamRepository < Repository
|
3
|
+
self.path = 'teams/'
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def instantiate_records(teams_json)
|
8
|
+
teams_json['results'].map { |team_json| instantiate_record(team_json) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def instantiate_record(team_json)
|
12
|
+
team_json[:region_id] = team_json.delete('region')
|
13
|
+
Team.new(team_json)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module MasterLeague
|
2
|
+
class Tournament
|
3
|
+
include Virtus.model(finalize: false)
|
4
|
+
|
5
|
+
attribute :id, Integer
|
6
|
+
attribute :name, String
|
7
|
+
attribute :start_date, Date
|
8
|
+
attribute :end_date, Date
|
9
|
+
attribute :region_id, Integer
|
10
|
+
attribute :url, String
|
11
|
+
attribute :stages, Array[Stage]
|
12
|
+
|
13
|
+
def region
|
14
|
+
RegionRepository.new.find(region_id) if region_id
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module MasterLeague
|
2
|
+
class TournamentRepository < Repository
|
3
|
+
self.path = 'tournaments/'
|
4
|
+
|
5
|
+
def order(order)
|
6
|
+
raise 'The Tournaments endpoint does not allow ordering'
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def instantiate_records(tournaments_json)
|
12
|
+
tournaments_json['results'].map { |tournament_json| instantiate_record(tournament_json) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def instantiate_record(tournament_json)
|
16
|
+
tournament_json[:region_id] = tournament_json.delete('region')
|
17
|
+
Tournament.new(tournament_json)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require 'master_league/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'master_league'
|
8
|
+
spec.version = MasterLeague::VERSION
|
9
|
+
spec.authors = ['Tobias Bühlmann']
|
10
|
+
spec.email = ['tobias@xn--bhlmann-n2a.de']
|
11
|
+
|
12
|
+
spec.summary = 'Client to consume the Master League API'
|
13
|
+
spec.description = 'This Gem serves as a client for the Master League API'
|
14
|
+
spec.homepage = 'https://github.com/tbuehlmann/master_league'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(/^exe/) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_dependency 'http'
|
26
|
+
spec.add_dependency 'virtus'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: master_league
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tobias Bühlmann
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: http
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: virtus
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: This Gem serves as a client for the Master League API
|
42
|
+
email:
|
43
|
+
- tobias@xn--bhlmann-n2a.de
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
50
|
+
- ".travis.yml"
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bin/console
|
56
|
+
- bin/setup
|
57
|
+
- lib/master_league.rb
|
58
|
+
- lib/master_league/cache.rb
|
59
|
+
- lib/master_league/draft.rb
|
60
|
+
- lib/master_league/event.rb
|
61
|
+
- lib/master_league/event_repository.rb
|
62
|
+
- lib/master_league/fetcher.rb
|
63
|
+
- lib/master_league/hero.rb
|
64
|
+
- lib/master_league/hero_repository.rb
|
65
|
+
- lib/master_league/map.rb
|
66
|
+
- lib/master_league/map_repository.rb
|
67
|
+
- lib/master_league/match.rb
|
68
|
+
- lib/master_league/match_repository.rb
|
69
|
+
- lib/master_league/patch.rb
|
70
|
+
- lib/master_league/patch_repository.rb
|
71
|
+
- lib/master_league/pick.rb
|
72
|
+
- lib/master_league/player.rb
|
73
|
+
- lib/master_league/player_repository.rb
|
74
|
+
- lib/master_league/region.rb
|
75
|
+
- lib/master_league/region_repository.rb
|
76
|
+
- lib/master_league/repository.rb
|
77
|
+
- lib/master_league/stage.rb
|
78
|
+
- lib/master_league/talent.rb
|
79
|
+
- lib/master_league/team.rb
|
80
|
+
- lib/master_league/team_repository.rb
|
81
|
+
- lib/master_league/tournament.rb
|
82
|
+
- lib/master_league/tournament_repository.rb
|
83
|
+
- lib/master_league/version.rb
|
84
|
+
- master_league.gemspec
|
85
|
+
homepage: https://github.com/tbuehlmann/master_league
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.6.8
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Client to consume the Master League API
|
109
|
+
test_files: []
|