cube-ruby 0.0.2 → 0.0.3
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.
- data/README.md +2 -2
- data/cube-ruby.gemspec +2 -2
- data/lib/cube.rb +21 -13
- data/lib/cube/version.rb +1 -1
- data/realtest.rb +6 -0
- data/spec/cube_spec.rb +17 -1
- metadata +5 -4
data/README.md
CHANGED
@@ -17,7 +17,7 @@ Here's a version compatibility table:
|
|
17
17
|
Cube | cube-ruby
|
18
18
|
--------------------
|
19
19
|
0.2.0 | 0.0.1
|
20
|
-
0.2.1
|
20
|
+
0.2.1+ | 0.0.2 (master)
|
21
21
|
|
22
22
|
Add this line to your application's `Gemfile`:
|
23
23
|
|
@@ -53,7 +53,7 @@ $cube = Cube::Client.new 'cube.example.org', 2280
|
|
53
53
|
$cube.send "foo"
|
54
54
|
|
55
55
|
# send a new event to cube that looks like this:
|
56
|
-
# { type: "request",
|
56
|
+
# { type: "request", data: { value: "somevalue" } }
|
57
57
|
$cube.send "request", value: "somevalue"
|
58
58
|
|
59
59
|
# optionally specify a specific date/time (two days ago)
|
data/cube-ruby.gemspec
CHANGED
@@ -4,8 +4,8 @@ require File.expand_path('../lib/cube/version', __FILE__)
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["Cody Krieger"]
|
6
6
|
gem.email = ["cody@codykrieger.com"]
|
7
|
-
gem.description = %q{A Cube client for Ruby (
|
8
|
-
gem.summary = %q{A Cube client for Ruby (
|
7
|
+
gem.description = %q{A Cube client for Ruby (http://square.github.com/cube).}
|
8
|
+
gem.summary = %q{A Cube client for Ruby (http://square.github.com/cube).}
|
9
9
|
gem.homepage = "https://github.com/codykrieger/cube-ruby"
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($\)
|
data/lib/cube.rb
CHANGED
@@ -22,17 +22,18 @@ module Cube
|
|
22
22
|
end
|
23
23
|
|
24
24
|
# Set 'er up with a host and port, defaults to `localhost:1180`.
|
25
|
+
#
|
26
|
+
# @param [String] The hostname to send metrics to.
|
27
|
+
# @param [Integer] The UDP port to send metrics to.
|
25
28
|
def initialize(host="localhost", port=1180)
|
26
29
|
@host, @port = host, port
|
27
30
|
end
|
28
31
|
|
29
|
-
# The primary endpoint for sending metrics to Cube
|
32
|
+
# The primary endpoint for sending metrics to Cube.
|
30
33
|
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
# cube.send "request", DateTime.now, duration_ms: 234
|
35
|
-
# ```
|
34
|
+
# @param [String] The desired name of the new Cube event.
|
35
|
+
# @param [Array] A splat that takes an optional DateTime, an event id
|
36
|
+
# (typically an integer, but can be any object), and a Hash of data.
|
36
37
|
def send(type, *args)
|
37
38
|
time = nil
|
38
39
|
id = nil
|
@@ -41,13 +42,14 @@ module Cube
|
|
41
42
|
until args.empty?
|
42
43
|
arg = args.shift
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
case arg
|
46
|
+
when DateTime, Time
|
47
|
+
time ||= arg
|
48
|
+
when Hash
|
49
|
+
data ||= arg
|
50
|
+
else
|
51
|
+
id ||= arg
|
52
|
+
end
|
51
53
|
end
|
52
54
|
|
53
55
|
# Send off our parsed arguments to be further massaged and socketized.
|
@@ -58,6 +60,12 @@ module Cube
|
|
58
60
|
|
59
61
|
# Actually send the given data to a socket, and potentially log it along
|
60
62
|
# the way.
|
63
|
+
#
|
64
|
+
# @param [String] The desired name of the new Cube event.
|
65
|
+
# @param [DateTime] Optional. A specific time when the Cube event occurred.
|
66
|
+
# @param [Object] Optional. Typically an integer, but can be any object.
|
67
|
+
# @param [Hash] Optional. Anything in this hash will be stored in the
|
68
|
+
# `data` subdocument of the Cube event.
|
61
69
|
def actual_send(type, time, id, data)
|
62
70
|
# Namespace support!
|
63
71
|
prefix = "#{@namespace}_" unless @namespace.nil?
|
data/lib/cube/version.rb
CHANGED
data/realtest.rb
ADDED
data/spec/cube_spec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
require 'date'
|
3
|
+
require 'time'
|
3
4
|
require 'json'
|
4
5
|
|
5
6
|
# a few things yanked verbatim from here: https://github.com/github/statsd-ruby/blob/master/spec/statsd_spec.rb
|
@@ -37,7 +38,7 @@ describe Cube::Client do
|
|
37
38
|
recv["type"].must_equal "request"
|
38
39
|
end
|
39
40
|
|
40
|
-
describe "with a
|
41
|
+
describe "with a DateTime" do
|
41
42
|
it "should format the message according to the Cube spec" do
|
42
43
|
type = "request"
|
43
44
|
time = DateTime.now
|
@@ -63,6 +64,21 @@ describe Cube::Client do
|
|
63
64
|
end
|
64
65
|
end
|
65
66
|
|
67
|
+
describe "with Time" do
|
68
|
+
it "should format the message according to the Cube spec" do
|
69
|
+
type = "request"
|
70
|
+
time = Time.now
|
71
|
+
id = 42
|
72
|
+
data = { duration_ms: 234 }
|
73
|
+
@cube.send type, time, id, data
|
74
|
+
recv = JSON.parse @cube.socket.recv.first
|
75
|
+
recv["type"].must_equal "request"
|
76
|
+
recv["time"].must_equal time.iso8601
|
77
|
+
recv["id"].must_equal 42
|
78
|
+
recv["data"].must_equal({ "duration_ms" => 234 })
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
66
82
|
describe "with data" do
|
67
83
|
it "should format the message according to the Cube spec" do
|
68
84
|
type = "request"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cube-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
@@ -27,7 +27,7 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
-
description: A Cube client for Ruby (
|
30
|
+
description: A Cube client for Ruby (http://square.github.com/cube).
|
31
31
|
email:
|
32
32
|
- cody@codykrieger.com
|
33
33
|
executables: []
|
@@ -42,6 +42,7 @@ files:
|
|
42
42
|
- cube-ruby.gemspec
|
43
43
|
- lib/cube.rb
|
44
44
|
- lib/cube/version.rb
|
45
|
+
- realtest.rb
|
45
46
|
- spec/cube_spec.rb
|
46
47
|
- spec/helper.rb
|
47
48
|
homepage: https://github.com/codykrieger/cube-ruby
|
@@ -67,7 +68,7 @@ rubyforge_project:
|
|
67
68
|
rubygems_version: 1.8.23
|
68
69
|
signing_key:
|
69
70
|
specification_version: 3
|
70
|
-
summary: A Cube client for Ruby (
|
71
|
+
summary: A Cube client for Ruby (http://square.github.com/cube).
|
71
72
|
test_files:
|
72
73
|
- spec/cube_spec.rb
|
73
74
|
- spec/helper.rb
|