rubg 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +210 -21
- data/lib/rubg.rb +6 -3
- data/lib/rubg/client.rb +4 -3
- data/lib/rubg/match.rb +162 -3
- data/lib/rubg/match_collection.rb +5 -0
- data/lib/rubg/participant.rb +59 -0
- data/lib/rubg/player.rb +2 -2
- data/lib/rubg/{players.rb → player_collection.rb} +2 -2
- data/lib/rubg/roster.rb +84 -0
- data/lib/rubg/rubg_endpoint.rb +4 -1
- data/lib/rubg/status.rb +1 -1
- data/lib/rubg/telemetry.rb +0 -0
- data/lib/rubg/version.rb +1 -1
- metadata +7 -4
- data/lib/rubg/matches.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a33d6af11b8d67d5a080754976bd05ff8ba813f38efb6db9a3381c92036bd930
|
4
|
+
data.tar.gz: d239858728b124cddd09b0a00457d84867b9fb243733243c531ddab3160c8948
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5631d4b842b7f788bddaeb5b80861b84049ca08041f97d17205855264fdc2106244a508a87ba9062a63b586b3c552726f28ba7d9a73d27f3bea002b812a3f87b
|
7
|
+
data.tar.gz: 749388d9a14e2caadf1669a263d5ae2e64c7152146b5c469e27a1ea5a889ce1dc36cf02db0c281012dde0364bbece6732077cfd562a497f5cb46acd09a0cc340
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -4,23 +4,28 @@ RUBG is an unofficial Ruby PUBG API wrapper.
|
|
4
4
|
|
5
5
|
It is also a side project I am using to build my own Ruby skills. As such, updates may be slow and this gem may not remain up to date with API changes. Please feel free to leave enhancement requests as issues, I may use that to help prioritize.
|
6
6
|
|
7
|
+
|
8
|
+
|
7
9
|
## Status
|
8
10
|
|
9
11
|
Development is very much in-progress. Note that breaking changes with new releases will be semi-frequent until initial development is complete (~1.0.0).
|
10
12
|
|
11
13
|
#### Working:
|
12
14
|
- The /status endpoint is fully functional.
|
13
|
-
- The /players endpoint is mostly functional. Queries may be performed, and player objects returned.
|
15
|
+
- The /players endpoint is mostly functional. Queries may be performed, and player objects returned.
|
16
|
+
- The /matches endpoint is fully funtional. Match, roster, and participant data and stats are available with getter methods.
|
14
17
|
|
15
18
|
#### To-do
|
16
|
-
1.
|
17
|
-
2.
|
19
|
+
1. cross-object lookup convenience methods (ie. player.matches.fetch_latest or similar)
|
20
|
+
2. gzip support
|
18
21
|
3. Telemetry
|
19
22
|
|
20
23
|
At some point in there I need to get testing coverage up to date.
|
21
24
|
|
22
25
|
*Note: xbox shards may not work correctly - only pc is currently tested. If you encounter issues pulling data from Xbox shards please log an issue and I will address.*
|
23
26
|
|
27
|
+
|
28
|
+
|
24
29
|
## Installation
|
25
30
|
|
26
31
|
Add this line to your application's Gemfile:
|
@@ -37,9 +42,14 @@ Or install it yourself as:
|
|
37
42
|
|
38
43
|
$ gem install rubg
|
39
44
|
|
45
|
+
|
46
|
+
|
40
47
|
## Usage
|
41
48
|
|
42
|
-
|
49
|
+
### API Lookups
|
50
|
+
|
51
|
+
Most lookup methods take a hash as argument.
|
52
|
+
|
43
53
|
|
44
54
|
#### Create a Client
|
45
55
|
First, create a client and provide your API key:
|
@@ -49,6 +59,13 @@ client = RUBG::Client.new({:api_key =>"your-api-key-here"})
|
|
49
59
|
|
50
60
|
The client object is used to make requests. If no key is added the gem will try and find it at ENV['PUBG_API_KEY'].
|
51
61
|
|
62
|
+
The response will contain either a top level object called 'errors' if unsuccessful.
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
response.errors # [{"title"=>"Not Found", "detail"=>"No players found matching criteria"}]
|
66
|
+
```
|
67
|
+
|
68
|
+
|
52
69
|
#### /status Endpoint
|
53
70
|
|
54
71
|
Check the PUBG API status and version:
|
@@ -59,49 +76,221 @@ client.status.version # "v8.1.2"
|
|
59
76
|
client.status.released_at # "2018-04-01T18:00:20Z"
|
60
77
|
```
|
61
78
|
|
79
|
+
|
62
80
|
#### /players Endpoint
|
63
|
-
/players is now mostly functional. Queries may be performed, and player objects returned. Match data is ID strings only, which you can use to look up manually until I implement /matches.
|
64
81
|
|
65
82
|
.players takes two arguments: :shard and :query_params
|
66
83
|
|
67
84
|
:shard
|
68
85
|
- Specify the [shard](https://documentation.playbattlegrounds.com/en/making-requests.html#regions) to retreieve data from. If none is specified, "pc-na" will be used as default.
|
69
86
|
|
70
|
-
|
71
|
-
-
|
72
|
-
-
|
87
|
+
:query_params - a hash containing any query options. For .players, the hash should contain *one* of the following options:
|
88
|
+
- :player_names - Comma-separated list of players to search for. Names are case-sensitive.
|
89
|
+
- :player_ids - Comma-separated list of player IDs to search for.
|
73
90
|
|
74
|
-
Note: If neither player_ids nor player_names are included in query_params no results will be returned - at least one name or Id must be present.
|
91
|
+
Note: If neither player_ids nor player_names are included in query_params no results will be returned - at least one name or Id must be present. The maximum in one request is currently 6.
|
75
92
|
|
76
93
|
```ruby
|
77
94
|
args = {:shard => "pc-na", :query_params => {:player_names => "shroud,JoshOG,PlayerUnknown"}}
|
78
|
-
|
95
|
+
response = client.players(args)
|
96
|
+
response.players # collection of player objects
|
97
|
+
|
98
|
+
response.response_ts # Time object containing date/time of response
|
99
|
+
response.ratelimit # Returns the max rate limit/min for your API key.
|
100
|
+
response.ratelimit_remaining # Returns the number of requests your API key has remaining before hitting the ratelimit.
|
101
|
+
```
|
102
|
+
|
103
|
+
|
104
|
+
#### /players/{:id} Endpoint
|
105
|
+
|
106
|
+
.player is similar to .players, but looks up only a single player by player_id only.
|
107
|
+
|
108
|
+
:shard
|
109
|
+
- Specify the [shard](https://documentation.playbattlegrounds.com/en/making-requests.html#regions) to retreieve data from. If none is specified, "pc-na" will be used as default.
|
110
|
+
|
111
|
+
:query_params - a hash containing any query options. For .player, the hash must contain:
|
112
|
+
- :player_id - Player ID to search for.
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
args = {:shard => "pc-na", :query_params => {:player_id => "shroud"}}
|
116
|
+
response = client.player(args)
|
117
|
+
|
118
|
+
response.response_ts # Time object containing date/time of response
|
119
|
+
response.ratelimit # Returns the max rate limit/min for your API key.
|
120
|
+
response.ratelimit_remaining # Returns the number of requests your API key has remaining before hitting the ratelimit.
|
121
|
+
```
|
122
|
+
|
123
|
+
|
124
|
+
#### /matches/{:id} Endpoint
|
125
|
+
|
126
|
+
.match looks up a single match by match_id only.
|
127
|
+
|
128
|
+
:shard
|
129
|
+
- Specify the [shard](https://documentation.playbattlegrounds.com/en/making-requests.html#regions) to retreieve data from. If none is specified, "pc-na" will be used as default.
|
130
|
+
|
131
|
+
:query_params - a hash containing any query options. For .match, the hash must contain:
|
132
|
+
- :match_id - Player ID to search for.
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
args = {:shard => "pc-na", :query_params => {:match_id => "match-id-here"}}
|
136
|
+
response = client.match(args)
|
137
|
+
|
138
|
+
response.response_ts # Time object containing date/time of response
|
139
|
+
response.ratelimit # Returns the max rate limit/min for your API key.
|
140
|
+
response.ratelimit_remaining # Returns the number of requests your API key has remaining before hitting the ratelimit.
|
141
|
+
|
79
142
|
```
|
80
143
|
|
81
|
-
|
144
|
+
|
145
|
+
|
146
|
+
### RUBG Objects
|
147
|
+
|
148
|
+
#### RUBG::Player
|
149
|
+
|
150
|
+
Retrieved from .players or .player.
|
82
151
|
|
83
152
|
```ruby
|
84
|
-
|
153
|
+
player.first.name #"shroud"
|
154
|
+
player.first.player_id #"account.d50fdc18fcad49c691d38466bed6f8fd"
|
155
|
+
player.first.match_ids # returns array of all match IDs for the player in the last 14 days
|
156
|
+
player.shard # Shard the player was retrieved from
|
157
|
+
player.stats # Not currently in use
|
85
158
|
```
|
86
159
|
|
160
|
+
|
161
|
+
#### RUBG::Match
|
162
|
+
|
163
|
+
Retrieved from .match.
|
164
|
+
|
87
165
|
```ruby
|
88
|
-
|
166
|
+
match.match_id # Unique match ID
|
167
|
+
match.created # Match creation time
|
168
|
+
match.duration # Match duration in seconds
|
169
|
+
match.mode # Match gamemode ("squad-fpp", "tequilafpp")
|
170
|
+
match.map # Miramar or Erangel
|
171
|
+
match.shard # Shard the match was played on
|
172
|
+
match.stats # Not currently in use
|
173
|
+
match.telemetry_id # ID for match telemetry file
|
174
|
+
match.telemetry_link # Link to match telemetry file
|
175
|
+
|
176
|
+
match.participants # Collection of RUBG::Participant objects for all participants in the match.
|
177
|
+
match.rosters # Collection of RUBG::Response objects for all rosters in the match.
|
178
|
+
match.winners # Retrieves the RUBG::Roster object for the winning team.
|
179
|
+
|
180
|
+
match.player_count # Count of players in the match.
|
181
|
+
match.roster_count # Count of teams in the match.
|
182
|
+
match.names # List of names for all players in the match.
|
183
|
+
match.survived # Collection of RUBG::Participant objects for players alive at the end.
|
184
|
+
match.dbnos # Total non-lethal knockdowns. (down but not outs)
|
185
|
+
match.assists # Total assists.
|
186
|
+
match.boosts # Total boosts used.
|
187
|
+
match.damage_dealt # Total damage dealt.
|
188
|
+
match.damage_dealt_avg # Avg damage dealt per player.
|
189
|
+
match.headshot_kills # Total headshot kills.
|
190
|
+
match.heals # Total heals used.
|
191
|
+
match.kills # Total kills by players.
|
192
|
+
match.ride_distance_avg # Avg distance traveled in vehicle per player.
|
193
|
+
match.revives # Total revives from downed state.
|
194
|
+
match.road_kills # Total road kills.
|
195
|
+
match.team_kills # Total team kills.
|
196
|
+
match.time_survived_avg # Avg time survived per player in seconds.
|
197
|
+
match.vehicle_destroys # Total vehicle destroys.
|
198
|
+
match.walk_distance_avg # Avg walk distance per player.
|
199
|
+
match.weapons_acquired # Total weapons acquired. Always 0 at present.
|
200
|
+
```
|
201
|
+
|
89
202
|
|
90
|
-
|
91
|
-
players.players.first.name #"account.d50fdc18fcad49c691d38466bed6f8fd"
|
92
|
-
players.players.first.match_ids #returns array of all match IDs for the player
|
203
|
+
#### RUBG::Roster
|
93
204
|
|
94
|
-
|
95
|
-
|
96
|
-
|
205
|
+
Retrieved from .match and available in .rosters method. Not available as an independent resource.
|
206
|
+
|
207
|
+
```ruby
|
208
|
+
match.rosters[0].roster_id # Unique roster ID
|
209
|
+
match.rosters[0].shard # Shard the match was played on
|
210
|
+
match.rosters[0].team_id # Randomly assigned integer identifying the roster during the match.
|
211
|
+
match.rosters[0].rank # Roster placement at end of match.
|
212
|
+
match.rosters[0].won # true/false
|
213
|
+
match.rosters[0].size # Count of participants in roster.
|
214
|
+
|
215
|
+
match.rosters[0].participants # Collection of RUBG::Participant objects for roster members.
|
216
|
+
|
217
|
+
match.rosters[0].names # List of names for all players on the roster.
|
218
|
+
match.rosters[0].survived # Collection of RUBG::Participant objects roster members alive at the end.
|
219
|
+
match.rosters[0].downed # Times roster members downed.
|
220
|
+
match.rosters[0].assists # Total assists by roster.
|
221
|
+
match.rosters[0].boosts # Total boosts used by roster.
|
222
|
+
match.rosters[0].damage_dealt # Total damage dealt by roster.
|
223
|
+
match.rosters[0].damage_dealt_avg # Avg damage dealt per player.
|
224
|
+
match.rosters[0].headshot_kills # Total headshot kills by roster.
|
225
|
+
match.rosters[0].heals # Total heals used by roster.
|
226
|
+
match.rosters[0].kills # Total kills by roster.
|
227
|
+
match.rosters[0].ride_distance # Total distance traveled in vehicle by roster.
|
228
|
+
match.rosters[0].ride_distance_avg # Avg distance traveled in vehicle per player.
|
229
|
+
match.rosters[0].revives # Total teammate revives from downed state by roster.
|
230
|
+
match.rosters[0].road_kills # Total road kills by roster.
|
231
|
+
match.rosters[0].team_kills # Total team kills by roster.
|
232
|
+
match.rosters[0].time_survived # Total time survived by roster in seconds.
|
233
|
+
match.rosters[0].time_survived_avg # Avg time survived per player in seconds.
|
234
|
+
match.rosters[0].vehicle_destroys # Total vehicle destroys by roster.
|
235
|
+
match.rosters[0].walk_distance # Total walk distance by roster.
|
236
|
+
match.rosters[0].walk_distance_avg # Avg walk distance by roster per player.
|
237
|
+
match.rosters[0].weapons_acquired # Total weapons acquired by roster. Always 0 at present.
|
238
|
+
```
|
239
|
+
|
240
|
+
|
241
|
+
#### RUBG::Participant
|
242
|
+
|
243
|
+
Retrieved from .match and available in .participants or .rosters[].participants methods. Not available as an independent resource. Match-specific stats for a player.
|
244
|
+
|
245
|
+
```ruby
|
246
|
+
match.participants[0].participant_id # Unique participant ID
|
247
|
+
match.participants[0].shard # Shard the match was played on
|
248
|
+
|
249
|
+
match.participants[0].downed # Times participant downed.
|
250
|
+
match.participants[0].assists # Total assists by participant.
|
251
|
+
match.participants[0].boosts # Total boosts used by participant.
|
252
|
+
match.participants[0].damage_dealt # Total damage dealt by participant.
|
253
|
+
match.participants[0].damage_dealt # Total damage dealt by participant.
|
254
|
+
match.participants[0].headshot_kills # Total headshot kills by participant.
|
255
|
+
match.participants[0].heals # Total heals used by participant.
|
256
|
+
match.participants[0].kill_placement # Kill placement vs other platers.
|
257
|
+
match.participants[0].kill_streaks # Total kill streaks by participant.
|
258
|
+
match.participants[0].kills # Total kills by participant.
|
259
|
+
match.participants[0].longest_kill # Distance of longest kill by player.
|
260
|
+
match.participants[0].most damage # Always seems to be 0, unknown.
|
261
|
+
match.participants[0].name # Participant name.
|
262
|
+
match.participants[0].player_id # Unique player ID for participant.
|
263
|
+
match.participants[0].revives # Total teammate revives from downed state by participant.
|
264
|
+
match.participants[0].ride_distance # Total distance traveled in vehicle by roster.
|
265
|
+
match.participants[0].road_kills # Total road kills by roster.
|
266
|
+
match.participants[0].team_kills # Total team kills by roster.
|
267
|
+
match.participants[0].time_survived # Total time survived by roster in seconds.
|
268
|
+
match.participants[0].vehicle_destroys # Total vehicle destroys by roster.
|
269
|
+
match.participants[0].walk_distance # Total walk distance by roster.
|
270
|
+
match.participants[0].weapons_acquired # Total weapons acquired by roster. Always 0 at present.
|
271
|
+
|
272
|
+
match.participants[0].kill_ranking_before...........# Kill ranking before match.
|
273
|
+
match.participants[0].kill_ranking_gained...........# Kill ranking gain or loss.
|
274
|
+
match.participants[0].win_ranking_before........... # Win ranking before match.
|
275
|
+
match.participants[0].win_ranking_gained........... # Win ranking gain or loss.
|
276
|
+
match.participants[0].overall_ranking_gained........# Overall ranking gained.
|
97
277
|
|
98
278
|
```
|
99
279
|
|
280
|
+
|
281
|
+
|
282
|
+
## Resources
|
283
|
+
[Offical PUBG API Documentation](https://documentation.playbattlegrounds.com/en/introduction.html)
|
284
|
+
|
285
|
+
[Official PUBG API Discord](https://discord.gg/FcsT7t3)
|
286
|
+
|
287
|
+
[Unofficial PUBG Developer Wiki](http://www.pubgwiki.org/Main_Page)
|
288
|
+
|
289
|
+
|
100
290
|
## Contributing
|
101
291
|
|
102
292
|
Bug reports are welcome on GitHub at https://github.com/dor-edras/rubg. Given that I am using this as a teaching tool for myself I will not be accepting contributions for the time being - this may change in future. That said, feel free to fork the repository and update it yourself as you'd like.
|
103
293
|
|
104
294
|
## License
|
105
295
|
|
106
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
107
|
-
|
296
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/rubg.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require "rubg/version"
|
2
2
|
require "rubg/client"
|
3
3
|
require "rubg/rubg_endpoint"
|
4
|
-
require "rubg/match"
|
5
|
-
require "rubg/matches"
|
6
4
|
require "rubg/player"
|
7
|
-
require "rubg/
|
5
|
+
require "rubg/player_collection"
|
6
|
+
require "rubg/match"
|
7
|
+
require "rubg/match_collection"
|
8
|
+
require "rubg/roster"
|
9
|
+
require "rubg/participant"
|
10
|
+
require "rubg/telemetry"
|
8
11
|
require "rubg/status"
|
9
12
|
|
10
13
|
|
data/lib/rubg/client.rb
CHANGED
@@ -22,7 +22,7 @@ module RUBG
|
|
22
22
|
|
23
23
|
def players( args )
|
24
24
|
args = {:client => self }.merge(args)
|
25
|
-
RUBG::
|
25
|
+
RUBG::PlayerCollection.fetch( args )
|
26
26
|
end
|
27
27
|
|
28
28
|
|
@@ -37,8 +37,9 @@ module RUBG
|
|
37
37
|
end
|
38
38
|
|
39
39
|
|
40
|
-
def match
|
41
|
-
|
40
|
+
def match ( args )
|
41
|
+
args = {:client => self }.merge(args)
|
42
|
+
RUBG::Match.fetch( args )
|
42
43
|
end
|
43
44
|
|
44
45
|
|
data/lib/rubg/match.rb
CHANGED
@@ -1,5 +1,164 @@
|
|
1
|
-
module RUBG
|
2
|
-
class Match
|
1
|
+
module RUBG
|
2
|
+
class Match < RubgEndpoint
|
3
|
+
attr_reader :match_id, :created, :duration, :mode, :map, :patch_version, :shard, :stats,
|
4
|
+
:tags, :title_id, :telemetry_id, :rounds, :spectators, :link, :telemetry_link,
|
5
|
+
:player_count, :roster_count, :winners, :names, :survived, :dbnos,
|
6
|
+
:assists, :boosts, :damage_dealt, :damage_dealt_avg, :death_types, :headshot_kills,
|
7
|
+
:heals, :kills, :ride_distance_avg, :revives, :road_kills, :team_kills,
|
8
|
+
:time_survived_avg, :vehicle_destroys, :walk_distance_avg, :weapons_acquired
|
9
|
+
|
10
|
+
attr_accessor :rosters, :participants
|
11
|
+
alias_method :winner, :winners
|
12
|
+
|
13
|
+
def initialize( args )
|
14
|
+
args = self.class.defaults.merge(args)
|
15
|
+
super({
|
16
|
+
:response => args[:response]
|
17
|
+
})
|
18
|
+
if args[:response]["data"]
|
19
|
+
@match_id = args[:match_data]["id"]
|
20
|
+
@created = args[:match_data]["attributes"]["createdAt"]
|
21
|
+
@duration = args[:match_data]["attributes"]["duration"]
|
22
|
+
@mode = args[:match_data]["attributes"]["gameMode"]
|
23
|
+
@map = convert_map_name(args[:match_data]["attributes"]["mapName"])
|
24
|
+
@patch_version = args[:match_data]["attributes"]["patchVersion"]
|
25
|
+
@shard = args[:match_data]["attributes"]["shardId"]
|
26
|
+
@stats = args[:match_data]["attributes"]["stats"]
|
27
|
+
@tags = args[:match_data]["attributes"]["tags"]
|
28
|
+
@title_id = args[:match_data]["attributes"]["titleId"]
|
29
|
+
@telemetry_id = args[:match_data]["relationships"]["assets"]["data"][0]["id"]
|
30
|
+
@rounds = args[:match_data]["relationships"]["rounds"]["data"]
|
31
|
+
@spectators = args[:match_data]["relationships"]["spectators"]["data"]
|
32
|
+
@link = args[:match_data]["links"]["self"]
|
33
|
+
@telemetry_link = args[:match_included].detect {|i| i["type"] == "asset" }["attributes"]["URL"]
|
34
|
+
|
35
|
+
@rosters = []
|
36
|
+
@participants = []
|
37
|
+
generate_roster_objects(args[:match_included])
|
38
|
+
|
39
|
+
|
40
|
+
@player_count = @participants.count
|
41
|
+
@roster_count = @rosters.count
|
42
|
+
@winners = @rosters.detect {|r| r.won}
|
43
|
+
|
44
|
+
|
45
|
+
#aggregates
|
46
|
+
@names = @participants.collect(&:name).sort!
|
47
|
+
@survived = @participants.select {|m| m.death_type == "alive"}
|
48
|
+
@dbnos = @participants.sum {|m| m.dbnos}
|
49
|
+
@assists = @participants.sum {|m| m.assists}
|
50
|
+
@boosts = @participants.sum {|m| m.boosts}
|
51
|
+
@damage_dealt = @participants.sum {|m| m.damage_dealt}
|
52
|
+
@damage_dealt_avg = ((participants.sum {|m| m.damage_dealt}).to_f/self.player_count.to_f).to_i
|
53
|
+
@headshot_kills = @participants.sum {|m| m.headshot_kills}
|
54
|
+
@heals = @participants.sum {|m| m.heals}
|
55
|
+
@kills = @participants.sum {|m| m.kills}
|
56
|
+
@ride_distance_avg = ((participants.sum {|m| m.ride_distance}).to_f/self.player_count.to_f).to_i
|
57
|
+
@revives = @participants.sum {|m| m.revives}
|
58
|
+
@road_kills = @participants.sum {|m| m.road_kills}
|
59
|
+
@team_kills = @participants.sum {|m| m.team_kills}
|
60
|
+
@time_survived_avg = ((participants.sum {|m| m.time_survived}).to_f/self.player_count.to_f).to_i
|
61
|
+
@vehicle_destroys = @participants.sum {|m| m.vehicle_destroys}
|
62
|
+
@walk_distance_avg = ((participants.sum {|m| m.walk_distance}).to_f/self.player_count.to_f).to_i
|
63
|
+
@weapons_acquired = @participants.sum {|m| m.weapons_acquired}
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
def self.fetch( args )
|
69
|
+
args = self.defaults.merge(args)
|
70
|
+
|
71
|
+
endpoint = "match"
|
72
|
+
|
73
|
+
match_id = args[:query_params][:match_id]
|
74
|
+
args[:query_params].delete(:match_id)
|
75
|
+
|
76
|
+
super({
|
77
|
+
:client => args[:client],
|
78
|
+
:endpoint => endpoint,
|
79
|
+
:lookup_id => match_id,
|
80
|
+
:shard => args[:shard],
|
81
|
+
:query_params => args[:query_params]
|
82
|
+
})
|
83
|
+
|
84
|
+
match_data = @response["data"]
|
85
|
+
match_included = @response["included"]
|
86
|
+
|
87
|
+
RUBG::Match.new({
|
88
|
+
:client => args[:client],
|
89
|
+
:response => @response,
|
90
|
+
:match_data => match_data,
|
91
|
+
:match_included => match_included
|
92
|
+
})
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def self.defaults
|
99
|
+
super
|
100
|
+
end
|
101
|
+
|
102
|
+
def convert_map_name (map_name)
|
103
|
+
if map_name == "Desert_Main"
|
104
|
+
"Miramar"
|
105
|
+
elsif map_name == "Erangel_Main"
|
106
|
+
"Erangel"
|
107
|
+
else
|
108
|
+
map_name
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
def participant_id_array(data)
|
114
|
+
participant_ids = []
|
115
|
+
data.map do |pt|
|
116
|
+
id = pt["id"]
|
117
|
+
participant_ids << id
|
118
|
+
end
|
119
|
+
return participant_ids
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
def generate_roster_objects (i)
|
124
|
+
rosters = i.select {|i| i["type"] == "roster"}
|
125
|
+
participants = i.select {|i| i["type"] == "participant"}
|
126
|
+
|
127
|
+
rosters.map do |roster|
|
128
|
+
roster_participants = find_roster_participants({
|
129
|
+
:roster => roster,
|
130
|
+
:participants => participants
|
131
|
+
})
|
132
|
+
|
133
|
+
|
134
|
+
roster_object = RUBG::Roster.new({
|
135
|
+
:roster_hash => roster,
|
136
|
+
:participant_array => roster_participants
|
137
|
+
})
|
138
|
+
@rosters << roster_object
|
139
|
+
@participants += roster_object.participants
|
140
|
+
end
|
141
|
+
|
142
|
+
@rosters.sort_by! {|r| r.rank}
|
143
|
+
@participants.sort_by! {|pt| pt.kill_place}
|
144
|
+
|
145
|
+
return @rosters, @participants
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
def find_roster_participants( args )
|
150
|
+
ids = participant_id_array(args[:roster]["relationships"]["participants"]["data"])
|
151
|
+
|
152
|
+
roster_participants = []
|
153
|
+
|
154
|
+
ids.map do |id|
|
155
|
+
|
156
|
+
participant_object = args[:participants].detect {|pt| pt["id"] == id}
|
157
|
+
roster_participants << participant_object
|
158
|
+
end
|
159
|
+
|
160
|
+
return roster_participants
|
161
|
+
end
|
3
162
|
|
4
163
|
end
|
5
|
-
end
|
164
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module RUBG
|
2
|
+
class Participant
|
3
|
+
attr_reader :participant_id, :actor, :shard, :dbnos, :assists, :boosts, :damage_dealt,
|
4
|
+
:death_type, :headshot_kills, :heals, :kill_place, :kill_ranking_before, :kill_ranking_gained,
|
5
|
+
:kill_streaks, :kills, :last_kill_points, :last_win_points, :longest_kill, :most_damage,
|
6
|
+
:name, :player_id, :revives, :ride_distance, :road_kills, :team_kills, :time_survived,
|
7
|
+
:vehicle_destroys, :walk_distance, :weapons_acquired, :win_place, :win_ranking_before,
|
8
|
+
:win_ranking_gained, :overall_ranking_gained, :stats
|
9
|
+
|
10
|
+
alias_method :downed, :dbnos
|
11
|
+
|
12
|
+
def initialize( args )
|
13
|
+
|
14
|
+
if args[:participant_hash]
|
15
|
+
@participant_id = args[:participant_hash]["id"]
|
16
|
+
@actor = args[:participant_hash]["attributes"]["actor"]
|
17
|
+
@shard = args[:participant_hash]["attributes"]["shardId"]
|
18
|
+
@dbnos = args[:participant_hash]["attributes"]["stats"]["DBNOs"]
|
19
|
+
@assists = args[:participant_hash]["attributes"]["stats"]["assists"]
|
20
|
+
@boosts = args[:participant_hash]["attributes"]["stats"]["boosts"]
|
21
|
+
@damage_dealt = args[:participant_hash]["attributes"]["stats"]["damageDealt"]
|
22
|
+
@death_type = args[:participant_hash]["attributes"]["stats"]["deathType"]
|
23
|
+
@headshot_kills = args[:participant_hash]["attributes"]["stats"]["headshotKills"]
|
24
|
+
@heals = args[:participant_hash]["attributes"]["stats"]["heals"]
|
25
|
+
@kill_place = args[:participant_hash]["attributes"]["stats"]["killPlace"]
|
26
|
+
@kill_ranking_before = args[:participant_hash]["attributes"]["stats"]["killPoints"]
|
27
|
+
@kill_ranking_gained = args[:participant_hash]["attributes"]["stats"]["killPointsDelta"].to_i
|
28
|
+
@kill_streaks = args[:participant_hash]["attributes"]["stats"]["killStreaks"]
|
29
|
+
@kills = args[:participant_hash]["attributes"]["stats"]["kills"]
|
30
|
+
@last_kill_points = args[:participant_hash]["attributes"]["stats"]["lastKillPoints"]
|
31
|
+
@last_win_points = args[:participant_hash]["attributes"]["stats"]["lastWinPoints"]
|
32
|
+
@longest_kill = args[:participant_hash]["attributes"]["stats"]["longestKill"]
|
33
|
+
@most_damage = args[:participant_hash]["attributes"]["stats"]["mostDamage"]
|
34
|
+
@name = args[:participant_hash]["attributes"]["stats"]["name"]
|
35
|
+
@player_id = args[:participant_hash]["attributes"]["stats"]["playerId"]
|
36
|
+
@revives = args[:participant_hash]["attributes"]["stats"]["revives"]
|
37
|
+
@ride_distance = args[:participant_hash]["attributes"]["stats"]["rideDistance"]
|
38
|
+
@road_kills = args[:participant_hash]["attributes"]["stats"]["roadKills"]
|
39
|
+
@team_kills = args[:participant_hash]["attributes"]["stats"]["teamKills"]
|
40
|
+
@time_survived = args[:participant_hash]["attributes"]["stats"]["timeSurvived"]
|
41
|
+
@vehicle_destroys = args[:participant_hash]["attributes"]["stats"]["vehicleDestroys"]
|
42
|
+
@walk_distance = args[:participant_hash]["attributes"]["stats"]["walkDistance"]
|
43
|
+
@weapons_acquired = args[:participant_hash]["attributes"]["stats"]["weaponsAcquired"]
|
44
|
+
@win_place = args[:participant_hash]["attributes"]["stats"]["winPlace"]
|
45
|
+
@win_ranking_before = args[:participant_hash]["attributes"]["stats"]["winPoints"]
|
46
|
+
@win_ranking_gained = args[:participant_hash]["attributes"]["stats"]["winPointsDelta"].to_i
|
47
|
+
@overall_ranking_gained = (
|
48
|
+
args[:participant_hash]["attributes"]["stats"]["winPointsDelta"] +
|
49
|
+
( args[:participant_hash]["attributes"]["stats"]["killPointsDelta"] * 0.2)
|
50
|
+
).to_i
|
51
|
+
@stats = args[:participant_hash]["attributes"]["stats"]
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
data/lib/rubg/player.rb
CHANGED
@@ -16,7 +16,7 @@ module RUBG
|
|
16
16
|
@created = args[:player_data]["attributes"]["createdAt"]
|
17
17
|
@updated = args[:player_data]["attributes"]["updatedAt"]
|
18
18
|
@patch_version = args[:player_data]["attributes"]["patchVersion"]
|
19
|
-
@
|
19
|
+
@shard = args[:player_data]["attributes"]["shardId"]
|
20
20
|
@stats = args[:player_data]["attributes"]["stats"]
|
21
21
|
@title_id = args[:player_data]["attributes"]["titleId"]
|
22
22
|
@assets = args[:player_data]["relationships"]["assets"]["data"]
|
@@ -29,7 +29,7 @@ module RUBG
|
|
29
29
|
|
30
30
|
def self.fetch( args )
|
31
31
|
args = self.defaults.merge(args)
|
32
|
-
|
32
|
+
|
33
33
|
endpoint = "player"
|
34
34
|
|
35
35
|
player_id = args[:query_params][:player_id]
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module RUBG
|
2
|
-
class
|
2
|
+
class PlayerCollection < RubgEndpoint
|
3
3
|
attr_reader :players
|
4
4
|
|
5
5
|
def initialize( args )
|
@@ -37,7 +37,7 @@ module RUBG
|
|
37
37
|
:query_params => args[:query_params]
|
38
38
|
})
|
39
39
|
|
40
|
-
RUBG::
|
40
|
+
RUBG::PlayerCollection.new({
|
41
41
|
:client => args[:client],
|
42
42
|
:response => @response
|
43
43
|
})
|
data/lib/rubg/roster.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
module RUBG
|
2
|
+
class Roster
|
3
|
+
attr_reader :roster_id, :shard, :team_id, :team, :rank, :won, :participant_ids, :size,
|
4
|
+
:names, :survived, :dbnos, :assists, :boosts, :damage_dealt, :damage_dealt_avg, :death_types, :headshot_kills,
|
5
|
+
:heals, :kills, :ride_distance, :ride_distance_avg, :revives, :road_kills, :team_kills, :time_survived,
|
6
|
+
:time_survived_avg, :vehicle_destroys, :walk_distance, :walk_distance_avg, :weapons_acquired
|
7
|
+
|
8
|
+
attr_accessor :participants
|
9
|
+
alias_method :player_count, :size
|
10
|
+
alias_method :downed, :dbnos
|
11
|
+
|
12
|
+
def initialize( args )
|
13
|
+
|
14
|
+
if args[:roster_hash]
|
15
|
+
@roster_id = args[:roster_hash]["id"]
|
16
|
+
@shard = args[:roster_hash]["attributes"]["shardId"]
|
17
|
+
@team_id = args[:roster_hash]["attributes"]["stats"]["teamId"]
|
18
|
+
@team = args[:roster_hash]["relationships"]["team"]["data"]
|
19
|
+
@rank = args[:roster_hash]["attributes"]["stats"]["rank"]
|
20
|
+
@won = args[:roster_hash]["attributes"]["won"] == "true" ? true : false
|
21
|
+
@participants = []
|
22
|
+
generate_participant_objects(args[:participant_array])
|
23
|
+
@size = @participants.count
|
24
|
+
|
25
|
+
#aggregate roster stats
|
26
|
+
@names = @participants.collect(&:name)
|
27
|
+
@survived = @participants.select {|m| m.death_type == "alive"}
|
28
|
+
@dbnos = @participants.sum {|m| m.dbnos}
|
29
|
+
@assists = @participants.sum {|m| m.assists}
|
30
|
+
@boosts = @participants.sum {|m| m.boosts}
|
31
|
+
@damage_dealt = @participants.sum {|m| m.damage_dealt}
|
32
|
+
@damage_dealt_avg = ((participants.sum {|m| m.damage_dealt}).to_f/self.size.to_f).to_i
|
33
|
+
@death_types = @participants.collect(&:death_type)
|
34
|
+
@headshot_kills = @participants.sum {|m| m.headshot_kills}
|
35
|
+
@heals = @participants.sum {|m| m.heals}
|
36
|
+
@kills = @participants.sum {|m| m.kills}
|
37
|
+
@ride_distance = @participants.sum {|m| m.ride_distance}
|
38
|
+
@ride_distance_avg = ((participants.sum {|m| m.ride_distance}).to_f/self.size.to_f).to_i
|
39
|
+
@revives = @participants.sum {|m| m.revives}
|
40
|
+
@road_kills = @participants.sum {|m| m.road_kills}
|
41
|
+
@team_kills = @participants.sum {|m| m.team_kills}
|
42
|
+
@time_survived = @participants.sum {|m| m.time_survived}
|
43
|
+
@time_survived_avg = ((participants.sum {|m| m.time_survived}).to_f/self.size.to_f).to_i
|
44
|
+
@vehicle_destroys = @participants.sum {|m| m.vehicle_destroys}
|
45
|
+
@walk_distance = @participants.sum {|m| m.walk_distance}
|
46
|
+
@walk_distance_avg = ((participants.sum {|m| m.walk_distance}).to_f/self.size.to_f).to_i
|
47
|
+
@weapons_acquired = @participants.sum {|m| m.weapons_acquired}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def won?
|
53
|
+
@won
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def participant_id_array(data)
|
59
|
+
participant_ids = []
|
60
|
+
|
61
|
+
data.each do |pt|
|
62
|
+
id = pt["id"]
|
63
|
+
participant_ids << id
|
64
|
+
end
|
65
|
+
|
66
|
+
return participant_ids
|
67
|
+
end
|
68
|
+
|
69
|
+
def generate_participant_objects(participants)
|
70
|
+
participants.map do |participant|
|
71
|
+
participant_object = RUBG::Participant.new({
|
72
|
+
:participant_hash => participant
|
73
|
+
})
|
74
|
+
|
75
|
+
@participants << participant_object
|
76
|
+
end
|
77
|
+
|
78
|
+
@participants.sort_by! {|pt| pt.name}
|
79
|
+
|
80
|
+
return @participants
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
data/lib/rubg/rubg_endpoint.rb
CHANGED
@@ -56,9 +56,12 @@ module RUBG
|
|
56
56
|
uri = '/status'
|
57
57
|
elsif args[:endpoint] == 'player'
|
58
58
|
uri = "/shards/#{args[:shard]}/players/#{args[:lookup_id]}"
|
59
|
+
elsif args[:endpoint] == 'match'
|
60
|
+
uri = "/shards/#{args[:shard]}/matches/#{args[:lookup_id]}"
|
59
61
|
else
|
60
62
|
uri = "/shards/#{args[:shard]}/#{args[:endpoint]}"
|
61
63
|
end
|
64
|
+
|
62
65
|
return uri
|
63
66
|
end
|
64
67
|
|
@@ -82,7 +85,7 @@ module RUBG
|
|
82
85
|
remove_spaces(value) if value
|
83
86
|
end
|
84
87
|
query = args[:query_params]
|
85
|
-
|
88
|
+
|
86
89
|
return query
|
87
90
|
end
|
88
91
|
|
data/lib/rubg/status.rb
CHANGED
File without changes
|
data/lib/rubg/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dor
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -99,11 +99,14 @@ files:
|
|
99
99
|
- lib/rubg.rb
|
100
100
|
- lib/rubg/client.rb
|
101
101
|
- lib/rubg/match.rb
|
102
|
-
- lib/rubg/
|
102
|
+
- lib/rubg/match_collection.rb
|
103
|
+
- lib/rubg/participant.rb
|
103
104
|
- lib/rubg/player.rb
|
104
|
-
- lib/rubg/
|
105
|
+
- lib/rubg/player_collection.rb
|
106
|
+
- lib/rubg/roster.rb
|
105
107
|
- lib/rubg/rubg_endpoint.rb
|
106
108
|
- lib/rubg/status.rb
|
109
|
+
- lib/rubg/telemetry.rb
|
107
110
|
- lib/rubg/version.rb
|
108
111
|
- rubg.gemspec
|
109
112
|
homepage: https://github.com/dor-edras/rubg
|