measures 1.0.0 → 2.0.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
  SHA1:
3
- metadata.gz: 5762e573fb1e82f50eae006d466fb725e57524cd
4
- data.tar.gz: 8e6bd6539060a82e7607aa76d988d9815d1bd95c
3
+ metadata.gz: fb39435f2dc43dab2b8ed85647f464077e5df90e
4
+ data.tar.gz: c91af23e4c666b86a9a5dc0df7e16b6abc5223a8
5
5
  SHA512:
6
- metadata.gz: 374ce521a3665d9d7125ff628a55e1db326ce6d738deb2d60c92456d710f1a3f5b57b964376d28979e8dd13309652e3280f7d5189d76ed93c9df75fd9842a2a5
7
- data.tar.gz: dce0f1c8a36464afdcc1fbf33368f256374acea8989ab5baa55f47a1c2f8fe07dbf993a2a18c7e4369c2149bb15b476f331c1d7ac6e66b610604979ea05be800
6
+ metadata.gz: 26ba1b0f7d91602a51a5ea372a69abe97a6d3cdf84e666f2280fb85b902db39f94eb8ecc3775c495e5a9653a8f6e1c8b5fde937e0055f0f4e682edeeb2f80616
7
+ data.tar.gz: 2f8718cdbd1f9496161148eaab0a6195e14103ec1369e5865995bbdb1c5882479282bec7fc01bdda95edd73a200d221bc2720d1363a72a4f0a4f43804b83d999
data/README.md CHANGED
@@ -25,8 +25,11 @@ $ gem install measures
25
25
  ```ruby
26
26
  require "measures"
27
27
 
28
+ # Creates the transport form (UDP/HTTP/...)
29
+ transport = Measures::Transport::UDP.new("logstash.foo.bar", 30)
30
+
28
31
  # Creates the measure client instance
29
- measures = Measures::Client.new("my-app", "logstash.foo.bar", 30)
32
+ measures = Measures::Client.new(transport, "my-app")
30
33
 
31
34
  # Sends count metric
32
35
  measures.count("my_count_metric")
data/lib/measures.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require "measures/version"
2
2
  require "measures/client"
3
+ require "measures/transport/udp"
4
+ require "measures/transport/http"
3
5
 
4
6
  module Measures; end
@@ -1,13 +1,11 @@
1
- require "socket"
2
1
  require "json"
3
2
  require "benchmark"
4
3
 
5
4
  module Measures
6
5
  class Client
7
- def initialize(client, host, port)
6
+ def initialize(transport, client)
8
7
  @client = client
9
- @socket = UDPSocket.new
10
- @socket.connect(host, port)
8
+ @transport = transport
11
9
  end
12
10
 
13
11
  def count(metric, data = {})
@@ -36,7 +34,7 @@ module Measures
36
34
 
37
35
  default.merge!(data)
38
36
 
39
- @socket.send(default.to_json, 0)
37
+ @transport.send(default.to_json)
40
38
  end
41
39
  end
42
40
  end
@@ -0,0 +1,28 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+ require "uri"
4
+
5
+ module Measures
6
+ module Transport
7
+ class HTTP
8
+ def initialize(host, port)
9
+ @host = host
10
+ @port = port
11
+ end
12
+
13
+ def send(data)
14
+ client = Faraday.new(url: URI::HTTP.build(host: @host, port: @port)) do |c|
15
+ c.request :json
16
+
17
+ c.adapter Faraday.default_adapter
18
+ end
19
+
20
+ client.post do |req|
21
+ req.url "/"
22
+ req.headers["Content-Type"] = "application/json"
23
+ req.body = data
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,16 @@
1
+ require "socket"
2
+
3
+ module Measures
4
+ module Transport
5
+ class UDP
6
+ def initialize(host, port)
7
+ @socket = UDPSocket.new
8
+ @socket.connect(host, port)
9
+ end
10
+
11
+ def send(data)
12
+ @socket.send(data, 0)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module Measures
2
- VERSION = "1.0.0"
2
+ VERSION = "2.0.0"
3
3
  end
data/measures.gemspec CHANGED
@@ -15,9 +15,13 @@ Gem::Specification.new do |spec|
15
15
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
16
  spec.require_paths = ["lib"]
17
17
 
18
+ spec.add_dependency "faraday"
19
+ spec.add_dependency "faraday_middleware"
20
+
18
21
  spec.add_development_dependency "bundler", "~> 1.11"
19
22
  spec.add_development_dependency "rake", "~> 10.0"
20
23
  spec.add_development_dependency "rspec"
21
24
  spec.add_development_dependency "guard"
22
25
  spec.add_development_dependency "guard-rspec"
26
+ spec.add_development_dependency "webmock"
23
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: measures
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Boeira
@@ -9,8 +9,36 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-04-08 00:00:00.000000000 Z
12
+ date: 2016-04-12 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: faraday_middleware
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
14
42
  - !ruby/object:Gem::Dependency
15
43
  name: bundler
16
44
  requirement: !ruby/object:Gem::Requirement
@@ -81,6 +109,20 @@ dependencies:
81
109
  - - ">="
82
110
  - !ruby/object:Gem::Version
83
111
  version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: webmock
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
84
126
  description: Measures ruby client
85
127
  email:
86
128
  - me@marceloboeira.com
@@ -100,6 +142,8 @@ files:
100
142
  - bin/setup
101
143
  - lib/measures.rb
102
144
  - lib/measures/client.rb
145
+ - lib/measures/transport/http.rb
146
+ - lib/measures/transport/udp.rb
103
147
  - lib/measures/version.rb
104
148
  - measures.gemspec
105
149
  homepage: ''