rubg 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +28 -0
- data/LICENSE.txt +21 -0
- data/README.md +63 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rubg.rb +8 -0
- data/lib/rubg/client.rb +28 -0
- data/lib/rubg/match.rb +5 -0
- data/lib/rubg/matches.rb +5 -0
- data/lib/rubg/player.rb +8 -0
- data/lib/rubg/players.rb +59 -0
- data/lib/rubg/status.rb +18 -0
- data/lib/rubg/version.rb +3 -0
- data/rubg.gemspec +30 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1f4594ad2750bbc41e12d65aa2d1ec87313b71d601943b873d62db470cb6ca22
|
4
|
+
data.tar.gz: de64980fede3b8c830f9cfb3bcbe33f8cedf10818878cd63fd861c661891759e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 007f7825e3a4371be7d9b23fa98c5212d3c97a80dc0a648e81b4d8057d27ce20d66c672017d9006937b071987b2884f8f8724cf41c5b80e69a77b13366960317
|
7
|
+
data.tar.gz: fdcf55449a44f0ec321b40ff9274f42ebbcfc769770568da6827dca05a9dbd0d98ce0044f4f860b72cb8ad1f5696b799b07f34fc30140135ac3b7186f35fab52
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rubg (0.1.2)
|
5
|
+
httparty (~> 0.16.2)
|
6
|
+
json
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
httparty (0.16.2)
|
12
|
+
multi_xml (>= 0.5.2)
|
13
|
+
json (2.1.0)
|
14
|
+
minitest (5.11.3)
|
15
|
+
multi_xml (0.6.0)
|
16
|
+
rake (10.5.0)
|
17
|
+
|
18
|
+
PLATFORMS
|
19
|
+
ruby
|
20
|
+
|
21
|
+
DEPENDENCIES
|
22
|
+
bundler (~> 1.16)
|
23
|
+
minitest (~> 5.0)
|
24
|
+
rake (~> 10.0)
|
25
|
+
rubg!
|
26
|
+
|
27
|
+
BUNDLED WITH
|
28
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Dor
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# RUBG
|
2
|
+
|
3
|
+
RUBG is an unofficial Ruby pUBG API wrapper.
|
4
|
+
|
5
|
+
It is also a project I am using to build my own development skills. As such, it is likely this gem will not remain up to date with API changes, and updates will be slow. Given that I am using this as a teaching tool for myself I will not be accepting contributions. That said, feel free to use the gem as-is in your own application if it is useful, or to fork the repository and update it yourself as you'd like.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rubg'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rubg
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
First, create a client and provide your API key:
|
26
|
+
```ruby
|
27
|
+
client = RUBG::Client.new("your-api-key-here")
|
28
|
+
```
|
29
|
+
|
30
|
+
If no key is added the gem will try and find it at ENV['PUBG_API_KEY'].
|
31
|
+
|
32
|
+
Check the PUBG API status and version:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
client.status.alive?
|
36
|
+
client.status.version
|
37
|
+
client.status.released_at
|
38
|
+
```
|
39
|
+
|
40
|
+
|
41
|
+
Only the players endpoint is functional at present, and it is only partially functional:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
options = {"shard" => "pc-na", "playerNames" => "Shroud"}
|
45
|
+
client.players(options)
|
46
|
+
```
|
47
|
+
|
48
|
+
options variable should be a hash of:
|
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.
|
52
|
+
|
53
|
+
Note that if neither playerIds or playerNames are included no results will be returned.
|
54
|
+
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
Bug reports are welcome on GitHub at https://github.com/dor-edras/rubg. As mentioned above, I am not accepting contributions to this project but you are welcome to fork it!
|
59
|
+
|
60
|
+
## License
|
61
|
+
|
62
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
63
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rubg"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/rubg.rb
ADDED
data/lib/rubg/client.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module RUBG
|
4
|
+
class Client
|
5
|
+
include HTTParty
|
6
|
+
base_uri 'https://api.playbattlegrounds.com'
|
7
|
+
attr_accessor :api_key, :content_type
|
8
|
+
|
9
|
+
def initialize(api_key = ENV['PUBG_API_KEY'])
|
10
|
+
@api_key = api_key
|
11
|
+
@content_type = "application/vnd.api+json"
|
12
|
+
end
|
13
|
+
|
14
|
+
def status
|
15
|
+
RUBG::Status.new(self)
|
16
|
+
end
|
17
|
+
|
18
|
+
|
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
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/rubg/matches.rb
ADDED
data/lib/rubg/player.rb
ADDED
data/lib/rubg/players.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
module RUBG
|
2
|
+
class Players
|
3
|
+
attr_reader :errors, :data, :raw_response, :uri, :headers, :query
|
4
|
+
|
5
|
+
|
6
|
+
def initialize(client, options)
|
7
|
+
players = players_endpoint(client, options)
|
8
|
+
|
9
|
+
@errors = players["errors"]
|
10
|
+
@data = players["data"]
|
11
|
+
@raw_response = players
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
private
|
16
|
+
def players_endpoint(client, options)
|
17
|
+
@uri = assemble_uri(options)
|
18
|
+
@headers = assemble_headers(client)
|
19
|
+
if options["playerIds"] || options["playerNames"]
|
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
|
+
|
31
|
+
|
32
|
+
def assemble_uri(options)
|
33
|
+
shard = options["shard"] || "pc-na"
|
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
|
47
|
+
|
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
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
# response["data"][0]["relationships"]["matches"]["data"][0]["id"]
|
data/lib/rubg/status.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module RUBG
|
2
|
+
class Status
|
3
|
+
attr_reader :released_at, :version
|
4
|
+
|
5
|
+
def initialize(client)
|
6
|
+
response = client.class.get("/status")
|
7
|
+
status = response.parsed_response
|
8
|
+
|
9
|
+
@alive = ((response.response.class == Net::HTTPOK) ? true : false)
|
10
|
+
@released_at = status["data"]["attributes"]["releasedAt"]
|
11
|
+
@version = status["data"]["attributes"]["version"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def alive?
|
15
|
+
@alive ? true : false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/rubg/version.rb
ADDED
data/rubg.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "rubg/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rubg"
|
8
|
+
spec.version = RUBG::VERSION
|
9
|
+
spec.authors = ["Dor"]
|
10
|
+
spec.email = ["dor.edras@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Unofficial PUBG API wrapper gem for Ruby.}
|
13
|
+
spec.description = %q{Unofficial PUBG API wrapper gem for Ruby.}
|
14
|
+
spec.homepage = "https://github.com/dor-edras/rubg"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
27
|
+
|
28
|
+
spec.add_dependency "httparty", "~> 0.16.2"
|
29
|
+
spec.add_dependency "json"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dor
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: httparty
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.16.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.16.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: json
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Unofficial PUBG API wrapper gem for Ruby.
|
84
|
+
email:
|
85
|
+
- dor.edras@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- Gemfile
|
93
|
+
- Gemfile.lock
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- lib/rubg.rb
|
100
|
+
- lib/rubg/client.rb
|
101
|
+
- lib/rubg/match.rb
|
102
|
+
- lib/rubg/matches.rb
|
103
|
+
- lib/rubg/player.rb
|
104
|
+
- lib/rubg/players.rb
|
105
|
+
- lib/rubg/status.rb
|
106
|
+
- lib/rubg/version.rb
|
107
|
+
- rubg.gemspec
|
108
|
+
homepage: https://github.com/dor-edras/rubg
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.7.6
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: Unofficial PUBG API wrapper gem for Ruby.
|
132
|
+
test_files: []
|