rubg 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7eacf7a25a81f8c8b29ea2640cd5203a2a79c1c58aa324866232d15c8b01e3b
4
- data.tar.gz: dca5a0f63fb95340bc6a173d9752929e88f862d3764e95eb77df5d93f4b8a69f
3
+ metadata.gz: c40ff2c000d618a71fb0cba213d4fe44c3d7b9f958af6f219b3b52255590b970
4
+ data.tar.gz: d8b32768bb46d7e196e8dedabb25098316bf0bd0e44a9be9b46a23c5f440a3f4
5
5
  SHA512:
6
- metadata.gz: ddaf0f56aef66e343780fcd2a3578d7a225f99d03bf5ee381e010e22ea0fa8a5491549a3b0f23358e0ece986d0841eb4d843f419cf9cd646ea41289103e30f25
7
- data.tar.gz: 860f40ee986728f1fabc5125bf20edc3ffb3099746cd689cb755d3366556f6b5b892364c70c25b716e17c76d5b11f13837e0a8cb404e17c5bfca9afe6dbc620c
6
+ metadata.gz: 1cf1631cc78707beb6d8bf0c0375c39a4a737f2d06554de2ab22939bd96d6dcf4cd868d9c6f26248fe7f135b7bd703a80a77c410007bda74fd19eb7c868b05a3
7
+ data.tar.gz: 4ce9d3142a2d56b8c4dd49d5a683c37da1cc0fd1bf86b03832d7d9c3f8db24536b854ec434fa648a08fad49f4066abcf9c5da3140453b63f2723f8afed407bf7
data/Gemfile.lock CHANGED
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubg (0.2.1)
4
+ rubg (0.2.2)
5
5
  httparty (~> 0.16.2)
6
- json
6
+ json (~> 2.1.0)
7
+ zlib (~> 1.0.0)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
@@ -14,6 +15,7 @@ GEM
14
15
  minitest (5.11.3)
15
16
  multi_xml (0.6.0)
16
17
  rake (10.5.0)
18
+ zlib (1.0.0)
17
19
 
18
20
  PLATFORMS
