gorgerb 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92bdd09b3212ee3b0310996d9f87481f1a23607b2bd53a32e27531631d648608
4
- data.tar.gz: 85905d90026e1001a90ae77a498856c63f31e998717d5761725a797ac5410de2
3
+ metadata.gz: 7ac26d65b69948cdf64ed0d232df076bc17f0788c4c4cebda0032c67ec1ec71a
4
+ data.tar.gz: 4c9a92e1e186b6c3abbaafa6f764ab8ed022fff61f6ad6cacb68064ebf3396ed
5
5
  SHA512:
6
- metadata.gz: 1c4750bef2d3559fe07a03892a2304f45769d8ec07ef50ddeee686dec0ba6858e9a5724ba909ea12aa541fb01b62bb0ed91d1516a3d543ae08b8cf77de30ed86
7
- data.tar.gz: bc10db0b6a28231f9d03b7712b24ea9ae91a015080396418607f38209b16a9071fbfcd7f20580314fbc4e1c929991729cea428f6fae8e6a49c7bb90003c8cab4
6
+ metadata.gz: cbc505a11b49dce7caa14f997961621786d4838da7ecabd9dd017f837c085b39f9efaa3307d7c7dc1a1ced80c7734c818d60d38f7626d2cb872c83bb9c984cf9
7
+ data.tar.gz: '03395f8f62d8cfd75cdc359abc8ee6569e8476c796703ebcf08cc4fefb9f1b5710965ae095b61baf41904ecf520e033f236d9a125ac91ec7cbbbf0b47b4a63bf'
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  spec/examples.txt
2
+ Gemfile.lock
@@ -19,6 +19,13 @@ glance - what to expact from upgrading to a new version.
19
19
  ### Removed
20
20
 
21
21
 
22
+ ## [0.2.0] - 2019-03-17
23
+
24
+ ### Added
25
+
26
+ - Add support for new output format of Gorge.
27
+
28
+
22
29
  ## [0.1.0] - 2018-04-03
23
30
 
24
31
  ### Added
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in sunscout.gemspec
3
+ # Specify your gem's dependencies in gorgerb.gemspec
4
4
  gemspec
@@ -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.1.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', '~> 1.16'
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
@@ -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
- response = request("players/#{ steam_id }/statistics")
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(:total, :alien, :marine)
6
- Accuracy = Struct.new(:total, :alien, :marine)
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, :kdr, :accuracy
11
+ attr_reader :steam_id
10
12
 
11
13
  def self.from_hsh(data)
12
- kdr_data = data.fetch('kdr')
13
- accuracy_data = data.fetch('accuracy')
14
-
15
- steam_id = data.fetch 'steam_id'
16
- kdr = KDR.new(
17
- kdr_data.fetch('total'),
18
- kdr_data.fetch('alien'),
19
- kdr_data.fetch('marine')
20
- )
21
- accuracy = Accuracy.new(
22
- accuracy_data.fetch('total'),
23
- accuracy_data.fetch('alien'),
24
- MarineAccuracy.new(
25
- accuracy_data.fetch('marine').fetch('total'),
26
- accuracy_data.fetch('marine').fetch('no_onos'),
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, kdr, accuracy)
49
+ PlayerStatistics.new(steam_id, stats_points)
31
50
  end
32
51
 
33
- def initialize(steam_id, kdr, accuracy)
52
+ def initialize(steam_id, statistics_points)
34
53
  @steam_id = steam_id
35
- @kdr = kdr
36
- @accuracy = accuracy
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.1.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: 2018-04-03 00:00:00.000000000 Z
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: '1.16'
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: '1.16'
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
- rubyforge_project:
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.
@@ -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