gorgerb 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +1 -1
- data/gorgerb.gemspec +2 -2
- data/lib/gorgerb/client.rb +15 -6
- data/lib/gorgerb/player_statistics.rb +51 -23
- metadata +5 -7
- data/Gemfile.lock +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ac26d65b69948cdf64ed0d232df076bc17f0788c4c4cebda0032c67ec1ec71a
|
4
|
+
data.tar.gz: 4c9a92e1e186b6c3abbaafa6f764ab8ed022fff61f6ad6cacb68064ebf3396ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbc505a11b49dce7caa14f997961621786d4838da7ecabd9dd017f837c085b39f9efaa3307d7c7dc1a1ced80c7734c818d60d38f7626d2cb872c83bb9c984cf9
|
7
|
+
data.tar.gz: '03395f8f62d8cfd75cdc359abc8ee6569e8476c796703ebcf08cc4fefb9f1b5710965ae095b61baf41904ecf520e033f236d9a125ac91ec7cbbbf0b47b4a63bf'
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/gorgerb.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'gorgerb'
|
7
|
-
spec.version = '0.
|
7
|
+
spec.version = '0.2.0'
|
8
8
|
spec.authors = ['Michael Senn']
|
9
9
|
spec.email = ['michael@morrolan.ch']
|
10
10
|
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_dependency 'typhoeus', '~> 1.3'
|
22
22
|
|
23
|
-
spec.add_development_dependency 'bundler', '~>
|
23
|
+
spec.add_development_dependency 'bundler', '~> 2'
|
24
24
|
spec.add_development_dependency 'rspec', '~> 3.7'
|
25
25
|
spec.add_development_dependency 'pry', '~> 0.11'
|
26
26
|
end
|
data/lib/gorgerb/client.rb
CHANGED
@@ -13,8 +13,15 @@ module Gorgerb
|
|
13
13
|
Typhoeus::Config.user_agent = user_agent
|
14
14
|
end
|
15
15
|
|
16
|
-
def player_statistics(steam_id)
|
17
|
-
|
16
|
+
def player_statistics(steam_id, statistics_classes:)
|
17
|
+
statistics_classes = [statistics_classes] unless statistics_classes.is_a? Array
|
18
|
+
|
19
|
+
response = request(
|
20
|
+
"players/#{ steam_id }/statistics",
|
21
|
+
params: {
|
22
|
+
statistics_classes: statistics_classes
|
23
|
+
}
|
24
|
+
)
|
18
25
|
|
19
26
|
PlayerStatistics.from_hsh(response)
|
20
27
|
rescue KeyError => e
|
@@ -22,8 +29,8 @@ module Gorgerb
|
|
22
29
|
end
|
23
30
|
|
24
31
|
private
|
25
|
-
def request(path, method: :get)
|
26
|
-
request = build_request(path, method: :get)
|
32
|
+
def request(path, method: :get, params: {})
|
33
|
+
request = build_request(path, method: :get, params: params)
|
27
34
|
request.run
|
28
35
|
|
29
36
|
response = request.response
|
@@ -42,10 +49,12 @@ module Gorgerb
|
|
42
49
|
raise APIError, 'Invalid JSON received from API'
|
43
50
|
end
|
44
51
|
|
45
|
-
def build_request(path, method: :get)
|
52
|
+
def build_request(path, method: :get, params:)
|
46
53
|
opts = {
|
47
54
|
connecttimeout: @connect_timeout,
|
48
|
-
timeout: @timeout
|
55
|
+
timeout: @timeout,
|
56
|
+
params: params,
|
57
|
+
params_encoding: :rack
|
49
58
|
}
|
50
59
|
opts[:userpwd] = "#{ @http_user }:#{ @http_password }" if @http_user && @http_password
|
51
60
|
|
@@ -2,38 +2,66 @@ require 'json'
|
|
2
2
|
|
3
3
|
module Gorgerb
|
4
4
|
class PlayerStatistics
|
5
|
-
KDR = Struct.new(:
|
6
|
-
Accuracy = Struct.new(:
|
5
|
+
KDR = Struct.new(:alien, :marine)
|
6
|
+
Accuracy = Struct.new(:alien, :marine)
|
7
7
|
MarineAccuracy = Struct.new(:total, :no_onos)
|
8
|
+
Meta = Struct.new(:sample_size)
|
9
|
+
StatisticsPoint = Struct.new(:meta, :kdr, :accuracy)
|
8
10
|
|
9
|
-
attr_reader :steam_id
|
11
|
+
attr_reader :steam_id
|
10
12
|
|
11
13
|
def self.from_hsh(data)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
kdr_data.fetch('
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
14
|
+
stats_points = {}
|
15
|
+
|
16
|
+
steam_id = data.fetch('_').fetch('steam_id')
|
17
|
+
# Prevent it being treated as a stats point further below.
|
18
|
+
data.delete('_')
|
19
|
+
|
20
|
+
data.each do |stats_class, class_data|
|
21
|
+
kdr_data = class_data.fetch('kdr')
|
22
|
+
accuracy_data = class_data.fetch('accuracy')
|
23
|
+
meta_data = class_data.fetch('_')
|
24
|
+
|
25
|
+
kdr = KDR.new(
|
26
|
+
kdr_data.fetch('alien'),
|
27
|
+
kdr_data.fetch('marine')
|
28
|
+
)
|
29
|
+
|
30
|
+
accuracy = Accuracy.new(
|
31
|
+
accuracy_data.fetch('alien'),
|
32
|
+
MarineAccuracy.new(
|
33
|
+
accuracy_data.fetch('marine').fetch('total'),
|
34
|
+
accuracy_data.fetch('marine').fetch('no_onos'),
|
35
|
+
)
|
36
|
+
)
|
37
|
+
|
38
|
+
meta = Meta.new(
|
39
|
+
meta_data.fetch('sample_size')
|
40
|
+
)
|
41
|
+
|
42
|
+
stats_points[stats_class] = StatisticsPoint.new(
|
43
|
+
meta,
|
44
|
+
kdr,
|
45
|
+
accuracy
|
27
46
|
)
|
28
|
-
|
47
|
+
end
|
29
48
|
|
30
|
-
PlayerStatistics.new(steam_id,
|
49
|
+
PlayerStatistics.new(steam_id, stats_points)
|
31
50
|
end
|
32
51
|
|
33
|
-
def initialize(steam_id,
|
52
|
+
def initialize(steam_id, statistics_points)
|
34
53
|
@steam_id = steam_id
|
35
|
-
@
|
36
|
-
|
54
|
+
@statistics_points = statistics_points
|
55
|
+
end
|
56
|
+
|
57
|
+
def method_missing(m, *args, &block)
|
58
|
+
stats_class = m.to_s
|
59
|
+
|
60
|
+
if @statistics_points.key? stats_class
|
61
|
+
@statistics_points[stats_class]
|
62
|
+
else
|
63
|
+
super(m, *args, &block)
|
64
|
+
end
|
37
65
|
end
|
38
66
|
end
|
39
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gorgerb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Senn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,7 +77,6 @@ files:
|
|
77
77
|
- ".rspec"
|
78
78
|
- CHANGELOG.md
|
79
79
|
- Gemfile
|
80
|
-
- Gemfile.lock
|
81
80
|
- LICENSE
|
82
81
|
- README.md
|
83
82
|
- Rakefile
|
@@ -105,8 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
104
|
- !ruby/object:Gem::Version
|
106
105
|
version: '0'
|
107
106
|
requirements: []
|
108
|
-
|
109
|
-
rubygems_version: 2.7.3
|
107
|
+
rubygems_version: 3.0.1
|
110
108
|
signing_key:
|
111
109
|
specification_version: 4
|
112
110
|
summary: Ruby binding to Gorge, the NS2+/Wonitor stats aggregator.
|
data/Gemfile.lock
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
gorgerb (0.1.0)
|
5
|
-
typhoeus
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
coderay (1.1.2)
|
11
|
-
diff-lcs (1.3)
|
12
|
-
ethon (0.11.0)
|
13
|
-
ffi (>= 1.3.0)
|
14
|
-
ffi (1.9.23)
|
15
|
-
method_source (0.9.0)
|
16
|
-
pry (0.11.3)
|
17
|
-
coderay (~> 1.1.0)
|
18
|
-
method_source (~> 0.9.0)
|
19
|
-
rspec (3.7.0)
|
20
|
-
rspec-core (~> 3.7.0)
|
21
|
-
rspec-expectations (~> 3.7.0)
|
22
|
-
rspec-mocks (~> 3.7.0)
|
23
|
-
rspec-core (3.7.1)
|
24
|
-
rspec-support (~> 3.7.0)
|
25
|
-
rspec-expectations (3.7.0)
|
26
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
-
rspec-support (~> 3.7.0)
|
28
|
-
rspec-mocks (3.7.0)
|
29
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
-
rspec-support (~> 3.7.0)
|
31
|
-
rspec-support (3.7.1)
|
32
|
-
typhoeus (1.3.0)
|
33
|
-
ethon (>= 0.9.0)
|
34
|
-
|
35
|
-
PLATFORMS
|
36
|
-
ruby
|
37
|
-
|
38
|
-
DEPENDENCIES
|
39
|
-
bundler (~> 1.16)
|
40
|
-
gorgerb!
|
41
|
-
pry
|
42
|
-
rspec
|
43
|
-
|
44
|
-
BUNDLED WITH
|
45
|
-
1.16.1
|