vainglory-api 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/vainglory_api.rb +110 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: df230271ab484d16bf6be0704412c6c738adbc50
|
4
|
+
data.tar.gz: 4e8f5f358709b76ceb99f394cd0d5d1d40a8dad9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 98837caf5b1f58a0ec473f87585b972863048079ae6ffb00e7d83ac7dd937b37ae297ff4d8004c194fe73e7b9e6e160170f75261b2be8cc5898c2229d8f9e294
|
7
|
+
data.tar.gz: 3dfcf7e3aa98c1f9392c9900de72d10ee704c76d1c2564c7e7042013217a0f407406f166d7a50d00c689c415af6b0125397415a46a29528952fde455e3a9e205
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'ostruct'
|
3
|
+
require 'openssl'
|
4
|
+
require 'net/http'
|
5
|
+
|
6
|
+
class VaingloryAPI
|
7
|
+
BASE_URL = "https://api.dc01.gamelockerapp.com"
|
8
|
+
|
9
|
+
def initialize(api_key, region = "na")
|
10
|
+
@api_key = api_key
|
11
|
+
@region = region
|
12
|
+
end
|
13
|
+
|
14
|
+
def samples(filter_params = {})
|
15
|
+
get_request(endpoint_uri("shards/#{@region}/samples", filter_params))
|
16
|
+
end
|
17
|
+
|
18
|
+
def matches(filter_params = {})
|
19
|
+
get_request(endpoint_uri("shards/#{@region}/matches", filter_params))
|
20
|
+
end
|
21
|
+
|
22
|
+
def match(match_id)
|
23
|
+
get_request(endpoint_uri("shards/#{@region}/matches/#{match_id}"))
|
24
|
+
end
|
25
|
+
|
26
|
+
def players(*names)
|
27
|
+
filter_params = {"filter[playerNames]" => names.join(',')}
|
28
|
+
get_request(endpoint_uri("shards/#{@region}/players", filter_params))
|
29
|
+
end
|
30
|
+
|
31
|
+
def player(player_id)
|
32
|
+
get_request(endpoint_uri("shards/#{@region}/players/#{player_id}"))
|
33
|
+
end
|
34
|
+
|
35
|
+
def telemetry(url)
|
36
|
+
get_request(URI(url), true, false)
|
37
|
+
end
|
38
|
+
|
39
|
+
def teams(filter_params = {})
|
40
|
+
raise(NotImplementedError, "Coming soon!")
|
41
|
+
end
|
42
|
+
|
43
|
+
def team(team_id)
|
44
|
+
raise(NotImplementedError, "Coming soon!")
|
45
|
+
end
|
46
|
+
|
47
|
+
def link(link_id)
|
48
|
+
raise(NotImplementedError, "Coming soon!")
|
49
|
+
end
|
50
|
+
|
51
|
+
def status
|
52
|
+
get_request_without_headers(endpoint_uri('status'))
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def get_request_without_headers(uri)
|
58
|
+
get_request(uri, false)
|
59
|
+
end
|
60
|
+
|
61
|
+
def get_request(uri, with_headers = true, with_auth = true)
|
62
|
+
req = Net::HTTP::Get.new(uri)
|
63
|
+
req = apply_headers(req, with_auth) if with_headers
|
64
|
+
|
65
|
+
request(uri, req)
|
66
|
+
end
|
67
|
+
|
68
|
+
def apply_headers(req, with_auth = true)
|
69
|
+
req['Authorization'] = "Bearer #{@api_key}" if with_auth
|
70
|
+
req['X-TITLE-ID'] = "semc-vainglory"
|
71
|
+
req['Accept'] = "application/vnd.api+json"
|
72
|
+
|
73
|
+
req
|
74
|
+
end
|
75
|
+
|
76
|
+
def request(uri, req)
|
77
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
78
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
79
|
+
http.use_ssl = true
|
80
|
+
|
81
|
+
response(http.request(req))
|
82
|
+
end
|
83
|
+
|
84
|
+
def endpoint_uri(path, filter_params = {})
|
85
|
+
uri = URI(endpoint_url(path))
|
86
|
+
uri.query = URI.encode_www_form(filter_params)
|
87
|
+
|
88
|
+
uri
|
89
|
+
end
|
90
|
+
|
91
|
+
def endpoint_url(path)
|
92
|
+
[BASE_URL, path].join('/')
|
93
|
+
end
|
94
|
+
|
95
|
+
def response(response_data)
|
96
|
+
parsed_body = JSON.parse(response_data.body, object_class: OpenStruct)
|
97
|
+
parsed_code = response_data.code.to_i
|
98
|
+
|
99
|
+
OpenStruct.new({
|
100
|
+
code: parsed_code,
|
101
|
+
success?: parsed_code < 300,
|
102
|
+
rate_limit: response_data['X-RateLimit-Limit'].to_i,
|
103
|
+
rate_remaining: response_data['X-RateLimit-Remaining'].to_i,
|
104
|
+
rate_reset: response_data['X-RateLimit-Reset'].to_i,
|
105
|
+
data: parsed_body.respond_to?(:data) ? parsed_body.data : parsed_body,
|
106
|
+
error: parsed_body.respond_to?(:error)? parsed_body.error : nil,
|
107
|
+
raw: response_data
|
108
|
+
})
|
109
|
+
end
|
110
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vainglory-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chet Bortz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: webmock
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: vcr
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.14'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.14'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: codeclimate-test-reporter
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.0'
|
83
|
+
description: A Ruby libary wrapper for the Vainglory API
|
84
|
+
email:
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- lib/vainglory_api.rb
|
90
|
+
homepage:
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '2.0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.4.8
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Vainglory API
|
114
|
+
test_files: []
|