statsman 1.0.1 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6e6ca78a88aaa087a5b1fe040851d6456c9020a
4
- data.tar.gz: af309337b7986f0418b40f8a178a71b16ff05526
3
+ metadata.gz: d752188d03561e87022a85944cf218e4fa06b853
4
+ data.tar.gz: b28134db13fd3290a4a25f3ccc662d01e06c42e2
5
5
  SHA512:
6
- metadata.gz: 6d853058a3144847f50606a4136896d08523fa66d98fb5d61709d8a68cfab8a33bef0f949d7277f3fff653e04efa620b62ecdee237f3e51f278ce66bc6479d03
7
- data.tar.gz: c27970aaa706221e83b13bc57d563d3623e563d375f771f877419f651aff88f47881c0829e95938443bd04600292ea2a480879044aad0f07d492295b09f98835
6
+ metadata.gz: 14a313c858001d4c7a00648bd76d59298dd0a34c381519b5880c8bcc865c34aec76dd387aec9a9523e79ca1eb4e9ef7200c560933166ea5462922e461ce060a0
7
+ data.tar.gz: 0f497b50cd46602827b9bb3e019ca0531bbae2603cc41200db829b57965d1d96c34b4a39c513f9c93d2a63e2bd06d7556ef59f634fb0063cd82deaee968d8664
@@ -3,43 +3,45 @@ require "sucker_punch"
3
3
  require "openssl"
4
4
  require "json"
5
5
 
6
- class ReporterJob
7
- include SuckerPunch::Job
8
-
9
- def perform(config, data_type, key, value, meta)
10
- Statsman::Agent.log("ReporterJob sending data_type: #{data_type}, key: #{key}, value: #{value}, meta: #{meta}")
11
-
12
- body = {
13
- data_type: data_type,
14
- key: key,
15
- value: value,
16
- meta: meta,
17
- time: Time.now.to_i # Add timestamp to body to avoid replay attacks
18
- }
19
-
20
- url = "#{config.url}/stats"
21
-
22
- resp = HTTParty.post(
23
- "#{config.url}/stats",
24
- headers: { "authorization" => request_auth_header(config, "/stats", body)},
25
- body: body
26
- )
27
- Statsman::Agent.log("sent data_type: #{data_type}, key: #{key}, value: #{value}, meta: #{meta}, response: [#{resp.code}] #{resp.headers.inspect}")
28
-
29
- rescue => e
30
- Statsman::Agent.log("Exception sending data_type: #{data_type}, key: #{key}, value: #{value}, meta: #{meta}: #{e.message}\n#{e.backtrace.join("\n")}")
31
-
32
- end
33
-
34
- def request_auth_header(config, path, body)
35
- signature = request_signature(config, path, body)
36
- "#{config.api_key}:#{signature}"
6
+ module Statsman
7
+ class ReporterJob
8
+ include SuckerPunch::Job
9
+
10
+ def perform(config, data_type, key, value, meta)
11
+ Statsman::Agent.log("ReporterJob sending data_type: #{data_type}, key: #{key}, value: #{value}, meta: #{meta}")
12
+
13
+ body = {
14
+ data_type: data_type,
15
+ key: key,
16
+ value: value,
17
+ meta: meta,
18
+ time: Time.now.to_i # Add timestamp to body to avoid replay attacks
19
+ }
20
+
21
+ url = "#{config.url}/stats"
22
+
23
+ resp = HTTParty.post(
24
+ "#{config.url}/stats",
25
+ headers: { "authorization" => request_auth_header(config, "/stats", body)},
26
+ body: body
27
+ )
28
+ Statsman::Agent.log("sent data_type: #{data_type}, key: #{key}, value: #{value}, meta: #{meta}, response: [#{resp.code}] #{resp.headers.inspect}")
29
+
30
+ rescue => e
31
+ Statsman::Agent.log("Exception sending data_type: #{data_type}, key: #{key}, value: #{value}, meta: #{meta}: #{e.message}\n#{e.backtrace.join("\n")}")
32
+
33
+ end
34
+
35
+ def request_auth_header(config, path, body)
36
+ signature = request_signature(config, path, body)
37
+ "#{config.api_key}:#{signature}"
38
+ end
39
+
40
+ def request_signature(config, path, body)
41
+ str = HTTParty::HashConversions.to_params(body)
42
+ to_sign = path + str
43
+ OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), config.api_secret, to_sign)
44
+ end
45
+
37
46
  end
38
-
39
- def request_signature(config, path, body)
40
- str = HTTParty::HashConversions.to_params(body)
41
- to_sign = path + str
42
- OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), config.api_secret, to_sign)
43
- end
44
-
45
47
  end
@@ -1,3 +1,3 @@
1
1
  module Statsman
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
data/lib/statsman.rb CHANGED
@@ -61,7 +61,7 @@ module Statsman
61
61
 
62
62
  def send_data(data_type, key, value, meta = {})
63
63
  log("enqueueing data_type: #{data_type}, key: #{key}, value: #{value}, meta: #{meta.inspect}")
64
- ReporterJob.new.async.perform(config, data_type, key, value, meta.to_json)
64
+ Statsman::ReporterJob.new.async.perform(config, data_type, key, value, meta.to_json)
65
65
  end
66
66
 
67
67
  end # Agent
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statsman
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Emminger
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-07-09 00:00:00.000000000 Z
12
+ date: 2015-07-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sucker_punch