19
21
  ruby
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  RUBG is an unofficial Ruby PUBG API wrapper.
4
4
 
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.
5
+ RUBG attempts to be fairly comprehensive and provide abstraction from the PUBG API while remaining consistent enough that the [offical PUBG API documentation](https://documentation.playbattlegrounds.com/en/introduction.html) is still useful.
6
6
 
7
7
 
8
8
 
@@ -16,9 +16,8 @@ Development is very much in-progress. Note that breaking changes with new releas
16
16
  - The /matches endpoint is fully funtional. Match, roster, and participant data and stats are available with getter methods.
17
17
 
18
18
  #### To-do
19
- 1. cross-object lookup convenience methods (ie. player.matches.fetch_latest or similar)
20
- 2. gzip support
21
- 3. Telemetry
19
+ 1. Telemetry
20
+ 2. cross-object lookup convenience methods (ie. player.matches.fetch_latest or similar)
22
21
 
23
22
  At some point in there I need to get testing coverage up to date.
24
23
 
@@ -51,6 +50,13 @@ Or install it yourself as:
51
50
  Most lookup methods take a hash as argument.
52
51
 
53
52
 
53
+ #### Base Class
54
+
55
+ ```ruby
56
+ RUBG.new # Convenience alias for RUBG::Client.new
57
+ RUBG.shards # Reference for available PUBG platform/region shards
58
+ ```
59
+
54
60
  #### Create a Client
55
61
  First, create a client and provide your API key:
56
62
  ```ruby
@@ -59,6 +65,8 @@ client = RUBG::Client.new({:api_key =>"your-api-key-here"})
59
65
 
60
66
  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'].
61
67
 
68
+ All responses are gzip that is parsed to json on receipt for faster transmission. At this timne this is not configurable, but should be transparent.
69
+
62
70
  The response will contain either a top level object called 'errors' if unsuccessful.
63
71
 
64
72
  ```ruby
@@ -187,7 +195,7 @@ match.player_count # Count of players in the match.
187
195
  match.roster_count # Count of teams in the match.
188
196
  match.names # List of names for all players in the match.
189
197
  match.survived # Collection of RUBG::Participant objects for players alive at the end.
190
- match.dbnos # Total non-lethal knockdowns. (down but not outs)
198
+ match.dbnos # Total non-lethal knockdowns. (down but not outs) Alias: .knocks
191
199
  match.assists # Total assists.
192
200
  match.boosts # Total boosts used.
193
201
  match.damage_dealt # Total damage dealt.
@@ -222,7 +230,7 @@ match.rosters[0].participants # Collection of RUBG::Participant
222
230
 
223
231
  match.rosters[0].names # List of names for all players on the roster.
224
232
  match.rosters[0].survived # Collection of RUBG::Participant objects roster members alive at the end.
225
- match.rosters[0].downed # Times roster members downed.
233
+ match.rosters[0].dbnos # Total non-lethal knockdowns. (down but not outs) Alias: .knocks
226
234
  match.rosters[0].assists # Total assists by roster.
227
235
  match.rosters[0].boosts # Total boosts used by roster.
228
236
  match.rosters[0].damage_dealt # Total damage dealt by roster.
@@ -252,7 +260,7 @@ Retrieved from .match and available in .participants or .rosters[].participants
252
260
  match.participants[0].participant_id # Unique participant ID
253
261
  match.participants[0].shard # Shard the match was played on
254
262
 
255
- match.participants[0].downed # Times participant downed.
263
+ match.participants[0].dbnos # Total non-lethal knockdowns. (down but not outs) Alias: .knocks
256
264
  match.participants[0].assists # Total assists by participant.
257
265
  match.participants[0].boosts # Total boosts used by participant.
258
266
  match.participants[0].damage_dealt # Total damage dealt by participant.
@@ -288,11 +296,14 @@ match.participants[0].overall_ranking_gained........# Overall ranking gained.
288
296
  ## Resources
289
297
  [Offical PUBG API Documentation](https://documentation.playbattlegrounds.com/en/introduction.html)
290
298
 
299
+ [Official PUBG API Developer Resources](https://github.com/pubg/api-assets)
300
+
291
301
  [Official PUBG API Discord](https://discord.gg/FcsT7t3)
292
302
 
293
303
  [Unofficial PUBG Developer Wiki](http://www.pubgwiki.org/Main_Page)
294
304
 
295
305
 
306
+
296
307
  ## Contributing
297
308
 
298
309
  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.
data/lib/rubg/client.rb CHANGED
@@ -4,7 +4,10 @@ module RUBG
4
4
  class Client
5
5
  include HTTParty
6
6
  base_uri 'https://api.playbattlegrounds.com'
7
- attr_accessor :api_key, :content_type, :gzip
7
+ format :json
8
+ parser RUBG::JsonGzipParser
9
+ attr_reader :gzip
10
+ attr_accessor :api_key, :content_type
8
11
 
9
12
  def initialize( args={} )
10
13
  args = self.class.defaults.merge(args)
@@ -54,7 +57,7 @@ module RUBG
54
57
  {
55
58
  :api_key => ENV['PUBG_API_KEY'],
56
59
  :content_type => "application/vnd.api+json",
57
- :gzip => false
60
+ :gzip => true
58
61
  }
59
62
  end
60
63
 
@@ -0,0 +1,8 @@
1
+ module RUBG
2
+ class JsonGzipParser < HTTParty::Parser
3
+ def json
4
+ resp = Zlib::GzipReader.new(StringIO.new(body)).read
5
+ JSON.parse(resp, :quirks_mode => true, :allow_nan => true)
6
+ end
7
+ end
8
+ end
data/lib/rubg/match.rb CHANGED
@@ -1,4 +1,4 @@
1
- module RUBG
1
+ module RUBG
2
2
  class Match < RubgEndpoint
3
3
  attr_reader :match_id, :created, :duration, :mode, :map, :patch_version, :shard, :stats,
4
4
  :tags, :title_id, :telemetry_id, :rounds, :spectators, :link, :telemetry_link,
@@ -9,6 +9,7 @@ module RUBG
9
9
 
10
10
  attr_accessor :rosters, :participants
11
11
  alias_method :winner, :winners
12
+ alias_method :knocks, :dbnos
12
13
 
13
14
  def initialize( args )
14
15
  args = self.class.defaults.merge(args)
@@ -1,4 +1,4 @@
1
- module RUBG
1
+ module RUBG
2
2
  class Participant
3
3
  attr_reader :participant_id, :actor, :shard, :dbnos, :assists, :boosts, :damage_dealt,
4
4
  :death_type, :headshot_kills, :heals, :kill_place, :kill_ranking_before, :kill_ranking_gained,
@@ -7,7 +7,7 @@ module RUBG
7
7
  :vehicle_destroys, :walk_distance, :weapons_acquired, :win_place, :win_ranking_before,
8
8
  :win_ranking_gained, :overall_ranking_gained, :stats
9
9
 
10
- alias_method :downed, :dbnos
10
+ alias_method :knocks, :dbnos
11
11
 
12
12
  def initialize( args )
13
13
 
data/lib/rubg/player.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module RUBG
2
2
  class Player < RubgEndpoint
3
- attr_reader :player_id, :name, :created, :updated, :patch_version, :shard_id, :stats,
3
+ attr_reader :player_id, :name, :created, :updated, :patch_version, :shard, :stats,
4
4
  :title_id, :assets, :match_ids, :link
5
5
 
6
6
  attr_accessor :matches
data/lib/rubg/roster.rb CHANGED
@@ -1,4 +1,4 @@
1
- module RUBG
1
+ module RUBG
2
2
  class Roster
3
3
  attr_reader :roster_id, :shard, :team_id, :team, :rank, :won, :participant_ids, :size,
4
4
  :names, :survived, :dbnos, :assists, :boosts, :damage_dealt, :damage_dealt_avg, :death_types, :headshot_kills,
@@ -7,7 +7,7 @@ module RUBG
7
7
 
8
8
  attr_accessor :participants
9
9
  alias_method :player_count, :size
10
- alias_method :downed, :dbnos
10
+ alias_method :knocks, :dbnos
11
11
 
12
12
  def initialize( args )
13
13
 
data/lib/rubg/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RUBG
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
data/lib/rubg.rb CHANGED
@@ -1,3 +1,7 @@
1
+ require 'httparty'
2
+ require 'zlib'
3
+
4
+ require "rubg/json_gzip_parser"
1
5
  require "rubg/version"
2
6
  require "rubg/client"
3
7
  require "rubg/rubg_endpoint"
@@ -13,4 +17,29 @@ require "rubg/status"
13
17
 
14
18
  module RUBG
15
19
  $RUBG_DEFAULT_SHARD = ENV['RUBG_DEFAULT_SHARD'] || "pc-na"
20
+
21
+ def self.new(args={})
22
+ RUBG::Client.new(args)
23
+ end
24
+
25
+ # This doesn't serve a huge purpose, but is a reminder of the currently defined shards as published by Bluehole.
26
+ # https://developer.playbattlegrounds.com/docs/en/making-requests.html#regions
27
+ # Updated: 3/14/2018 @ 1:57PM EST
28
+ def self.shards
29
+ {
30
+ "pc-na" => "PC - North Amaerica",
31
+ "pc-eu" => "PC - Europe",
32
+ "pc-krjp" => "PC - Korea/Japan",
33
+ "pc-oc" => "PC - Oceania",
34
+ "pc-kakao" => "PC - Kakao",
35
+ "pc-sea" => "PC - South East Asia",
36
+ "pc-sa" => "PC - South America",
37
+ "pc-as" => "PC - Asia",
38
+ "xbox-na" => "XBOX - North America",
39
+ "xbox-eu" => "XBOX - Europe",
40
+ "xbox-as" => "XBOX - Asia",
41
+ "xbox-oc" => "XBOX - Oceania"
42
+ }
43
+ end
44
+
16
45
  end
data/rubg.gemspec CHANGED
@@ -26,5 +26,6 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "minitest", "~> 5.0"
27
27
 
28
28
  spec.add_dependency "httparty", "~> 0.16.2"
29
- spec.add_dependency "json"
29
+ spec.add_dependency "json", "~> 2.1.0"
30
+ spec.add_dependency "zlib", "~> 1.0.0"
30
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dor
@@ -70,16 +70,30 @@ dependencies:
70
70
  name: json
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 2.1.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.1.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: zlib
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.0.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '0'
96
+ version: 1.0.0
83
97
  description: RUBG is a Ruby wrapper for the official PUBG API.
84
98
  email:
85
99
  - dor.edras@gmail.com
@@ -98,6 +112,7 @@ files:
98
112
  - bin/setup
99
113
  - lib/rubg.rb
100
114
  - lib/rubg/client.rb
115
+ - lib/rubg/json_gzip_parser.rb
101
116
  - lib/rubg/match.rb
102
117
  - lib/rubg/match_collection.rb
103
118
  - lib/rubg/participant.rb