rubg 0.1.3 → 0.1.4
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 +33 -18
- data/lib/rubg/client.rb +25 -10
- data/lib/rubg/player.rb +72 -5
- data/lib/rubg/players.rb +41 -9
- data/lib/rubg/rubg_endpoint.rb +59 -27
- data/lib/rubg/status.rb +23 -7
- data/lib/rubg/version.rb +1 -1
- data/lib/rubg.rb +3 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74e11b6f6090d28926b01b5370636d1974d96e3a8379371d7bdd3c6f0ab5adca
|
4
|
+
data.tar.gz: e5aee919fce9263f75d3fb5a8f18f98447787afabe1748eba55768cdf5628452
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0717ccdf1144e4cc74b764906ef08cf4a71e5031cc0523bf8e0cc9da7875ff7eb0cbd3635cad6557dc6269c5b512645ae10993e0efcd0a007a2660e36328c112
|
7
|
+
data.tar.gz: 10dcfbaa0242892d7c543cd73ab0ceebfb459b897dce7a4096f7bec2dc5a8af964d2b703afb3bb249eaa562ccbf65504bc0c4c2ab15339b9f2af595d2fe77d3c
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -6,20 +6,21 @@ It is also a side project I am using to build my own Ruby skills. As such, updat
|
|
6
6
|
|
7
7
|
## Status
|
8
8
|
|
9
|
-
Development is very much in-progress.
|
9
|
+
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
10
|
|
11
11
|
#### Working:
|
12
12
|
- The /status endpoint is fully functional.
|
13
|
-
- The /players endpoint is
|
13
|
+
- The /players endpoint is mostly functional. Queries may be performed, and player objects returned. Match data is ID strings only.
|
14
14
|
|
15
15
|
#### To-do
|
16
|
-
1. Finish /players endpoint,
|
17
|
-
2. Add /
|
18
|
-
3.
|
19
|
-
4. Telemetry
|
16
|
+
1. Finish /players endpoint, allowing conversion of matches to Match objects in response
|
17
|
+
2. Add /matches endpoint to retrieve a single match, including objects for Rosters, etc.
|
18
|
+
3. Telemetry
|
20
19
|
|
21
20
|
At some point in there I need to get testing coverage up to date.
|
22
21
|
|
22
|
+
*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
|
+
|
23
24
|
## Installation
|
24
25
|
|
25
26
|
Add this line to your application's Gemfile:
|
@@ -38,10 +39,12 @@ Or install it yourself as:
|
|
38
39
|
|
39
40
|
## Usage
|
40
41
|
|
42
|
+
Most methods take a hash as argument.
|
43
|
+
|
41
44
|
#### Create a Client
|
42
45
|
First, create a client and provide your API key:
|
43
46
|
```ruby
|
44
|
-
client = RUBG::Client.new("your-api-key-here")
|
47
|
+
client = RUBG::Client.new({:api_key =>"your-api-key-here"})
|
45
48
|
```
|
46
49
|
|
47
50
|
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'].
|
@@ -57,29 +60,41 @@ client.status.released_at # "2018-04-01T18:00:20Z"
|
|
57
60
|
```
|
58
61
|
|
59
62
|
#### /players Endpoint
|
60
|
-
/players is
|
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
|
+
|
65
|
+
.players takes two arguments: :shard and :query_params
|
61
66
|
|
62
|
-
|
67
|
+
:shard
|
68
|
+
- 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.
|
63
69
|
|
64
|
-
|
65
|
-
- "
|
66
|
-
- "
|
70
|
+
"query_params" - a hash containing any query options. For .players, the hash should contain *one* of the following options:
|
71
|
+
- "player_names" - Comma-separated list of players to search for. Names are case-sensitive.
|
72
|
+
- "player_ids" - Comma-separated list of player IDs to search for.
|
67
73
|
|
68
|
-
Note: If neither
|
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.
|
69
75
|
|
70
76
|
```ruby
|
71
|
-
|
72
|
-
players = client.players(
|
77
|
+
args = {:shard => "pc-na", :query_params => {:player_names => "shroud,JoshOG,PlayerUnknown"}}
|
78
|
+
players = client.players(args)
|
73
79
|
```
|
74
80
|
|
75
|
-
The response will contain a top level object called 'errors' or 'data' depending on if the query failed or succeeded.
|
81
|
+
The response will contain a top level object called 'errors' or 'data' and 'players', depending on if the query failed or succeeded.
|
76
82
|
|
77
83
|
```ruby
|
78
|
-
players.errors .
|
84
|
+
players.errors . # [{"title"=>"Not Found", "detail"=>"No players found matching criteria"}]
|
79
85
|
```
|
80
86
|
|
81
87
|
```ruby
|
82
|
-
players.data
|
88
|
+
players.data # Returns retrieved player data.
|
89
|
+
|
90
|
+
players.players.first.name #"shroud"
|
91
|
+
players.players.first.name #"account.d50fdc18fcad49c691d38466bed6f8fd"
|
92
|
+
players.players.first.match_ids #returns array of all match IDs for the player
|
93
|
+
|
94
|
+
players.response_ts # Time object containing date/time of response
|
95
|
+
players.ratelimit # Returns the max rate limit/min for your API key.
|
96
|
+
players.ratelimit_remaining # Returns the number of requests your API key has remaining before hitting the ratelimit.
|
97
|
+
|
83
98
|
```
|
84
99
|
|
85
100
|
## Contributing
|
data/lib/rubg/client.rb
CHANGED
@@ -6,25 +6,29 @@ module RUBG
|
|
6
6
|
base_uri 'https://api.playbattlegrounds.com'
|
7
7
|
attr_accessor :api_key, :content_type, :gzip
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
|
11
|
-
@
|
12
|
-
@
|
9
|
+
def initialize( args )
|
10
|
+
args = self.class.defaults.merge(args)
|
11
|
+
@api_key = args[:api_key]
|
12
|
+
@content_type = args[:content_type]
|
13
|
+
@gzip = args[:gzip]
|
13
14
|
end
|
14
15
|
|
15
16
|
|
16
|
-
def status
|
17
|
-
|
17
|
+
def status( args={} )
|
18
|
+
args = {:client => self }.merge(args)
|
19
|
+
RUBG::Status.fetch(args)
|
18
20
|
end
|
19
21
|
|
20
22
|
|
21
|
-
def players(
|
22
|
-
|
23
|
+
def players( args )
|
24
|
+
args = {:client => self }.merge(args)
|
25
|
+
RUBG::Players.fetch( args )
|
23
26
|
end
|
24
27
|
|
25
28
|
|
26
|
-
def player
|
27
|
-
|
29
|
+
def player( args )
|
30
|
+
args = {:client => self }.merge(args)
|
31
|
+
RUBG::Player.fetch( args )
|
28
32
|
end
|
29
33
|
|
30
34
|
|
@@ -42,5 +46,16 @@ module RUBG
|
|
42
46
|
|
43
47
|
end
|
44
48
|
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def self.defaults
|
53
|
+
{
|
54
|
+
:api_key => ENV['PUBG_API_KEY'],
|
55
|
+
:content_type => "application/vnd.api+json",
|
56
|
+
:gzip => false
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
45
60
|
end
|
46
61
|
end
|
data/lib/rubg/player.rb
CHANGED
@@ -1,8 +1,75 @@
|
|
1
|
-
module RUBG
|
2
|
-
class Player
|
1
|
+
module RUBG
|
2
|
+
class Player < RubgEndpoint
|
3
|
+
attr_reader :player_id, :name, :created, :updated, :patch_version, :shard_id, :stats,
|
4
|
+
:title_id, :assets, :match_ids, :link
|
5
|
+
|
6
|
+
attr_accessor :matches
|
7
|
+
|
8
|
+
def initialize( args )
|
9
|
+
args = self.class.defaults.merge(args)
|
10
|
+
super({
|
11
|
+
:response => args[:response]
|
12
|
+
})
|
13
|
+
if args[:response]["data"]
|
14
|
+
@player_id = args[:player_data]["id"]
|
15
|
+
@name = args[:player_data]["attributes"]["name"]
|
16
|
+
@created = args[:player_data]["attributes"]["createdAt"]
|
17
|
+
@updated = args[:player_data]["attributes"]["updatedAt"]
|
18
|
+
@patch_version = args[:player_data]["attributes"]["patchVersion"]
|
19
|
+
@shard_id = args[:player_data]["attributes"]["shardId"]
|
20
|
+
@stats = args[:player_data]["attributes"]["stats"]
|
21
|
+
@title_id = args[:player_data]["attributes"]["titleId"]
|
22
|
+
@assets = args[:player_data]["relationships"]["assets"]["data"]
|
23
|
+
@match_ids = match_id_array(args[:player_data]["relationships"]["matches"]["data"])
|
24
|
+
@matches = nil
|
25
|
+
@link = args[:player_data]["links"]["self"]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def self.fetch( args )
|
31
|
+
args = self.defaults.merge(args)
|
32
|
+
STDERR.puts args.inspect
|
33
|
+
endpoint = "player"
|
34
|
+
|
35
|
+
player_id = args[:query_params][:player_id]
|
36
|
+
args[:query_params].delete(:player_id)
|
37
|
+
|
38
|
+
super({
|
39
|
+
:client => args[:client],
|
40
|
+
:endpoint => endpoint,
|
41
|
+
:lookup_id => player_id,
|
42
|
+
:shard => args[:shard],
|
43
|
+
:query_params => args[:query_params]
|
44
|
+
})
|
45
|
+
|
46
|
+
player_data = @response["data"]
|
47
|
+
|
48
|
+
RUBG::Player.new({
|
49
|
+
:client => args[:client],
|
50
|
+
:response => @response,
|
51
|
+
:player_data => player_data
|
52
|
+
})
|
53
|
+
end
|
3
54
|
|
4
|
-
end
|
5
|
-
end
|
6
55
|
|
56
|
+
private
|
7
57
|
|
8
|
-
|
58
|
+
def match_id_array(data)
|
59
|
+
match_ids = []
|
60
|
+
|
61
|
+
data.each do |m|
|
62
|
+
id = m["id"]
|
63
|
+
match_ids << id
|
64
|
+
end
|
65
|
+
|
66
|
+
return match_ids
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def self.defaults
|
71
|
+
super
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
data/lib/rubg/players.rb
CHANGED
@@ -1,22 +1,54 @@
|
|
1
1
|
module RUBG
|
2
2
|
class Players < RubgEndpoint
|
3
|
+
attr_reader :players
|
4
|
+
|
5
|
+
def initialize( args )
|
6
|
+
args = self.class.defaults.merge(args)
|
3
7
|
|
4
|
-
def initialize(client,response)
|
5
8
|
super
|
9
|
+
|
10
|
+
@players = []
|
11
|
+
if args[:response]["data"]
|
12
|
+
args[:response]["data"].each do |player_data|
|
13
|
+
player = RUBG::Player.new({
|
14
|
+
:client => args[:client],
|
15
|
+
:response => args[:response],
|
16
|
+
:player_data => player_data
|
17
|
+
})
|
18
|
+
|
19
|
+
|
20
|
+
@players << player
|
21
|
+
end
|
22
|
+
end
|
6
23
|
end
|
7
24
|
|
8
25
|
|
9
|
-
def self.fetch(
|
26
|
+
def self.fetch( args )
|
27
|
+
args = self.defaults.merge(args)
|
28
|
+
|
10
29
|
endpoint = "players"
|
11
|
-
query_options["filter[playerNames]"] = query_options.delete("playerNames")
|
12
|
-
query_options["filter[playerIds]"] = query_options.delete("playerIds")
|
13
|
-
super(client,endpoint,shard,query_options)
|
14
30
|
|
15
|
-
|
31
|
+
args[:query_params]["filter[playerNames]"] = args[:query_params].delete(:player_names)
|
32
|
+
args[:query_params]["filter[playerIds]"] = args[:query_params].delete(:player_ids)
|
33
|
+
super({
|
34
|
+
:client => args[:client],
|
35
|
+
:endpoint => endpoint,
|
36
|
+
:shard => args[:shard],
|
37
|
+
:query_params => args[:query_params]
|
38
|
+
})
|
39
|
+
|
40
|
+
RUBG::Players.new({
|
41
|
+
:client => args[:client],
|
42
|
+
:response => @response
|
43
|
+
})
|
16
44
|
end
|
17
45
|
|
18
|
-
end
|
19
|
-
end
|
20
46
|
|
47
|
+
private
|
48
|
+
|
49
|
+
def self.defaults
|
50
|
+
super
|
51
|
+
end
|
21
52
|
|
22
|
-
|
53
|
+
end
|
54
|
+
end
|
data/lib/rubg/rubg_endpoint.rb
CHANGED
@@ -2,23 +2,37 @@ module RUBG
|
|
2
2
|
class RubgEndpoint
|
3
3
|
attr_reader :errors, :data, :response_ts, :ratelimit, :ratelimit_remaining, :raw_response
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
|
7
|
-
@
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@
|
5
|
+
def initialize( args )
|
6
|
+
args = self.class.defaults.merge(args)
|
7
|
+
@errors = args[:response]["errors"]
|
8
|
+
@data = args[:response]["data"]
|
9
|
+
@response_ts = Time.parse(args[:response].headers['date']) if args[:response].headers['date']
|
10
|
+
@ratelimit = args[:response].headers['x-ratelimit-limit']
|
11
|
+
@ratelimit_remaining = args[:response].headers['x-ratelimit-remaining']
|
12
|
+
@raw_response = args[:response]
|
12
13
|
end
|
13
14
|
|
14
15
|
|
15
|
-
def self.fetch(client,endpoint,shard={},
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
def self.fetch( args ) #client,endpoint,shard={},query_params={}
|
17
|
+
args = self.defaults.merge(args)
|
18
|
+
|
19
|
+
uri = assemble_uri({
|
20
|
+
:shard => args[:shard],
|
21
|
+
:endpoint => args[:endpoint],
|
22
|
+
:lookup_id => args[:lookup_id]
|
23
|
+
})
|
19
24
|
|
20
|
-
|
21
|
-
|
25
|
+
headers = assemble_headers({
|
26
|
+
:client => args[:client]
|
27
|
+
})
|
28
|
+
|
29
|
+
query = assemble_query({
|
30
|
+
:client => args[:client],
|
31
|
+
:query_params => args[:query_params]
|
32
|
+
})
|
33
|
+
|
34
|
+
@response = args[:client].class.get(uri,{headers: headers,
|
35
|
+
query: query})
|
22
36
|
|
23
37
|
return @response
|
24
38
|
end
|
@@ -26,38 +40,56 @@ module RUBG
|
|
26
40
|
|
27
41
|
|
28
42
|
private
|
29
|
-
|
30
|
-
|
43
|
+
|
44
|
+
def self.defaults
|
45
|
+
{
|
46
|
+
:shard => $RUBG_DEFAULT_SHARD,
|
47
|
+
:query_params => {},
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def self.assemble_uri( args )
|
53
|
+
args = self.defaults.merge(args)
|
54
|
+
|
55
|
+
if args[:endpoint] == 'status'
|
31
56
|
uri = '/status'
|
57
|
+
elsif args[:endpoint] == 'player'
|
58
|
+
uri = "/shards/#{args[:shard]}/players/#{args[:lookup_id]}"
|
32
59
|
else
|
33
|
-
uri = "/shards/#{shard}/#{endpoint}"
|
60
|
+
uri = "/shards/#{args[:shard]}/#{args[:endpoint]}"
|
34
61
|
end
|
35
|
-
|
36
62
|
return uri
|
37
63
|
end
|
38
64
|
|
39
65
|
|
40
|
-
def self.assemble_headers(client
|
41
|
-
|
66
|
+
def self.assemble_headers( args ) #client
|
67
|
+
args = self.defaults.merge(args)
|
68
|
+
|
69
|
+
headers = { "Accept" => args[:client].content_type }
|
42
70
|
|
43
|
-
headers["Authorization"] = client.api_key
|
44
|
-
headers["Accept-Encoding"] = "gzip"
|
71
|
+
headers["Authorization"] = args[:client].api_key if args[:client].api_key
|
72
|
+
headers["Accept-Encoding"] = "gzip" if args[:client].gzip
|
45
73
|
|
46
74
|
return headers
|
47
75
|
end
|
48
76
|
|
49
77
|
|
50
|
-
def self.assemble_query(client,
|
51
|
-
|
78
|
+
def self.assemble_query( args ) #client, query_params
|
79
|
+
args = self.defaults.merge(args)
|
80
|
+
|
81
|
+
args[:query_params].each do |key,value|
|
52
82
|
remove_spaces(value) if value
|
53
83
|
end
|
54
|
-
query =
|
84
|
+
query = args[:query_params]
|
55
85
|
|
56
86
|
return query
|
57
87
|
end
|
58
88
|
|
59
|
-
|
60
|
-
|
61
|
-
|
89
|
+
|
90
|
+
private
|
91
|
+
def self.remove_spaces(string)
|
92
|
+
string.gsub!(/((?<=,)\s+)|(\s+(?=,))/,"") if string
|
93
|
+
end
|
62
94
|
end
|
63
95
|
end
|
data/lib/rubg/status.rb
CHANGED
@@ -2,23 +2,39 @@ module RUBG
|
|
2
2
|
class Status < RubgEndpoint
|
3
3
|
attr_reader :released_at, :version
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
|
7
|
-
|
8
|
-
@
|
5
|
+
def initialize( args )
|
6
|
+
args = self.class.defaults.merge(args)
|
7
|
+
|
8
|
+
@alive = ((args[:response].response.class == Net::HTTPOK) ? true : false)
|
9
|
+
@released_at = Time.parse(args[:response]["data"]["attributes"]["releasedAt"])
|
10
|
+
@version = args[:response]["data"]["attributes"]["version"]
|
9
11
|
super
|
10
12
|
end
|
11
13
|
|
12
14
|
|
13
|
-
def self.fetch(
|
15
|
+
def self.fetch( args )
|
14
16
|
endpoint = "status"
|
15
|
-
super(
|
17
|
+
super({
|
18
|
+
:client => args[:client],
|
19
|
+
:endpoint => endpoint
|
20
|
+
})
|
16
21
|
|
17
|
-
RUBG::Status.new(
|
22
|
+
RUBG::Status.new({
|
23
|
+
:client => args[:client],
|
24
|
+
:response => @response
|
25
|
+
})
|
18
26
|
end
|
19
27
|
|
20
28
|
def alive?
|
21
29
|
@alive ? true : false
|
22
30
|
end
|
31
|
+
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def self.defaults
|
36
|
+
super
|
37
|
+
end
|
38
|
+
|
23
39
|
end
|
24
40
|
end
|
data/lib/rubg/version.rb
CHANGED
data/lib/rubg.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.1.
|
4
|
+
version: 0.1.4
|
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-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|