Browse Source

Update readme to be comprehensive. Close #1

Tweak objects and formatting.
master
Andrew Zah 2 years ago
parent
commit
6e055e7951
Signed by: Andrew Zah <zah@andrewzah.com> GPG Key ID: 0AE942445EB70FAA

+ 10
- 0
.travis.yml View File

@@ -1 +1,11 @@
1 1
 language: crystal
2
+script:
3
+- crystal deps
4
+- crystal spec
5
+env:
6
+  global:
7
+  - ENCRYPTION_LABEL: 563f1b46fb00
8
+  - COMMIT_AUTHOR_EMAIL: zah.andrew@gmail.com
9
+after_success:
10
+  - chmox a+x ./deploy.sh
11
+  - bash ./deploy.sh

+ 280
- 7
README.md View File

@@ -1,4 +1,4 @@
1
-# dota
1
+# dotacr
2 2
 
3 3
 A Crystal client for the [DotA 2 API](https://wiki.teamfortress.com/wiki/WebAPI#Dota_2).
4 4
 
@@ -63,7 +63,7 @@ api.matches({"hero_id" => 43})          # Allowed options:
63 63
                                         # :player_id   - Integer, With this player (32-bit Steam ID)
64 64
                                         # :league_id   - Integer, In this league. Use Dota.leagues to get a list of leagues
65 65
                                         # :mode_id     - Integer, In this game mode. See Dota::API::Match::MODES
66
-                                        # :skill_level - Integer, In this skill level (ignored if :player_id is provided). See Dota::API::Match::SKILL_LEVELS
66
+                                        # :skill_level - Integer, In this skill level (ignored if :player_id is provided). See Dota::API::Match::SkillLevels
67 67
                                         # :from        - Integer, Minimum timestamp
68 68
                                         # :to          - Integer, Maximum timestamp
69 69
                                         # :min_players - Integer, With at least this number of players
@@ -81,15 +81,288 @@ api.cosmetic_rarities                   # => All cosmetic rarities
81 81
 api.friends(76561198052976237)           # => All friends of user
82 82
 ```
83 83
 
84
-TODO: Write usage instructions here
84
+#### Custom Requests
85 85
 
86
-## Development
86
+For the unsupported endpoints, you can use `api.get`. For example, the following code is similar to `api.matches(789645621)` except it will return the raw JSON payload instead of an array of `Dota::Match`es.
87 87
 
88
-TODO: Write development instructions here
88
+```crystal
89
+api.get(<Method>, <Class>, <Interface>, <Options Hash>)
90
+api.get("GetMatchDetails", API::Match, "IDOTA2Match_570", {"match_id" => 789645621})
91
+```
92
+
93
+**Note**: For queries that return an array of objects, you must use the relative list class:
94
+* Match => MatchesList
95
+* BasicMatch => BasicMatchesList
96
+* League => LeaguesList
97
+* etc.
98
+
99
+## API Objects
100
+
101
+### Hero
102
+
103
+```crystal
104
+hero.id        # Int8, ID of the hero
105
+hero.name      # String, Name of the hero
106
+hero.image_url # String, URL of the hero portrait
107
+```
108
+
109
+### Item
110
+
111
+```crystal
112
+item.id        # Int32
113
+item.name      # String
114
+item.image_url # String
115
+```
116
+
117
+### Ability
118
+
119
+```crystal
120
+ability.id        # Int32
121
+ability.name      # String -> "Beserker's Call"
122
+ability.fullName  # String -> "Axe Beserker's Call"
123
+```
124
+
125
+### Team
126
+TeamsList:
127
+
128
+```crystal
129
+list.status  # Int8
130
+list.teams   # Array(Dota::API::Team)
131
+```
132
+
133
+```crystal
134
+team.player_ids                   # Array(Int32)
135
+team.name                         # String
136
+team.tag                          # String
137
+team.country_code                 # String, ISO 3166-1 country code (see http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes)
138
+team.admin_id                     # Integer, Team admin's 32-bit Steam ID
139
+team.player_ids                   # Array[Integer], Players' 32-bit Steam IDs
140
+team.logo                         # String, UGC ID of the team's logo
141
+team.logo_sponsor                 # String, UGC ID of the team's logo
142
+team.url                          # String, URL of the team's website
143
+team.time_created                 # Int32
144
+team.games_played                 # Int16
145
+team.player0_id                   # Int32 | Nil
146
+...
147
+team.player6_id                   # Int32 | Nil
148
+team.calibration_games_remaining  # Int8
149
+```
150
+
151
+#### League
152
+`LeaguesList` has one member: `leagues: Array(Dota::API::League)`.
153
+
154
+```crystal
155
+league.id          # Int32
156
+league.name        # String
157
+league.description # String
158
+league.url         # String
159
+league.itemdef     # Int32
160
+
161
+Dota::API::League::Tiers
162
+enum Tiers
163
+    Amateur      = 1
164
+    Professional
165
+    Premier
166
+end
167
+```
168
+
169
+#### Match
170
+
171
+Caveat: Getting a list of matches via `api.matches` will call [GetMatchHistory](https://wiki.teamfortress.com/wiki/WebAPI/GetMatchHistory) which has very few attributes for the matches returned (obviously for performance reasons), as opposed to getting info about a particular match via `api.matches(id)` which will instead call [GetMatchDetails](https://wiki.teamfortress.com/wiki/WebAPI/GetMatchDetails). The former uses `Dota::API::BasicMatch`, the latter uses `Dota::API::Match`.
172
+
173
+#### Dota::API::BasicMatch
174
+The response will always be `Dota::API::BasicMatchesList`, even if there are 0 results.
175
+
176
+```crystal
177
+list.status             # Int32
178
+list.num_results        # Int32
179
+list.total_results      # Int32
180
+list.results_remaining  # Int32
181
+list.matches            # Array(Dota::API::BasicMatch)
182
+```
183
+
184
+```crystal
185
+basicMatch.match_id        # Int64
186
+basicmatch.match_seq_num   # Int64
187
+basicMatch.start_time      # Int32
188
+basicMatch.lobby_type      # Dota::API::MatchStatus::GameModes
189
+basicMatch.radiant_team_id # In32
190
+basicMatch.dire_team_id    # Int32
191
+basicMatch.players         # Array(Dota::API::BasicPlayer)
192
+```
193
+
194
+BasicPlayer:
195
+```crystal
196
+account_id    # Int64 | Nil
197
+player_slot   # Int8
198
+hero_id       # Int32
199
+```
200
+
201
+#### Dota::API::Match
202
+`Dota::API::MatchesList` has one member: `matches: Array(Dota::API::Match)`.
203
+
204
+```crystal
205
+match.id                      # Int64
206
+match.radiant_win             # Bool
207
+match.duration                # Int32, Length of the match, in seconds since the match began
208
+match.pre_game_duration       # Int32
209
+match.start_time              # Int32
210
+match.match_seq_num           # Int64
211
+match.tower_status_radiant    # Enum, Dota::API::MatchStatus::Towers
212
+match.tower_status_dire       # Enum, Dota::API::MatchStatus::Towers
213
+match.barracks_status_radiant # Enum, Dota::API::MatchStatus::Barracks
214
+match.barracks_status_dire    # Enum, Dota::API::MatchStatus::Barracks
215
+match.cluster                 # Int32
216
+match.first_blood_time        # Int32
217
+match.lobby_type              # Enum, Dota::API::MatchStatus::GameModes
218
+match.human_players           # Int8
219
+match.leagueid                # Int32
220
+match.positive_votes          # Int32
221
+match.negative_votes          # Int32
222
+match.game_mode               # Enum, Dota::API::MatchStatus::GameModes
223
+match.flags                   # Int32
224
+match.engine                  # Int32
225
+match.radiant_score           # Int32,
226
+match.dire_score              # Int32,
227
+match.radiant_team_id         # Int32 | Nil
228
+match.radiant_name            # String | Nil
229
+match.radiant_logo            # String | Nil
230
+match.radiant_team_complete   # Int32 | Nil
231
+match.dire_team_id            # Int32 | Nil
232
+match.dire_name               # String | Nil
233
+match.dire_team_complete      # Int32 | Nil
234
+match.radiant_captain         # Int32 | Nil
235
+match.dire_captain            # Int32 | Nil
236
+match.picks_bans              # Array(Dota::API::Match::Draft) | Nil, Picks and bans in the match, if the game mode is "Captains Mode"
237
+match.players                 # Array(Dota::API::Match::Player) | Nil
238
+
239
+# Dota::API::Match::Draft
240
+draft.order          # Integer, 1-20
241
+draft.pick?          # Boolean, true if the draft is a pick, and not a ban
242
+draft.team           # Enum, Dota::API::PlayerStatus::Teams
243
+draft.hero_id        # Int32
244
+
245
+# Dota::API::Match::Player
246
+player.account_id    # Int64
247
+player.player_slot   # Int8
248
+player.hero_id       # Int8
249
+player.kills         # Int16
250
+player.deaths        # Int16
251
+player.assists       # Int16
252
+player.leaver_status # Dota::API::PlayerStatus::Status
253
+player.last_hits     # Int16
254
+player.denies        # Int16
255
+player.gold_per_min  # Int16
256
+player.xp_per_min    # Int16
257
+player.item0_id      # Int16
258
+player.item1_id      # Int16
259
+player.item2_id      # Int16
260
+player.item3_id      # Int16
261
+player.item4_id      # Int16
262
+player.item5_id      # Int16
263
+```
264
+
265
+#### Live Matches
266
+`Dota::API::LiveMatchesList` has one member: `liveMatches: Array(Dota::API::Match)`.
267
+
268
+```crystal
269
+live_match.radiant          # Dota::API::LiveMatch::Side, Info about the team on the Radiant side
270
+live_match.dire             # Dota::API::LiveMatch::Side, Info about the team on the Dire side
271
+
272
+live_match.id               # Int64
273
+live_match.lobby_id         # Int64
274
+live_match.spectators       # Int32
275
+live_match.league_id        # Int32
276
+live_match.stream_delay     # Int32, Number of seconds the stream is behind actual game time
277
+live_match.series_type      # Int8, Best of X series
278
+live_match.league_tier      # Enum, Dota::API::League::Tiers
279
+live_match.duration         # Integer, Length of the match, in seconds since the match began
280
+live_match.roshan_timer     # Int16
281
+live_match.scoreboard       # Dota::API::LiveMatch::Scoreboard
282
+live_match.players          # Array(Dota::API::LiveMatch::SimplePlayer)
283
+live_match.dire_team        # Dota::API::LiveMatch::Team
284
+
285
+SimplePlayer
286
+sp.account_id               # Int64
287
+sp.name                     # String
288
+sp.hero_id                  # Int32
289
+sp.team                     # Enum, Dota::API::PlayerStatus::Teams
290
+
291
+Team
292
+t.name                      # String
293
+t.id                        # Int64
294
+t.logo                      # String
295
+t.complete                  # Bool
296
+
297
+Scoreboard
298
+sb.duration                 # Float32
299
+sb.roshan_respawn_timer     # Int16
300
+sb.radiant                  # Dota::API::LiveMatch::Side
301
+sb.dire                     # Dota::API::LiveMatch::Side
302
+```
303
+
304
+### Side (Currently only used by LiveMatch)
305
+```crystal
306
+side.score           # Int32
307
+side.tower_state     # Enum, Dota::API::MatchStatus::Towers
308
+side.barracks_state  # Enum, Dota::API::MatchStatus::Barracks
309
+side.picks           # Array(Pick) | Nil
310
+side.bans            # Array(Bans) | Nil
311
+side.players         # Array(LivePlayer)
312
+side.abilities       # Array(Ability) | Nil
313
+
314
+Pick
315
+pick.hero_id         # Int32
316
+
317
+Ban
318
+ban.hero_id          # Int32
319
+
320
+Ability
321
+ablity_id            # Int32
322
+ability_level        # Int8
323
+
324
+LivePlayer
325
+lp.account_id         # Int64
326
+lp.player_slot        # Int8
327
+lp.level              # Int8
328
+lp.kills              # Int16
329
+lp.deaths             # Int16
330
+lp.assists            # Int16
331
+lp.denies             # Int16
332
+lp.gold               # Int32
333
+lp.gold_per_min       # Int16
334
+lp.xp_per_min         # Int16
335
+lp.ultimate_state     # Int8
336
+lp.ultimate_cooldown  # Int32
337
+lp.respawn_timer      # Int32
338
+lp.position_x         # Float32
339
+lp.position_y         # Float32
340
+lp.net_worth          # Int32
341
+lp.item0_id           # Int16
342
+...
343
+lp.item5_id           # Int16
344
+```
345
+
346
+### Friends
347
+`Dota::API::FriendsList` has one member: `friends: Array(Dota::API::Friend)`.
348
+
349
+```crystal
350
+friend.steamid  # String
351
+friend.relationship    # String
352
+friend.friend_since    # Int32
353
+```
354
+
355
+## Resources
356
+
357
+- [vinnicc/dota](https://github.com/vinnicc/dota) The ruby version of this wrapper, and the inspiration behind it.
358
+- [Steam-Powered DOTA on Rails](http://www.sitepoint.com/steam-powered-dota-on-rails/) and [DOTA 2 on Rails: Digging Deeper](http://www.sitepoint.com/dota-2-rails-digging-deeper/) by Ilya Bodrov-Krukowski - A tutorial for getting personal match statistics that makes use of this library for Steam integration. (www.sitepoint.com)
359
+- [Things You Should Know Before Starting API Development](http://dev.dota2.com/showthread.php?t=58317) by MuppetMaster42 (dev.dota2.com)
360
+- [Dota 2 WebAPI Wiki](https://wiki.teamfortress.com/wiki/WebAPI#Dota_2) (wiki.teamfortress.com)
361
+- [Dota 2 WebAPI Forums](http://dev.dota2.com/forumdisplay.php?f=411) (dev.dota2.com)
89 362
 
90 363
 ## Contributing
91 364
 
92
-1. Fork it ( https://github.com/[your-github-name]/dota/fork )
365
+1. Fork it ( https://github.com/azah/dotacr/fork )
93 366
 2. Create your feature branch (git checkout -b my-new-feature)
94 367
 3. Commit your changes (git commit -am 'Add some feature')
95 368
 4. Push to the branch (git push origin my-new-feature)
@@ -97,4 +370,4 @@ TODO: Write development instructions here
97 370
 
98 371
 ## Contributors
99 372
 
100
-- [[your-github-name]](https://github.com/[your-github-name]) Andrew Zah - creator, maintainer
373
+- [azah](https://github.com/azah) Andrew Zah - creator, maintainer

+ 66
- 0
deploy.sh View File

@@ -0,0 +1,66 @@
1
+#!/bin/bash
2
+
3
+# Script adapted from https://gist.github.com/domenic/ec8b0fc8ab45f39403dd
4
+set -e # Exit with nonzero exit code if anything fails
5
+
6
+# Save some useful information
7
+REPO=`git config remote.origin.url`
8
+SSH_REPO=${REPO/https:\/\/github.com\//git@github.com:}
9
+SHA=`git rev-parse --verify HEAD`
10
+
11
+SOURCE_BRANCH="master"
12
+TARGET_BRANCH="gh-pages"
13
+
14
+function doCompile {
15
+  crystal doc
16
+}
17
+
18
+# Pull requests and commits to other branches shouldn't try to deploy, just build to verify
19
+if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then
20
+    echo "Skipping deploy; just doing a build."
21
+    doCompile
22
+    exit 0
23
+fi
24
+
25
+if [ -n "$TRAVIS_TAG" ]; then
26
+    SOURCE_BRANCH=$TRAVIS_TAG
27
+fi
28
+
29
+# Clone the existing gh-pages for this repo into out/
30
+# Create a new empty branch if gh-pages doesn't exist yet (should only happen on first deply)
31
+git clone -b $TARGET_BRANCH $REPO out
32
+
33
+mkdir -p out/doc/$SOURCE_BRANCH
34
+
35
+# Clean out existing contents
36
+rm -rf out/doc/$SOURCE_BRANCH/**/* || exit 0
37
+
38
+# Run our compile script
39
+doCompile
40
+
41
+# Move results
42
+mv doc/* out/doc/$SOURCE_BRANCH/
43
+
44
+# Now let's go have some fun with the cloned repo
45
+cd out
46
+
47
+git config user.name "Travis CI"
48
+git config user.email "$COMMIT_AUTHOR_EMAIL"
49
+
50
+# Commit the "changes", i.e. the new version.
51
+# The delta will show diffs between new and old versions.
52
+git add .
53
+git commit -m "Deploy to GitHub Pages: ${SHA}"
54
+
55
+# Get the deploy key by using Travis's stored variables to decrypt deploy_key.enc
56
+ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key"
57
+ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv"
58
+ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR}
59
+ENCRYPTED_IV=${!ENCRYPTED_IV_VAR}
60
+openssl aes-256-cbc -K $ENCRYPTED_KEY -iv $ENCRYPTED_IV -in deploy_key.enc -out deploy_key -d
61
+chmod 600 deploy_key
62
+eval `ssh-agent -s`
63
+ssh-add deploy_key
64
+
65
+# Now that we're all set up, we can push.
66
+git push $SSH_REPO $TARGET_BRANCH

BIN
deploy_key.enc View File


+ 2
- 2
spec/dota_spec.cr View File

@@ -13,9 +13,9 @@ describe Dota do
13 13
     Dota::Dota.configuration.api_key.should eq "xx"
14 14
   end
15 15
 
16
-  # set up api
16
+  # Set up API with Travis env vars
17 17
   Dota::Dota.configure do |config|
18
-    config.api_key = "xx"
18
+    config.api_key = ENV["api_key"]
19 19
   end
20 20
   api = Dota::Dota.api
21 21
 

+ 1
- 1
src/dota/api/client.cr View File

@@ -84,7 +84,7 @@ module Dota
84 84
 
85 85
       def live_matches(options = {} of String => Int32 | String)
86 86
         response = get("GetLiveLeagueGames", LiveMatchesList, "IDOTA2Match_570", options)
87
-        response.games if response.games.size > 0
87
+        response.liveMatches if response.liveMatches.size > 0
88 88
       end
89 89
 
90 90
       def cosmetic_rarities(options = {"language" => "en"})

+ 11
- 0
src/dota/api/converters.cr View File

@@ -0,0 +1,11 @@
1
+module Dota
2
+  module API
3
+    module Converters
4
+      module LogoConverter
5
+        def self.from_json(parser : JSON::PullParser) : String
6
+          parser.read_raw.to_s
7
+        end
8
+      end
9
+    end
10
+  end
11
+end

+ 4
- 4
src/dota/api/league.cr View File

@@ -17,15 +17,15 @@ module Dota
17 17
         itemdef: Int32
18 18
       )
19 19
 
20
+      def id
21
+        @leagueid
22
+      end
23
+
20 24
       enum Tiers
21 25
         Amateur      = 1
22 26
         Professional
23 27
         Premier
24 28
       end
25
-
26
-      def to_s
27
-        "League: #{@name}"
28
-      end
29 29
     end
30 30
   end
31 31
 end

+ 35
- 18
src/dota/api/live_match.cr View File

@@ -2,7 +2,7 @@ module Dota
2 2
   module API
3 3
     class LiveMatchesList
4 4
       JSON.mapping(
5
-        games: Array(LiveMatch)
5
+        liveMatches: {key: "games", type: Array(LiveMatch)}
6 6
       )
7 7
     end
8 8
 
@@ -18,16 +18,24 @@ module Dota
18 18
         stream_delay_s: Int32,
19 19
         radiant_series_wins: Int32,
20 20
         dire_series_wins: Int32,
21
-        series_type: Int32,
21
+        series_type: Int8,
22 22
         league_series_id: Int32,
23 23
         league_game_id: Int32,
24 24
         stage_name: String,
25
-        league_tier: Int32,
25
+        league_tier: League::Tiers,
26 26
         dire_team: {type: Team, nilable: true},
27 27
         radiant_team: {type: Team, nilable: true},
28 28
         scoreboard: {type: Scoreboard, nilable: true}
29 29
       )
30 30
 
31
+      def id
32
+        @match_id
33
+      end
34
+
35
+      def roshan_timer
36
+        @scoreboard["roshan_respawn_timer"]
37
+      end
38
+
31 39
       class SimplePlayer
32 40
         include Dota::API::PlayerStatus
33 41
         JSON.mapping(
@@ -39,10 +47,12 @@ module Dota
39 47
       end
40 48
 
41 49
       class Team
50
+        include Dota::API::Converters
51
+
42 52
         JSON.mapping(
43
-          team_name: String,
44
-          team_id: Int32,
45
-          team_logo: Int32,
53
+          name: {key: "team_name", type: String},
54
+          id: {key: "team_id", type: Int64},
55
+          logo: {key: "team_logo", type: String, converter: LogoConverter},
46 56
           complete: Bool
47 57
         )
48 58
       end
@@ -50,7 +60,7 @@ module Dota
50 60
       class Scoreboard
51 61
         JSON.mapping(
52 62
           duration: Float32,
53
-          roshan_respawn_timer: Int32,
63
+          roshan_respawn_timer: Int16,
54 64
           radiant: Side,
55 65
           dire: Side
56 66
         )
@@ -70,7 +80,7 @@ module Dota
70 80
         class Ability
71 81
           JSON.mapping(
72 82
             ability_id: Int32,
73
-            ability_level: Int32
83
+            ability_level: Int8
74 84
           )
75 85
         end
76 86
 
@@ -80,24 +90,24 @@ module Dota
80 90
           barracks_state: Barracks,
81 91
           picks: {type: Array(Pick), nilable: true},
82 92
           bans: {type: Array(Ban), nilable: true},
83
-          players: Array(ComplexPlayer),
93
+          players: Array(LivePlayer),
84 94
           abilities: {type: Array(Ability), nilable: true}
85 95
         )
86 96
       end
87 97
 
88
-      class ComplexPlayer
98
+      class LivePlayer
89 99
         JSON.mapping(
90
-          account_id: Int32,
100
+          account_id: Int64,
91 101
           player_slot: Int32,
92 102
           hero_id: Int32,
93
-          level: Int32,
94
-          kills: Int32,
95
-          death: Int32,
96
-          assists: Int32,
97
-          last_hits: Int32,
98
-          denies: Int32,
103
+          level: Int8,
104
+          kills: Int16,
105
+          deaths: {key: "death", type: Int16},
106
+          assists: Int16,
107
+          last_hits: Int16,
108
+          denies: Int16,
99 109
           gold: Int32,
100
-          gold_per_min: Int32,
110
+          gold_per_min: Int16,
101 111
           xp_per_min: Int32,
102 112
           ultimate_state: Int32,
103 113
           ultimate_cooldown: Int32,
@@ -112,6 +122,13 @@ module Dota
112 122
           item4_id: {type: Int16, key: "item4"},
113 123
           item5_id: {type: Int16, key: "item5"}
114 124
         )
125
+
126
+        def items
127
+          [
128
+            item0_id, item1_id, item2_id,
129
+            item3_id, item4_id, item5_id,
130
+          ].map { |id| Item.new(id.to_i32) }
131
+        end
115 132
       end
116 133
     end
117 134
   end

+ 6
- 7
src/dota/api/match.cr View File

@@ -3,12 +3,7 @@ module Dota
3 3
     class Match
4 4
       include Dota::API::MatchStatus
5 5
       include Dota::API::PlayerStatus
6
-
7
-      module LogoConverter
8
-        def self.from_json(parser : JSON::PullParser) : String
9
-          parser.read_raw.to_s
10
-        end
11
-      end
6
+      include Dota::API::Converters
12 7
 
13 8
       JSON.mapping(
14 9
         match_id: Int64,
@@ -47,12 +42,16 @@ module Dota
47 42
         players: {type: Array(Player), nilable: true}
48 43
       )
49 44
 
45
+      def id
46
+        @match_id
47
+      end
48
+
50 49
       class Draft
51 50
         JSON.mapping(
52 51
           is_pick: Bool,
53 52
           hero_id: Int32,
54 53
           team: Teams,
55
-          order: Int32
54
+          order: Int8
56 55
         )
57 56
       end
58 57
 

+ 1
- 1
src/dota/api/status/match_status.cr View File

@@ -81,4 +81,4 @@ module Dota
81 81
       end
82 82
     end
83 83
   end
84
-end
84
+end

+ 1
- 1
src/dota/api/status/player_status.cr View File

@@ -19,4 +19,4 @@ module Dota
19 19
       end
20 20
     end
21 21
   end
22
-end
22
+end

+ 20
- 10
src/dota/api/team.cr View File

@@ -8,25 +8,35 @@ module Dota
8 8
     end
9 9
 
10 10
     class Team
11
+      include Dota::API::Converters
12
+
11 13
       JSON.mapping(
12 14
         name: String,
13 15
         tag: String,
14 16
         time_created: Int32,
15 17
         calibration_games_remaining: Int8,
16
-        logo: Int64,
17
-        logo_sponsor: Int64,
18
+        logo: {type: String, converter: LogoConverter},
19
+        logo_sponsor: {type: String, converter: LogoConverter},
18 20
         country_code: String,
19 21
         url: String,
20 22
         games_played: Int16,
21
-        admin_account_id: Int32,
22
-        player_0_account_id: {type: Int32, nilable: true},
23
-        player_1_account_id: {type: Int32, nilable: true},
24
-        player_2_account_id: {type: Int32, nilable: true},
25
-        player_3_account_id: {type: Int32, nilable: true},
26
-        player_4_account_id: {type: Int32, nilable: true},
27
-        player_5_account_id: {type: Int32, nilable: true},
28
-        player_6_account_id: {type: Int32, nilable: true}
23
+        admin_id: {key: "admin_account_id", type: Int32},
24
+        player0_id: {key: "player_0_account_id", type: Int32, nilable: true},
25
+        player1_id: {key: "player_1_account_id", type: Int32, nilable: true},
26
+        player2_id: {key: "player_2_account_id", type: Int32, nilable: true},
27
+        player3_id: {key: "player_3_account_id", type: Int32, nilable: true},
28
+        player4_id: {key: "player_4_account_id", type: Int32, nilable: true},
29
+        player5_id: {key: "player_5_account_id", type: Int32, nilable: true},
30
+        player6_id: {key: "player_6_account_id", type: Int32, nilable: true},
29 31
       )
32
+
33
+      def player_ids
34
+        [
35
+          player_0_account_id, player_1_account_id, player_2_account_id,
36
+          player_3_account_id, player_4_account_id, player_5_account_id,
37
+          player_6_account_id,
38
+        ].compact_map &.itself
39
+      end
30 40
     end
31 41
   end
32 42
 end

+ 1
- 1
src/dota/configuration.cr View File

@@ -1,7 +1,7 @@
1 1
 module Dota
2 2
   class Configuration
3 3
     property api_key : String?
4
-    getter api_version : String
4
+    property api_version : String
5 5
 
6 6
     DEFAULT_API_VERSION = "v1"
7 7
     OPTIONS             = [API_KEY, API_VERSION]

+ 1
- 1
src/dota/utils/mapped.cr View File

@@ -17,4 +17,4 @@ module Dota
17 17
       end
18 18
     end
19 19
   end
20
-end
20
+end

Loading…
Cancel
Save