pubg-ruby 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: '09270cd3e31642d535e00bdeade6d59326e0770b'
4
+ data.tar.gz: 94e8c6f555f0f3232787811ca8d3b68bd942a134
5
+ SHA512:
6
+ metadata.gz: 818fafdcabc1037b97397b769be87bd71b2092b35e98d5b3fa865c1ddf6a29fe2a040956aae87c345d2f09c43c673c09b50d494b9474555b030ca0d31f393a28
7
+ data.tar.gz: 07bd16008f09ad566e2f8611b0095f063166e2a0e51b7315338e1501bdb71005438a89f0b1b79545e871e0da3058119bf138837e926b027adeb2f006e0b3f857
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.rspec_status
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in pubg-ruby.gemspec
6
+ gemspec
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pubg-ruby (0.1.0)
5
+ sawyer (~> 0.8)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.5.2)
11
+ public_suffix (>= 2.0.2, < 4.0)
12
+ coderay (1.1.2)
13
+ diff-lcs (1.3)
14
+ faraday (0.15.1)
15
+ multipart-post (>= 1.2, < 3)
16
+ method_source (0.9.0)
17
+ multipart-post (2.0.0)
18
+ pry (0.11.3)
19
+ coderay (~> 1.1.0)
20
+ method_source (~> 0.9.0)
21
+ public_suffix (3.0.2)
22
+ rake (10.5.0)
23
+ rspec (3.7.0)
24
+ rspec-core (~> 3.7.0)
25
+ rspec-expectations (~> 3.7.0)
26
+ rspec-mocks (~> 3.7.0)
27
+ rspec-core (3.7.1)
28
+ rspec-support (~> 3.7.0)
29
+ rspec-expectations (3.7.0)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.7.0)
32
+ rspec-mocks (3.7.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.7.0)
35
+ rspec-support (3.7.1)
36
+ sawyer (0.8.1)
37
+ addressable (>= 2.3.5, < 2.6)
38
+ faraday (~> 0.8, < 1.0)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ bundler (~> 1.16)
45
+ pry (~> 0.11)
46
+ pubg-ruby!
47
+ rake (~> 10.0)
48
+ rspec (~> 3.7)
49
+
50
+ BUNDLED WITH
51
+ 1.16.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Marcelo Alves
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.
@@ -0,0 +1,76 @@
1
+ # PUBG-Ruby
2
+
3
+ API wrapper for the official [PUBG API](https://developer.playbattlegrounds.com/)
4
+
5
+ _Currently in active development. Gem could be wildly unstable_
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'pubg-ruby'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install pubg-ruby
22
+
23
+ ## Getting Started
24
+
25
+ ### Setup
26
+
27
+ ```ruby
28
+ require 'pubg'
29
+
30
+ client = PUBG::Client.new(access_token: '123.456789', region: 'xbox-na')
31
+ ```
32
+
33
+ ### Usage
34
+
35
+ ```ruby
36
+ # Find Single Match
37
+ client.match('967f6581-31e2-4402-9661-8f020c68d87b')
38
+
39
+ # Find player by ID
40
+ client.player('account.6782798d64c64886a80dda0c4b22fc2a')
41
+
42
+ # Search players by name
43
+ client.players('user1,user2')
44
+
45
+ # Search players by ID
46
+ client.players('account.6782798d64c64886a80dda0c4b22fc2a,befd8e5b2f9d4b438ae83126bfd5de61')
47
+
48
+ # Match telemetry
49
+ client.telemetry('https://telemetry-cdn.playbattlegrounds.com/bluehole-pubg/xbox-na/2018/05/18/09/27/b6cb61e0-5a7d-11e8-a5e4-0a58647ff40d-telemetry.json')
50
+
51
+ # List seasons
52
+ client.seasons
53
+
54
+ # API status
55
+ client.status
56
+ ```
57
+
58
+ ## Development
59
+
60
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
61
+
62
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
63
+
64
+ ## Contributing
65
+
66
+ Bug reports and pull requests are welcome on GitHub at https://github.com/marceloalves/pubg-ruby.
67
+
68
+ Some areas that need improvement:
69
+
70
+ * Tests
71
+ * Clean up response json (camel_case keys, remove unnecessary info)
72
+ * Include [PUBG Assets](https://github.com/pubg/api-assets)
73
+
74
+ ## License
75
+
76
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ task :default => :spec
5
+ task :test => :spec
6
+
7
+ Bundler::GemHelper.install_tasks
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
9
+ t.rspec_opts = ['--color', '-f progress', '-r ./spec/spec_helper.rb']
10
+ t.pattern = 'spec/**/*_spec.rb'
11
+ t.fail_on_error = true
12
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'pubg'
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
+ require 'pry'
10
+ Pry.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,16 @@
1
+ require 'pubg/client'
2
+ require 'pubg/default'
3
+
4
+ # Ruby gem for the PUBG API
5
+ module PUBG
6
+ class << self
7
+ include PUBG::Configurable
8
+
9
+ def client
10
+ return @client if defined?(@client)
11
+ @client = PUBG::Client.new(options)
12
+ end
13
+ end
14
+ end
15
+
16
+ PUBG.reset!
@@ -0,0 +1,27 @@
1
+ require 'sawyer'
2
+ require 'pubg/connection'
3
+ require 'pubg/configurable'
4
+ require 'pubg/client/match'
5
+ require 'pubg/client/player'
6
+ require 'pubg/client/seasons'
7
+ require 'pubg/client/status'
8
+ require 'pubg/client/telemetry'
9
+
10
+ module PUBG
11
+ # Client for PUBG API
12
+ class Client
13
+ include PUBG::Configurable
14
+ include PUBG::Connection
15
+ include PUBG::Client::Match
16
+ include PUBG::Client::Player
17
+ include PUBG::Client::Seasons
18
+ include PUBG::Client::Status
19
+ include PUBG::Client::Telemetry
20
+
21
+ def initialize(options = {})
22
+ PUBG::Configurable.keys.each do |key|
23
+ instance_variable_set(:"@#{key}", options[key] || PUBG.instance_variable_get(:"@#{key}"))
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,19 @@
1
+ module PUBG
2
+ class Client
3
+ # Methods for Match API
4
+ #
5
+ # @see https://documentation.playbattlegrounds.com/en/matches-endpoint.html
6
+ module Match
7
+ # Find a single match by ID
8
+ #
9
+ # @param id [String] Match ID
10
+ # @example Find match
11
+ # client.match('967f6581-31e2-4402-9661-8f020c68d87b')
12
+ # @see https://documentation.playbattlegrounds.com/en/matches-endpoint.html
13
+ def match(id)
14
+ path = ['shards', @region, 'matches', id].join('/')
15
+ get(path)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,33 @@
1
+ module PUBG
2
+ class Client
3
+ # Methods for Player API
4
+ #
5
+ # @see https://documentation.playbattlegrounds.com/en/players-endpoint.html
6
+ module Player
7
+ # Find multiple players by name or ID
8
+ #
9
+ # @param items [String] Comma-separated player names or account IDs
10
+ # @example Find players
11
+ # client.players('user1,user2')
12
+ # client.players('account.6782798d64c64886a80dda0c4b22fc2a,befd8e5b2f9d4b438ae83126bfd5de61')
13
+ # @see https://documentation.playbattlegrounds.com/en/players-endpoint.html#/Players/get_players
14
+ def players(items)
15
+ filter_type = items.include?('account.') ? 'playerIds' : 'playerNames'
16
+ path = ['shards', @region, 'players'].join('/')
17
+ options = { query: { "filter[#{filter_type}]" => items } }
18
+ get(path, options)
19
+ end
20
+
21
+ # Find a single player by ID
22
+ #
23
+ # @param player_id [String] Player account ID
24
+ # @example Find player by ID
25
+ # client.player('account.6782798d64c64886a80dda0c4b22fc2a')
26
+ # @see https://documentation.playbattlegrounds.com/en/players-endpoint.html#/Players/get_players__id_
27
+ def player(player_id)
28
+ path = ['shards', @region, 'players', player_id].join('/')
29
+ get(path)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,16 @@
1
+ module PUBG
2
+ class Client
3
+ # Methods for Seasons API
4
+ module Seasons
5
+ # List all sessions for region
6
+ #
7
+ # @example List Seasons
8
+ # client.seasons
9
+ # @see https://documentation.playbattlegrounds.com/en/players-endpoint.html#/Seasons/get_seasons
10
+ def seasons
11
+ path = ['shards', @region, 'seasons'].join('/')
12
+ get(path)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ module PUBG
2
+ class Client
3
+ # Methods for Status API
4
+ #
5
+ # @see https://documentation.playbattlegrounds.com/en/status-endpoint.html
6
+ module Status
7
+ # Get the current API Status
8
+ #
9
+ # @example Get Status
10
+ # client.status
11
+ # @see https://documentation.playbattlegrounds.com/en/status-endpoint.html#/Status/get_status
12
+ def status
13
+ get('status')
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ module PUBG
2
+ class Client
3
+ # Methods for Telemetry API
4
+ #
5
+ # @see https://documentation.playbattlegrounds.com/en/telemetry.html
6
+ module Telemetry
7
+ # Fetch telemetry by URL
8
+ #
9
+ # @param url [String] Telemetry URL
10
+ # @example Fetch Telemetry
11
+ # client.telemetry('https://telemetry-cdn.playbattlegrounds.com/bluehole-pubg/xbox-na/2018/05/18/09/27/b6cb61e0-5a7d-11e8-a5e4-0a58647ff40d-telemetry.json')
12
+ # @see https://documentation.playbattlegrounds.com/en/telemetry.html#to-retrieve-telemetry-data
13
+ def telemetry(url)
14
+ Sawyer::Agent.call(:get, url).data
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ module PUBG
2
+ # Configuration options for {Client}
3
+ module Configurable
4
+ attr_accessor :access_token, :region
5
+ attr_reader :connection_options, :api_endpoint
6
+
7
+ class << self
8
+ def keys
9
+ @keys || %i[access_token region connection_options api_endpoint]
10
+ end
11
+ end
12
+
13
+ def configure
14
+ yield self
15
+ end
16
+
17
+ def reset!
18
+ PUBG::Configurable.keys.each do |key|
19
+ instance_variable_set(:"@#{key}", PUBG::Default.options[key])
20
+ end
21
+ self
22
+ end
23
+
24
+ private
25
+
26
+ def options
27
+ Hash[PUBG::Configurable.keys.map { |key| [key, instance_variable_get(:"@#{key}")] }]
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,29 @@
1
+ module PUBG
2
+ # Network layer
3
+ module Connection
4
+ def get(url, options = {})
5
+ request :get, url, options
6
+ end
7
+
8
+ def agent
9
+ @agent || Sawyer::Agent.new(api_endpoint, sawyer_options) do |http|
10
+ http.headers[:accept] = @connection_options[:headers][:accept]
11
+ http.authorization 'Bearer', @access_token
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def request(method, path, options = {})
18
+ @last_response = response = agent.call(method, Addressable::URI.parse(path.to_s), nil, options)
19
+ response.data
20
+ end
21
+
22
+ def sawyer_options
23
+ {
24
+ links_parser: Sawyer::LinkParsers::Simple.new,
25
+ faraday: Faraday.new(@connection_options)
26
+ }
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,39 @@
1
+ module PUBG
2
+ # DEfault configuration options for {Client}
3
+ module Default
4
+ # Default API Endpoint
5
+ API_ENDPOINT = 'https://api.playbattlegrounds.com'.freeze
6
+
7
+ # Default region
8
+ REGION = 'xbox-na'.freeze
9
+
10
+ # Default media type
11
+ DEFAULT_MEDIA_TYPE = 'application/vnd.api+json'.freeze
12
+
13
+ class << self
14
+ def options
15
+ Hash[PUBG::Configurable.keys.map { |key| [key, send(key)] }]
16
+ end
17
+
18
+ def api_endpoint
19
+ API_ENDPOINT
20
+ end
21
+
22
+ def access_token
23
+ ENV['PUBG_ACCESS_TOKEN']
24
+ end
25
+
26
+ def region
27
+ ENV['PUBG_REGION'] || REGION
28
+ end
29
+
30
+ def connection_options
31
+ {
32
+ headers: {
33
+ accept: DEFAULT_MEDIA_TYPE
34
+ }
35
+ }
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module PUBG
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,39 @@
1
+
2
+ lib = File.expand_path('lib', __dir__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pubg/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'pubg-ruby'
8
+ spec.version = PUBG::VERSION
9
+ spec.authors = ['Marcelo Alves']
10
+ spec.email = ['selfmadecelo@gmail.com']
11
+
12
+ spec.summary = 'Ruby wrapper of the PUBG API.'
13
+ spec.description = 'Ruby wrapper of the PUBG API.'
14
+ # spec.homepage = "TODO: Put your gem's website or public repo URL here."
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise 'RubyGems 2.0 or newer is required to protect against ' \
23
+ # 'public gem pushes.'
24
+ # end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_dependency 'sawyer', '~> 0.8'
34
+
35
+ spec.add_development_dependency 'bundler', '~> 1.16'
36
+ spec.add_development_dependency 'pry', '~> 0.11'
37
+ spec.add_development_dependency 'rake', '~> 10.0'
38
+ spec.add_development_dependency 'rspec', '~> 3.7'
39
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pubg-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marcelo Alves
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sawyer
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.7'
83
+ description: Ruby wrapper of the PUBG API.
84
+ email:
85
+ - selfmadecelo@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/pubg.rb
100
+ - lib/pubg/client.rb
101
+ - lib/pubg/client/match.rb
102
+ - lib/pubg/client/player.rb
103
+ - lib/pubg/client/seasons.rb
104
+ - lib/pubg/client/status.rb
105
+ - lib/pubg/client/telemetry.rb
106
+ - lib/pubg/configurable.rb
107
+ - lib/pubg/connection.rb
108
+ - lib/pubg/default.rb
109
+ - lib/pubg/version.rb
110
+ - pubg-ruby.gemspec
111
+ homepage:
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.6.11
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Ruby wrapper of the PUBG API.
135
+ test_files: []