hots_api 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/README.md +80 -13
- data/lib/hots_api.rb +12 -8
- data/lib/hots_api/models/ability.rb +18 -0
- data/lib/hots_api/models/hero.rb +17 -0
- data/lib/hots_api/models/{map_translation.rb → map.rb} +2 -2
- data/lib/hots_api/models/player.rb +5 -1
- data/lib/hots_api/models/replay.rb +5 -2
- data/lib/hots_api/models/score.rb +30 -0
- data/lib/hots_api/models/talent.rb +18 -0
- data/lib/hots_api/repositories/hero_repository.rb +17 -0
- data/lib/hots_api/repositories/map_repository.rb +17 -0
- data/lib/hots_api/repositories/replay_repository.rb +25 -16
- data/lib/hots_api/repositories/repository.rb +39 -28
- data/lib/hots_api/repositories/simple_repository.rb +51 -0
- data/lib/hots_api/version.rb +1 -1
- metadata +10 -6
- data/lib/hots_api/models/hero_translation.rb +0 -10
- data/lib/hots_api/repositories/hero_translation_repository.rb +0 -17
- data/lib/hots_api/repositories/map_translation_repository.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6eacde3f7fec5d281b325c19a18105c85ec4f22
|
4
|
+
data.tar.gz: a3c762e406afc473666090ce6019752c2420d96c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9584f70e097bd947efcce00fb3dc2ad80ee9d4fa1c44ae82899204abcc6fc7bb5bbfc22cccdc901018ff659f37e0e587cf2af32f3eaaeeaf42f72236c1308afc
|
7
|
+
data.tar.gz: 8296bbb3762930865734236099632b73d1ea11c55b4fe17d750294d8ffdf389b24dda6b12487217986a235bf4284d07f7c505216b8d796bac088c3c37a40148b
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -28,21 +28,54 @@ Or install it yourself as:
|
|
28
28
|
replay = HotsApi.replays.find(59) # => #<HotsApi::Models::Replay>
|
29
29
|
replay.id # => 59
|
30
30
|
replay.filename # => '04e92942-7a46-f12c-24f6-65dcf4ea409f'
|
31
|
+
replay.size # => 1495665
|
31
32
|
replay.fingerprint # => '04e92942-7a46-2cf1-24f6-65dcf4ea409f'
|
32
33
|
replay.game_date # => 2017-08-15 23:16:28 +0200
|
33
34
|
replay.game_length # => 872
|
34
35
|
replay.game_map # => 'Braxis Holdout'
|
35
36
|
replay.game_type # => 'HeroLeague'
|
36
37
|
replay.game_version # => '2.27.1.56361'
|
38
|
+
replay.region # => 2
|
39
|
+
replay.processed # => true
|
40
|
+
replay.url # => 'http://hotsapi.s3-website-eu-west-1.amazonaws.com/04e92942-7a46-f12c-24f6-65dcf4ea409f.StormReplay'
|
41
|
+
replay.created_at # => 2017-08-27 14:58:59 +0200
|
42
|
+
replay.updated_at # => 2017-10-04 01:23:53 +0200
|
37
43
|
replay.players # => [#<HotsApi::Models::Player>, …]
|
38
44
|
|
39
|
-
player = replay.players[
|
45
|
+
player = replay.players[2] # => #<HotsApi::Models::Player>
|
40
46
|
player.blizz_id # => 215378
|
41
47
|
player.battletag # => 'Poma'
|
42
48
|
player.hero # => 'Chromie'
|
43
49
|
player.hero_level # => 13
|
44
50
|
player.team # => 0
|
45
51
|
player.winner # => true
|
52
|
+
player.party # => 0
|
53
|
+
player.talents # => {'1' => 'ChromieTimewalkersPursuit', '4' => 'ChromieBronzeTalons', '7' => 'ChromieDragonsBreathDragonsEye', '10' => 'ChromieHeroicAbilityTemporalLoop', '13' => 'ChromieReachingThroughTime', '16' => 'ChromieQuantumOverdrive'}
|
54
|
+
player.score # => #<HotsApi::Models::Score>
|
55
|
+
|
56
|
+
score = player.score # => #<HotsApi::Models::Score>
|
57
|
+
score.level # => 16
|
58
|
+
score.kills # => 9
|
59
|
+
score.assists # => 14
|
60
|
+
score.takedowns # => 23
|
61
|
+
score.deaths # => 1
|
62
|
+
score.highest_kill_streak # => 23
|
63
|
+
score.hero_damage # => 35902
|
64
|
+
score.siege_damage # => 33200
|
65
|
+
score.structure_damage # => 10571
|
66
|
+
score.minion_damage # => 20839
|
67
|
+
score.creep_damage # => 6686
|
68
|
+
score.summon_damage # => 1790
|
69
|
+
score.time_cc_enemy_heroes # => 5033
|
70
|
+
score.healing # => nil
|
71
|
+
score.self_healing # => 0
|
72
|
+
score.damage_taken # => nil
|
73
|
+
score.experience_contribution # => 7683
|
74
|
+
score.town_kills # => 0
|
75
|
+
score.time_spent_dead # => 44
|
76
|
+
score.merc_camp_captures # => 3
|
77
|
+
score.watch_tower_captures # => 0
|
78
|
+
score.meta_experience # => 52960
|
46
79
|
```
|
47
80
|
|
48
81
|
#### Finding Replays
|
@@ -58,6 +91,9 @@ replays = HotsApi.replays.to_a # => [#<HotsApi::Models::Replay>, …]
|
|
58
91
|
replays = HotsApi.replays.where(start_date: '2017-09-01 00:00').to_a
|
59
92
|
replays = HotsApi.replays.where(end_date: '2017-09-01 00:00').to_a
|
60
93
|
|
94
|
+
# by game map
|
95
|
+
replays = HotsApi.replays.where(game_map: 'Hanamura').to_a
|
96
|
+
|
61
97
|
# by game type
|
62
98
|
replays = HotsApi.replays.where(game_type: 'HeroLeague').to_a
|
63
99
|
|
@@ -74,6 +110,8 @@ replays = HotsApi.replays.where(hero: 'Tassadar').to_a
|
|
74
110
|
replays = HotsApi.replays.where(start_date: '2017-09-01 00:00', end_date: '2017-09-01 23:59').where(game_type: 'HeroLeague').to_a
|
75
111
|
```
|
76
112
|
|
113
|
+
Note: Filtering by player and hero is disabled on the server right now, so you cannot use it.
|
114
|
+
|
77
115
|
#### Include Players
|
78
116
|
|
79
117
|
Replays don't include its players per default. If you want to include players, use `with_players` (which is also chainable):
|
@@ -146,7 +184,7 @@ HotsApi.replays.fingerprints_uploaded?(fingerprints) # => {'04e92942-7a46-2cf1-2
|
|
146
184
|
|
147
185
|
#### Triggering HotsLogs Uploads
|
148
186
|
|
149
|
-
If there's a replay saved on HotsApi, you can trigger uploading it to HotsLogs
|
187
|
+
If there's a replay saved on HotsApi, you can trigger uploading it to HotsLogs usings its fingerprint:
|
150
188
|
|
151
189
|
```ruby
|
152
190
|
fingerprint = '04e92942-7a46-2cf1-24f6-65dcf4ea409f'
|
@@ -159,7 +197,7 @@ else
|
|
159
197
|
end
|
160
198
|
```
|
161
199
|
|
162
|
-
The actual uploading to HotsLogs happens from the HotsApi server.
|
200
|
+
The actual uploading to HotsLogs happens from the HotsApi server, not your local computer.
|
163
201
|
|
164
202
|
#### Getting The Minimal Supported Build Version
|
165
203
|
|
@@ -167,24 +205,53 @@ The actual uploading to HotsLogs happens from the HotsApi server.
|
|
167
205
|
HotsApi.replays.minimum_supported_build # => 43905
|
168
206
|
```
|
169
207
|
|
170
|
-
## Finding
|
208
|
+
## Finding Heroes
|
209
|
+
|
210
|
+
#### Finding a Single Hero
|
171
211
|
|
172
212
|
```ruby
|
173
|
-
|
213
|
+
hero = HotsApi.heroes.find('Tassadar') # => #<HotsApi::Models::Hero>
|
214
|
+
hero.name # => 'Tassadar'
|
215
|
+
hero.short_name # => 'tassadar'
|
216
|
+
hero.role # => 'Support'
|
217
|
+
hero.type # => 'Ranged'
|
218
|
+
hero.release_date # => 2014-03-13
|
219
|
+
hero.icon_url # => {'92x93' => 'http://s3.hotsapi.net/img/heroes/92x93/tassadar.png'}
|
220
|
+
hero.translations # => ['тассадар', '태사다르', '塔萨达尔', '塔薩達', 'tassadar']
|
221
|
+
hero.abilities # => [#<HotsApi::Models::Ability>, …]
|
222
|
+
|
223
|
+
ability = hero.abilities[0] # => #<HotsApi::Models::Ability>
|
224
|
+
ability.name # => 'D1'
|
225
|
+
ability.owner # => 'Tassadar'
|
226
|
+
ability.title # => 'Oracle'
|
227
|
+
ability.description # => 'Activate to greatly increase Tassadar's vision radius, allow him to see over obstacles, and detect stealthed units. Lasts for 5 seconds. Passive: Tassadar's Basic Attack is a Distortion Beam that slows enemy units by 20%.'
|
228
|
+
ability.icon # => nil
|
229
|
+
ability.hotkey # => 'D'
|
230
|
+
ability.cooldown # => 30
|
231
|
+
ability.mana_cost # => nil
|
232
|
+
ability.trait # => true
|
233
|
+
```
|
234
|
+
|
235
|
+
#### Finding Heroes
|
174
236
|
|
175
|
-
|
176
|
-
|
177
|
-
hero_translation.versions # => ['abatur', 'абатур', '아바투르', '阿巴瑟', 'abathur']
|
237
|
+
```ruby
|
238
|
+
heroes = HotsApi.heroes.to_a # => [#<HotsApi::Models::Hero>, …]
|
178
239
|
```
|
179
240
|
|
180
|
-
## Finding
|
241
|
+
## Finding Maps
|
242
|
+
|
243
|
+
#### Finding a Single Map
|
181
244
|
|
182
245
|
```ruby
|
183
|
-
|
246
|
+
map = HotsApi.maps.find('Tomb of the Spider Queen') # => #<HotsApi::Models::Map>
|
247
|
+
map.name # => 'Tomb of the Spider Queen'
|
248
|
+
map.translations # => ['tumba de la reina araña', '蛛后之墓', 'tumba da aranha rainha', '거미 여왕의 무덤', 'tombe de la reine araignée', 'grabkammer der spinnenkönigin', 'grobowiec pajęczej królowej', 'tomba della regina ragno', 'гробница королевы пауков', '蛛后墓', 'tomb of the spider queen']
|
249
|
+
```
|
184
250
|
|
185
|
-
|
186
|
-
|
187
|
-
|
251
|
+
#### Finding Maps
|
252
|
+
|
253
|
+
```ruby
|
254
|
+
map = HotsApi.maps.to_a # => [#<HotsApi::Models::Map>, …]
|
188
255
|
```
|
189
256
|
|
190
257
|
## Rate Limiting
|
data/lib/hots_api.rb
CHANGED
@@ -4,15 +4,19 @@ require_relative 'hots_api/fetcher'
|
|
4
4
|
require_relative 'hots_api/version'
|
5
5
|
|
6
6
|
require_relative 'hots_api/models/model'
|
7
|
-
require_relative 'hots_api/models/
|
8
|
-
require_relative 'hots_api/models/
|
7
|
+
require_relative 'hots_api/models/ability'
|
8
|
+
require_relative 'hots_api/models/talent'
|
9
|
+
require_relative 'hots_api/models/hero'
|
10
|
+
require_relative 'hots_api/models/map'
|
11
|
+
require_relative 'hots_api/models/score'
|
9
12
|
require_relative 'hots_api/models/player'
|
10
13
|
require_relative 'hots_api/models/replay'
|
11
14
|
require_relative 'hots_api/models/uploaded_replay'
|
12
15
|
|
13
16
|
require_relative 'hots_api/repositories/repository'
|
14
|
-
require_relative 'hots_api/repositories/
|
15
|
-
require_relative 'hots_api/repositories/
|
17
|
+
require_relative 'hots_api/repositories/simple_repository'
|
18
|
+
require_relative 'hots_api/repositories/hero_repository'
|
19
|
+
require_relative 'hots_api/repositories/map_repository'
|
16
20
|
require_relative 'hots_api/repositories/replay_repository'
|
17
21
|
|
18
22
|
module HotsApi
|
@@ -32,11 +36,11 @@ module HotsApi
|
|
32
36
|
Repositories::ReplayRepository.new
|
33
37
|
end
|
34
38
|
|
35
|
-
def self.
|
36
|
-
Repositories::
|
39
|
+
def self.heroes
|
40
|
+
Repositories::HeroRepository.new
|
37
41
|
end
|
38
42
|
|
39
|
-
def self.
|
40
|
-
Repositories::
|
43
|
+
def self.maps
|
44
|
+
Repositories::MapRepository.new
|
41
45
|
end
|
42
46
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HotsApi
|
4
|
+
module Models
|
5
|
+
class Ability < Model
|
6
|
+
attribute :owner, String
|
7
|
+
attribute :name, String
|
8
|
+
attribute :title, String
|
9
|
+
attribute :description, String
|
10
|
+
attribute :icon, String
|
11
|
+
attribute :hotkey, String
|
12
|
+
attribute :cooldown, Integer
|
13
|
+
attribute :mana_cost, Integer
|
14
|
+
attribute :mana_cost, Integer
|
15
|
+
attribute :trait, Boolean
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HotsApi
|
4
|
+
module Models
|
5
|
+
class Hero < Model
|
6
|
+
attribute :name, String
|
7
|
+
attribute :short_name, String
|
8
|
+
attribute :role, String
|
9
|
+
attribute :type, String
|
10
|
+
attribute :release_date, Date
|
11
|
+
attribute :icon_url, Hash
|
12
|
+
attribute :translations, Array[String]
|
13
|
+
attribute :abilities, Array[Ability]
|
14
|
+
attribute :talents, Array[Talent]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -3,12 +3,16 @@
|
|
3
3
|
module HotsApi
|
4
4
|
module Models
|
5
5
|
class Player < Model
|
6
|
-
attribute :battletag, String
|
7
6
|
attribute :hero, String
|
8
7
|
attribute :hero_level, Integer
|
9
8
|
attribute :team, Integer
|
10
9
|
attribute :winner, Boolean
|
11
10
|
attribute :blizz_id, Integer
|
11
|
+
attribute :party, Integer
|
12
|
+
attribute :silenced, Boolean
|
13
|
+
attribute :battletag, String
|
14
|
+
attribute :talents, Hash
|
15
|
+
attribute :score, Score
|
12
16
|
end
|
13
17
|
end
|
14
18
|
end
|
@@ -8,12 +8,15 @@ module HotsApi
|
|
8
8
|
attribute :size, Integer
|
9
9
|
attribute :game_type, String
|
10
10
|
attribute :game_date, Time
|
11
|
-
attribute :game_length, Integer
|
12
11
|
attribute :game_map, String
|
12
|
+
attribute :game_length, Integer
|
13
13
|
attribute :game_version, String
|
14
|
-
attribute :region, Integer
|
15
14
|
attribute :fingerprint, String
|
15
|
+
attribute :region, Integer
|
16
|
+
attribute :processed, Boolean
|
16
17
|
attribute :url, String
|
18
|
+
attribute :created_at, Time
|
19
|
+
attribute :updated_at, Time
|
17
20
|
attribute :players, Array[Player]
|
18
21
|
|
19
22
|
def reload
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HotsApi
|
4
|
+
module Models
|
5
|
+
class Score < Model
|
6
|
+
attribute :level, Integer
|
7
|
+
attribute :kills, Integer
|
8
|
+
attribute :assists, Integer
|
9
|
+
attribute :takedowns, Integer
|
10
|
+
attribute :deaths, Integer
|
11
|
+
attribute :highest_kill_streak, Integer
|
12
|
+
attribute :hero_damage, Integer
|
13
|
+
attribute :siege_damage, Integer
|
14
|
+
attribute :structure_damage, Integer
|
15
|
+
attribute :minion_damage, Integer
|
16
|
+
attribute :creep_damage, Integer
|
17
|
+
attribute :summon_damage, Integer
|
18
|
+
attribute :time_cc_enemy_heroes, Integer
|
19
|
+
attribute :healing, Integer
|
20
|
+
attribute :self_healing, Integer
|
21
|
+
attribute :damage_taken, Integer
|
22
|
+
attribute :experience_contribution, Integer
|
23
|
+
attribute :town_kills, Integer
|
24
|
+
attribute :time_spent_dead, Integer
|
25
|
+
attribute :merc_camp_captures, Integer
|
26
|
+
attribute :watch_tower_captures, Integer
|
27
|
+
attribute :meta_experience, Integer
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HotsApi
|
4
|
+
module Models
|
5
|
+
class Talent < Model
|
6
|
+
attribute :name, String
|
7
|
+
attribute :title, String
|
8
|
+
attribute :description, String
|
9
|
+
attribute :icon, String
|
10
|
+
attribute :icon_url, Hash
|
11
|
+
attribute :ability, String
|
12
|
+
attribute :sort, Integer
|
13
|
+
attribute :cooldown, Integer
|
14
|
+
attribute :mana_cost, Integer
|
15
|
+
attribute :level, Integer
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HotsApi
|
4
|
+
module Repositories
|
5
|
+
class HeroRepository < SimpleRepository
|
6
|
+
private
|
7
|
+
|
8
|
+
def instantiate_record_with(attributes)
|
9
|
+
Models::Hero.new(attributes)
|
10
|
+
end
|
11
|
+
|
12
|
+
def collection_path
|
13
|
+
'heroes'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HotsApi
|
4
|
+
module Repositories
|
5
|
+
class MapRepository < SimpleRepository
|
6
|
+
private
|
7
|
+
|
8
|
+
def instantiate_record_with(attributes)
|
9
|
+
Models::Map.new(attributes)
|
10
|
+
end
|
11
|
+
|
12
|
+
def collection_path
|
13
|
+
'maps'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -4,22 +4,25 @@ module HotsApi
|
|
4
4
|
module Repositories
|
5
5
|
class ReplayRepository < Repository
|
6
6
|
def upload(file)
|
7
|
-
response = HotsApi.post(
|
7
|
+
response = HotsApi.post('replays', file: file)
|
8
8
|
Models::UploadedReplay.new(response.parse)
|
9
9
|
end
|
10
10
|
|
11
11
|
def trigger_hotslogs_upload(fingerprint)
|
12
|
-
HotsApi.get("
|
12
|
+
response = HotsApi.get("replays/fingerprints/v3/#{fingerprint}", params: {uploadToHotslogs: 1})
|
13
|
+
response.parse['exists']
|
13
14
|
end
|
14
15
|
|
15
16
|
def fingerprint_uploaded?(fingerprint)
|
16
|
-
HotsApi.get("
|
17
|
+
response = HotsApi.get("replays/fingerprints/v3/#{fingerprint}")
|
18
|
+
response.parse['exists']
|
17
19
|
end
|
18
20
|
|
19
21
|
def fingerprints_uploaded?(fingerprints)
|
20
22
|
return {} if fingerprints.empty?
|
21
23
|
|
22
|
-
|
24
|
+
response = HotsApi.post('replays/fingerprints', body: fingerprints.join("\n"))
|
25
|
+
upload_statuses = response.parse
|
23
26
|
|
24
27
|
{}.tap do |fingerprint_statuses|
|
25
28
|
upload_statuses['exists'].each do |fingerprint|
|
@@ -33,37 +36,43 @@ module HotsApi
|
|
33
36
|
end
|
34
37
|
|
35
38
|
def minimum_supported_build
|
36
|
-
HotsApi.get(
|
39
|
+
HotsApi.get('replays/min-build').to_s.to_i
|
37
40
|
end
|
38
41
|
|
39
42
|
def with_players
|
40
|
-
|
43
|
+
copy { @where_values[:with_players] = 1 }
|
41
44
|
end
|
42
45
|
|
43
46
|
private
|
44
47
|
|
45
48
|
def start_date=(date)
|
46
|
-
where_values[:start_date] = date_string_for(date)
|
49
|
+
@where_values[:start_date] = date_string_for(date)
|
47
50
|
end
|
48
51
|
|
49
52
|
def end_date=(date)
|
50
|
-
where_values[:end_date] = date_string_for(date)
|
53
|
+
@where_values[:end_date] = date_string_for(date)
|
54
|
+
end
|
55
|
+
|
56
|
+
def game_map=(map)
|
57
|
+
@where_values[:game_map] = map
|
51
58
|
end
|
52
59
|
|
53
60
|
def game_type=(game_type)
|
54
|
-
where_values[:game_type] = game_type
|
61
|
+
@where_values[:game_type] = game_type
|
55
62
|
end
|
56
63
|
|
57
64
|
def min_id=(id)
|
58
|
-
where_values[:min_id] = id
|
65
|
+
@where_values[:min_id] = id
|
59
66
|
end
|
60
67
|
|
61
68
|
def player=(player)
|
62
|
-
|
69
|
+
raise 'filtering by player is currently deactivated on hotsapi.net'
|
70
|
+
@where_values[:player] = player
|
63
71
|
end
|
64
72
|
|
65
73
|
def hero=(hero)
|
66
|
-
|
74
|
+
raise 'filtering by hero is currently deactivated on hotsapi.net'
|
75
|
+
@where_values[:hero] = hero
|
67
76
|
end
|
68
77
|
|
69
78
|
def date_string_for(date)
|
@@ -74,12 +83,12 @@ module HotsApi
|
|
74
83
|
end
|
75
84
|
end
|
76
85
|
|
77
|
-
def
|
78
|
-
|
86
|
+
def instantiate_record_with(attributes)
|
87
|
+
Models::Replay.new(attributes)
|
79
88
|
end
|
80
89
|
|
81
|
-
def
|
82
|
-
|
90
|
+
def collection_path
|
91
|
+
'replays'
|
83
92
|
end
|
84
93
|
end
|
85
94
|
end
|
@@ -5,20 +5,20 @@ module HotsApi
|
|
5
5
|
class Repository
|
6
6
|
include Enumerable
|
7
7
|
|
8
|
-
def
|
9
|
-
@
|
8
|
+
def initialize(where_values: {})
|
9
|
+
@where_values = where_values
|
10
10
|
end
|
11
11
|
|
12
12
|
def find(id)
|
13
|
-
response = HotsApi.get("#{
|
13
|
+
response = HotsApi.get("#{collection_path}/#{id}")
|
14
14
|
|
15
15
|
if response.status.ok?
|
16
|
-
|
16
|
+
instantiate_record_with(response.parse)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
def where(conditions = {})
|
21
|
-
|
21
|
+
copy do
|
22
22
|
conditions.each do |attribute, value|
|
23
23
|
if respond_to?("#{attribute}=", true)
|
24
24
|
send("#{attribute}=", value)
|
@@ -30,13 +30,11 @@ module HotsApi
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def next_page
|
33
|
-
if records.any?
|
34
|
-
where(min_id: records.last.id + 1)
|
35
|
-
end
|
33
|
+
fetch { where(min_id: @records.last.id + 1) if @records.any? }
|
36
34
|
end
|
37
35
|
|
38
36
|
def each(&block)
|
39
|
-
records.each(&block)
|
37
|
+
fetch { @records.each(&block) }
|
40
38
|
end
|
41
39
|
|
42
40
|
def find_each(&block)
|
@@ -44,16 +42,39 @@ module HotsApi
|
|
44
42
|
end
|
45
43
|
|
46
44
|
def last(n = nil)
|
47
|
-
n ? records.last(n) : records.last
|
45
|
+
fetch { n ? @records.last(n) : @records.last }
|
46
|
+
end
|
47
|
+
|
48
|
+
def size
|
49
|
+
fetch { @records.size }
|
50
|
+
end
|
51
|
+
|
52
|
+
def length
|
53
|
+
fetch { @records.length }
|
48
54
|
end
|
49
55
|
|
50
|
-
|
51
|
-
|
56
|
+
private
|
57
|
+
|
58
|
+
def copy(&block)
|
59
|
+
self.class.new(where_values: @where_values.clone, &block).tap do |repository|
|
52
60
|
repository.instance_exec(&block)
|
53
61
|
end
|
54
62
|
end
|
55
63
|
|
56
|
-
|
64
|
+
def fetched?
|
65
|
+
@fetched
|
66
|
+
end
|
67
|
+
|
68
|
+
def fetch
|
69
|
+
unless @fetched
|
70
|
+
response = HotsApi.get(collection_path, params: @where_values)
|
71
|
+
@records = instantiate_records(response.parse)
|
72
|
+
|
73
|
+
@fetched = true
|
74
|
+
end
|
75
|
+
|
76
|
+
yield
|
77
|
+
end
|
57
78
|
|
58
79
|
def find_each_enum
|
59
80
|
Enumerator.new do |yielder|
|
@@ -66,27 +87,17 @@ module HotsApi
|
|
66
87
|
end
|
67
88
|
end
|
68
89
|
|
69
|
-
def
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
def records
|
74
|
-
@records ||= fetch_records
|
75
|
-
end
|
76
|
-
|
77
|
-
def fetch_records
|
78
|
-
response = HotsApi.get(path, params: where_values)
|
79
|
-
|
80
|
-
response.parse.map do |attributes|
|
81
|
-
model.new(attributes)
|
90
|
+
def instantiate_records(json)
|
91
|
+
json.map do |attributes|
|
92
|
+
instantiate_record_with(attributes)
|
82
93
|
end
|
83
94
|
end
|
84
95
|
|
85
|
-
def
|
96
|
+
def instantiate_record_with(attributes)
|
86
97
|
raise NotImplementedError
|
87
98
|
end
|
88
99
|
|
89
|
-
def
|
100
|
+
def collection_path
|
90
101
|
raise NotImplementedError
|
91
102
|
end
|
92
103
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HotsApi
|
4
|
+
module Repositories
|
5
|
+
class SimpleRepository
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
def find(id)
|
9
|
+
response = HotsApi.get("#{collection_path}/#{id}")
|
10
|
+
|
11
|
+
if response.status.ok?
|
12
|
+
instantiate_record_with(response.parse)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def each(&block)
|
17
|
+
records.each(&block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def last(n = nil)
|
21
|
+
n ? records.last(n) : records.last
|
22
|
+
end
|
23
|
+
|
24
|
+
def size
|
25
|
+
records.size
|
26
|
+
end
|
27
|
+
|
28
|
+
def length
|
29
|
+
records.length
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def records
|
35
|
+
@records ||= fetch_records
|
36
|
+
end
|
37
|
+
|
38
|
+
def fetch_records
|
39
|
+
response = HotsApi.get(collection_path)
|
40
|
+
|
41
|
+
response.parse.map do |attributes|
|
42
|
+
instantiate_record_with(attributes)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def collection_path
|
47
|
+
raise NotImplementedError
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/hots_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hots_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Bühlmann
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|
@@ -58,16 +58,20 @@ files:
|
|
58
58
|
- hots_api.gemspec
|
59
59
|
- lib/hots_api.rb
|
60
60
|
- lib/hots_api/fetcher.rb
|
61
|
-
- lib/hots_api/models/
|
62
|
-
- lib/hots_api/models/
|
61
|
+
- lib/hots_api/models/ability.rb
|
62
|
+
- lib/hots_api/models/hero.rb
|
63
|
+
- lib/hots_api/models/map.rb
|
63
64
|
- lib/hots_api/models/model.rb
|
64
65
|
- lib/hots_api/models/player.rb
|
65
66
|
- lib/hots_api/models/replay.rb
|
67
|
+
- lib/hots_api/models/score.rb
|
68
|
+
- lib/hots_api/models/talent.rb
|
66
69
|
- lib/hots_api/models/uploaded_replay.rb
|
67
|
-
- lib/hots_api/repositories/
|
68
|
-
- lib/hots_api/repositories/
|
70
|
+
- lib/hots_api/repositories/hero_repository.rb
|
71
|
+
- lib/hots_api/repositories/map_repository.rb
|
69
72
|
- lib/hots_api/repositories/replay_repository.rb
|
70
73
|
- lib/hots_api/repositories/repository.rb
|
74
|
+
- lib/hots_api/repositories/simple_repository.rb
|
71
75
|
- lib/hots_api/version.rb
|
72
76
|
homepage: https://github.com/tbuehlmann/hots_api
|
73
77
|
licenses:
|