rubg 0.1.2 → 0.1.3
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 +44 -15
- data/lib/rubg.rb +3 -1
- data/lib/rubg/client.rb +29 -11
- data/lib/rubg/players.rb +10 -47
- data/lib/rubg/rubg_endpoint.rb +63 -0
- data/lib/rubg/status.rb +13 -7
- data/lib/rubg/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30c5fa847dde8f815c0bc0e5acef0586886a7eec299c6dd75f04b60878553616
|
4
|
+
data.tar.gz: 9228f84e1d438a246eb680057ef98646f4e31a3a8988c71fd2ffe9aad715ac2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de0897838c786655f77303ea177870f652423ce5c3ff24ca22becd74affe3de512f1cffc3aad28e9260d55b997de1a333b920274b3a75e2b1084a791b34ced4e
|
7
|
+
data.tar.gz: d0315f45b876e5a6aa5ebca73fc7ed130b55dc3d7b30a2ead9294f9404015afa88e7e1b697f2e62b20b0a0ae00ff7ea491867457731b4e359c5d428fa4643115
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,24 @@
|
|
1
1
|
# RUBG
|
2
2
|
|
3
|
-
RUBG is an unofficial Ruby
|
3
|
+
RUBG is an unofficial Ruby PUBG API wrapper.
|
4
4
|
|
5
|
-
It is also a project I am using to build my own
|
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
|
+
|
7
|
+
## Status
|
8
|
+
|
9
|
+
Development is very much in-progress.
|
10
|
+
|
11
|
+
#### Working:
|
12
|
+
- The /status endpoint is fully functional.
|
13
|
+
- The /players endpoint is partially functional. Queries may be performed, but the response is raw JSON only.
|
14
|
+
|
15
|
+
#### To-do
|
16
|
+
1. Finish /players endpoint, converting players to Player objects and matches to Match objects in response
|
17
|
+
2. Add /player endpoint to retrieve a single player
|
18
|
+
3. Add /matches endpoint to retrieve a single match, including objects for Rosters, etc.
|
19
|
+
4. Telemetry
|
20
|
+
|
21
|
+
At some point in there I need to get testing coverage up to date.
|
6
22
|
|
7
23
|
## Installation
|
8
24
|
|
@@ -22,40 +38,53 @@ Or install it yourself as:
|
|
22
38
|
|
23
39
|
## Usage
|
24
40
|
|
41
|
+
#### Create a Client
|
25
42
|
First, create a client and provide your API key:
|
26
43
|
```ruby
|
27
44
|
client = RUBG::Client.new("your-api-key-here")
|
28
45
|
```
|
29
46
|
|
30
|
-
If no key is added the gem will try and find it at ENV['PUBG_API_KEY'].
|
47
|
+
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'].
|
48
|
+
|
49
|
+
#### /status Endpoint
|
31
50
|
|
32
51
|
Check the PUBG API status and version:
|
33
52
|
|
34
53
|
```ruby
|
35
|
-
client.status.alive?
|
36
|
-
client.status.version
|
37
|
-
client.status.released_at
|
54
|
+
client.status.alive? # true/false
|
55
|
+
client.status.version # "v8.1.2"
|
56
|
+
client.status.released_at # "2018-04-01T18:00:20Z"
|
38
57
|
```
|
39
58
|
|
59
|
+
#### /players Endpoint
|
60
|
+
/players is currently only partially functional. Queries may be performed, but the response is JSON only. You can obtain match IDs to look up manually, however, until I implement /matches.
|
61
|
+
|
62
|
+
.players requires an 'options' argument, which should be a hash containing:
|
40
63
|
|
41
|
-
|
64
|
+
- "shard" - 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.
|
65
|
+
- "playerNames" - Comma-separated list of players to search for. Names are case-sensitive.
|
66
|
+
- "playerIds" - Comma-separated list of player IDs to search for.
|
67
|
+
|
68
|
+
Note: If neither playerIds nor playerNames are included in options no results will be returned - at least one name or Id must be present.
|
42
69
|
|
43
70
|
```ruby
|
44
|
-
options = {"shard" => "pc-na", "playerNames" => "Shroud"}
|
45
|
-
client.players(options)
|
71
|
+
options = {"shard" => "pc-na", "playerNames" => "Shroud,JoshOG,PlayerUnknown"}
|
72
|
+
players = client.players(options)
|
46
73
|
```
|
47
74
|
|
48
|
-
|
49
|
-
- "shard" - Specify the shard to retreieve data from. If none is specified pc-na will be used.
|
50
|
-
- "playerNames" - Comma-separated list of players to search for, case-sensitive
|
51
|
-
- "playerIds" - Comma-separated list of player IDs to search for.
|
75
|
+
The response will contain a top level object called 'errors' or 'data' depending on if the query failed or succeeded.
|
52
76
|
|
53
|
-
|
77
|
+
```ruby
|
78
|
+
players.errors . # [{"title"=>"Not Found", "detail"=>"No players found matching criteria"}]
|
79
|
+
```
|
54
80
|
|
81
|
+
```ruby
|
82
|
+
players.data # Returns retrieved player data.
|
83
|
+
```
|
55
84
|
|
56
85
|
## Contributing
|
57
86
|
|
58
|
-
Bug reports are welcome on GitHub at https://github.com/dor-edras/rubg.
|
87
|
+
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.
|
59
88
|
|
60
89
|
## License
|
61
90
|
|
data/lib/rubg.rb
CHANGED
data/lib/rubg/client.rb
CHANGED
@@ -4,25 +4,43 @@ 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
|
8
|
-
|
9
|
-
def initialize(api_key
|
7
|
+
attr_accessor :api_key, :content_type, :gzip
|
8
|
+
|
9
|
+
def initialize(api_key=ENV['PUBG_API_KEY'],gzip=false)
|
10
10
|
@api_key = api_key
|
11
11
|
@content_type = "application/vnd.api+json"
|
12
|
+
@gzip = gzip
|
12
13
|
end
|
13
14
|
|
15
|
+
|
14
16
|
def status
|
15
|
-
RUBG::Status.
|
17
|
+
RUBG::Status.fetch(self)
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def players(shard=$RUBG_DEFAULT_SHARD,query_options={})
|
22
|
+
RUBG::Players.fetch(self, shard, query_options)
|
16
23
|
end
|
17
24
|
|
25
|
+
|
26
|
+
def player
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def matches
|
18
32
|
|
19
|
-
# options variable is a hash of:
|
20
|
-
# "shard" - Specify the shard to retreieve data from. If none is specified pc-na will be used.
|
21
|
-
# "playerNames" - Comma-separated list of players to search for, case-sensitive
|
22
|
-
# "playerIds" - Comma-separated list of player IDs to search for.
|
23
|
-
# Note that if neither playerIds or playerNames is included no results will be returned.
|
24
|
-
def players(options)
|
25
|
-
RUBG::Players.new(self, options)
|
26
33
|
end
|
34
|
+
|
35
|
+
|
36
|
+
def match
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def telemetry
|
42
|
+
|
43
|
+
end
|
44
|
+
|
27
45
|
end
|
28
46
|
end
|
data/lib/rubg/players.rb
CHANGED
@@ -1,57 +1,20 @@
|
|
1
1
|
module RUBG
|
2
|
-
class Players
|
3
|
-
attr_reader :errors, :data, :raw_response, :uri, :headers, :query
|
2
|
+
class Players < RubgEndpoint
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
players = players_endpoint(client, options)
|
8
|
-
|
9
|
-
@errors = players["errors"]
|
10
|
-
@data = players["data"]
|
11
|
-
@raw_response = players
|
4
|
+
def initialize(client,response)
|
5
|
+
super
|
12
6
|
end
|
13
7
|
|
14
8
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@query = assemble_query(client,options)
|
21
|
-
else
|
22
|
-
@query = ""
|
23
|
-
end
|
24
|
-
|
25
|
-
response = client.class.get(@uri,{headers: @headers,
|
26
|
-
query: @query})
|
27
|
-
|
28
|
-
return response.parsed_response
|
29
|
-
end
|
30
|
-
|
9
|
+
def self.fetch(client,shard,query_options)
|
10
|
+
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)
|
31
14
|
|
32
|
-
|
33
|
-
|
34
|
-
uri = "/shards/#{shard}/players"
|
35
|
-
|
36
|
-
return uri
|
37
|
-
end
|
38
|
-
|
39
|
-
def assemble_headers(client)
|
40
|
-
headers = {
|
41
|
-
"Authorization" => client.api_key,
|
42
|
-
"Accept" => client.content_type
|
43
|
-
}
|
44
|
-
|
45
|
-
return headers
|
46
|
-
end
|
15
|
+
RUBG::Players.new(client,@response)
|
16
|
+
end
|
47
17
|
|
48
|
-
def assemble_query(client, options)
|
49
|
-
query = {}
|
50
|
-
query["filter[playerIds]"] = options["playerIds"].delete(' ') if options["playerIds"]
|
51
|
-
query["filter[playerNames]"] = options["playerNames"].delete(' ') if options["playerNames"]
|
52
|
-
query["page[limit]"] = 1
|
53
|
-
return query
|
54
|
-
end
|
55
18
|
end
|
56
19
|
end
|
57
20
|
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module RUBG
|
2
|
+
class RubgEndpoint
|
3
|
+
attr_reader :errors, :data, :response_ts, :ratelimit, :ratelimit_remaining, :raw_response
|
4
|
+
|
5
|
+
def initialize(client,response)
|
6
|
+
@errors = response["errors"]
|
7
|
+
@data = response["data"]
|
8
|
+
@response_ts = Time.parse(response.headers['date']) if response.headers['date']
|
9
|
+
@ratelimit = response.headers['x-ratelimit-limit']
|
10
|
+
@ratelimit_remaining = response.headers['x-ratelimit-remaining']
|
11
|
+
@raw_response = response
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def self.fetch(client,endpoint,shard={},query_options={})
|
16
|
+
@uri = assemble_uri(shard,endpoint)
|
17
|
+
@headers = assemble_headers(client)
|
18
|
+
@query = assemble_query(client,query_options)
|
19
|
+
|
20
|
+
@response = client.class.get(@uri,{headers: @headers,
|
21
|
+
query: @query})
|
22
|
+
|
23
|
+
return @response
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
private
|
29
|
+
def self.assemble_uri(shard,endpoint)
|
30
|
+
if endpoint == 'status'
|
31
|
+
uri = '/status'
|
32
|
+
else
|
33
|
+
uri = "/shards/#{shard}/#{endpoint}"
|
34
|
+
end
|
35
|
+
|
36
|
+
return uri
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def self.assemble_headers(client)
|
41
|
+
headers = { "Accept" => client.content_type }
|
42
|
+
|
43
|
+
headers["Authorization"] = client.api_key if client.api_key
|
44
|
+
headers["Accept-Encoding"] = "gzip" if client.gzip
|
45
|
+
|
46
|
+
return headers
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def self.assemble_query(client, query_options)
|
51
|
+
query_options.each do |key,value|
|
52
|
+
remove_spaces(value) if value
|
53
|
+
end
|
54
|
+
query = query_options
|
55
|
+
|
56
|
+
return query
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.remove_spaces(string)
|
60
|
+
string.gsub!(/((?<=,)\s+)|(\s+(?=,))/,"") if string
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/rubg/status.rb
CHANGED
@@ -1,14 +1,20 @@
|
|
1
1
|
module RUBG
|
2
|
-
class Status
|
2
|
+
class Status < RubgEndpoint
|
3
3
|
attr_reader :released_at, :version
|
4
4
|
|
5
|
-
def initialize(client)
|
6
|
-
response = client.class.get("/status")
|
7
|
-
status = response.parsed_response
|
8
|
-
|
5
|
+
def initialize(client,response)
|
9
6
|
@alive = ((response.response.class == Net::HTTPOK) ? true : false)
|
10
|
-
@released_at =
|
11
|
-
@version =
|
7
|
+
@released_at = Time.parse(response["data"]["attributes"]["releasedAt"])
|
8
|
+
@version = response["data"]["attributes"]["version"]
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def self.fetch(client)
|
14
|
+
endpoint = "status"
|
15
|
+
super(client,endpoint)
|
16
|
+
|
17
|
+
RUBG::Status.new(client, @response)
|
12
18
|
end
|
13
19
|
|
14
20
|
def alive?
|
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.1.
|
4
|
+
version: 0.1.3
|
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-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/rubg/matches.rb
|
103
103
|
- lib/rubg/player.rb
|
104
104
|
- lib/rubg/players.rb
|
105
|
+
- lib/rubg/rubg_endpoint.rb
|
105
106
|
- lib/rubg/status.rb
|
106
107
|
- lib/rubg/version.rb
|
107
108
|
- rubg.gemspec
|