hoptoad_zmq_notifier 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in hoptoad_notifier_zmq.gemspec
4
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2011, Nick Recobra
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,34 @@
1
+ = Hoptoad 0MQ Notifier
2
+
3
+ Hoptoad notifier extension for speaking to the server over 0mq socket.
4
+
5
+ One should use this library to speak to Errbit server extended by Errbit 0MQ Handler (https://github.com/oruen/errbit_zmq_handler)
6
+
7
+ == Installation
8
+
9
+ Install zeromq 2.1 from http://www.zeromq.org/ or your favorite package system.
10
+
11
+ Install the gem:
12
+
13
+ gem install hoptoad_zmq_notifier
14
+
15
+ == Usage
16
+
17
+ In the same initializer you initialize your Hoptoad Notifier client:
18
+ HoptoadNotifier.configure do |config|
19
+ config.api_key = 'ba134e3c7fab581e8685cde0a5e68728'
20
+ config.host = 'localhost'
21
+ config.port = 3000
22
+ end
23
+
24
+ HoptoadZmqHandler.configure do |config|
25
+ # Address to connect to send exception notifications
26
+ config.uri = "tcp://127.0.0.1:9998"
27
+ end
28
+
29
+ From now all notices will be send through 0MQ socket to address you defined.
30
+
31
+ == License
32
+
33
+ HoptoadZmqNotifier is Copyright © 2011 oruen. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
34
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec) do |t|
6
+ end
7
+ task :default => :spec
8
+
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "hoptoad_zmq_notifier/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "hoptoad_zmq_notifier"
7
+ s.version = HoptoadZmqNotifier::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Nick Recobra"]
10
+ s.email = ["oruenu@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{0MQ client for Errbit}
13
+ s.description = %q{Hoptoad Notifier extension making hoptoad client speak to server via 0MQ socket.}
14
+
15
+ s.rubyforge_project = "hoptoad_notifier_zmq"
16
+
17
+ s.add_dependency 'hoptoad_notifier', '> 0'
18
+ s.add_dependency 'ffi-rzmq'
19
+ s.add_dependency 'ffi'
20
+ s.add_development_dependency 'rspec', '>= 2.5.0'
21
+
22
+ s.files = `git ls-files`.split("\n")
23
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
+ s.require_paths = ["lib"]
26
+ end
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+ module HoptoadZmqNotifier
3
+ # Used to set up and modify settings for the notifier.
4
+ class Configuration
5
+
6
+ OPTIONS = [:mailbox_size, :uri].freeze
7
+
8
+ # Size of outgoing messages queue. All messages over this value will be dropped.
9
+ attr_accessor :mailbox_size
10
+
11
+ # The uri to connect to (0MQ socket)
12
+ attr_accessor :uri
13
+
14
+ def initialize
15
+ @mailbox_size = 200
16
+ end
17
+
18
+ def zmq_context
19
+ @zmq_context ||= ZMQ::Context.new
20
+ end
21
+
22
+ def socket
23
+ @socket ||= begin
24
+ s = zmq_context.socket ZMQ::PUB
25
+ s.connect @uri
26
+ s.setsockopt(ZMQ::HWM, mailbox_size)
27
+ s
28
+ end
29
+ end
30
+
31
+ # Allows config options to be read like a hash
32
+ #
33
+ # @param [Symbol] option Key for a given attribute
34
+ def [](option)
35
+ send(option)
36
+ end
37
+
38
+ # Returns a hash of all configurable options
39
+ def to_hash
40
+ OPTIONS.inject({}) do |hash, option|
41
+ hash.merge(option.to_sym => send(option))
42
+ end
43
+ end
44
+
45
+ # Returns a hash of all configurable options merged with +hash+
46
+ #
47
+ # @param [Hash] hash A set of configuration options that will take precedence over the defaults
48
+ def merge(hash)
49
+ to_hash.merge(hash)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+ require 'ffi'
3
+ require 'ffi-rzmq'
4
+
5
+ module HoptoadZmqNotifier
6
+ class Sender
7
+ def send_to_hoptoad data
8
+ logger.debug { "Sending request to #{@uri}:\n#{data}" } if logger
9
+ socket.send_string data
10
+ end
11
+
12
+ def initialize(options = {})
13
+ [:mailbox_size, :uri].each do |option|
14
+ instance_variable_set("@#{option}", options[option])
15
+ end
16
+ end
17
+
18
+ private
19
+ def logger
20
+ HoptoadNotifier.logger
21
+ end
22
+
23
+ def socket
24
+ @socket ||= HoptoadZmqNotifier.configuration.socket
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module HoptoadZmqNotifier
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+ require 'hoptoad_notifier'
3
+ module HoptoadZmqNotifier
4
+ autoload :Configuration, 'hoptoad_zmq_notifier/configuration'
5
+ autoload :Sender, 'hoptoad_zmq_notifier/sender'
6
+ class << self
7
+ # The sender object is responsible for delivering formatted data to the Hoptoad server.
8
+ # Must respond to #send_to_hoptoad. See HoptoadNotifier::Sender.
9
+ attr_accessor :sender
10
+
11
+ # A Hoptoad Notifier ZMQ configuration object. Must act like a hash and return sensible
12
+ # values for all Hoptoad ZMQ configuration options. See HoptoadNotifierZmq::Configuration.
13
+ attr_accessor :configuration
14
+
15
+ # Call this method to modify defaults in your initializers.
16
+ #
17
+ # @example
18
+ # HoptoadNotifierZmq.configure do |config|
19
+ # config.mailbox_sizr = 1000
20
+ # config.uri = 'tcp://errbit.home:9999'
21
+ # end
22
+ def configure
23
+ self.configuration ||= Configuration.new
24
+ yield(configuration)
25
+ self.sender = Sender.new(configuration)
26
+ end
27
+ end
28
+ end
29
+
30
+ HoptoadNotifier.configure do |config|
31
+ end
32
+
33
+ module HoptoadNotifier
34
+ class Sender
35
+ def send_to_hoptoad *args
36
+ HoptoadZmqNotifier.sender.send_to_hoptoad(*args)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe HoptoadZmqNotifier::Configuration do
5
+ it "should provide default mailbox size" do
6
+ assert_config_default :mailbox_size, 200
7
+ end
8
+
9
+ it "should mailbox size to be overitten" do
10
+ assert_config_overridable :mailbox_size
11
+ end
12
+
13
+ it "should have an uri" do
14
+ assert_config_overridable :uri
15
+ end
16
+ end
17
+
18
+ def assert_config_overridable(option, value = 'a value')
19
+ config = HoptoadZmqNotifier::Configuration.new
20
+ config.send(:"#{option}=", value)
21
+ config.send(option).should == value
22
+ end
23
+
24
+ def assert_config_default(option, default_value, config = nil)
25
+ config ||= HoptoadZmqNotifier::Configuration.new
26
+ config.send(option).should == default_value
27
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe HoptoadZmqNotifier::Sender do
5
+ before(:each) do
6
+ @uri = "tcp://127.0.0.1:9998"
7
+ @message = "sample message"
8
+ @mailbox_size = 35
9
+ HoptoadZmqNotifier.configure do |config|
10
+ config.uri = @uri
11
+ config.mailbox_size = @mailbox_size
12
+ end
13
+
14
+ ctx = ZMQ::Context.new
15
+ @subscriber = ctx.socket ZMQ::SUB
16
+ @subscriber.bind(@uri)
17
+ @subscriber.setsockopt ZMQ::SUBSCRIBE, ""
18
+ end
19
+
20
+ after :each do
21
+ @subscriber.close
22
+ end
23
+
24
+ it "should send messages via 0MQ" do
25
+ HoptoadNotifier.sender.send_to_hoptoad(@message)
26
+ sleep 1
27
+ @subscriber.recv_string(ZMQ::NOBLOCK).should == @message
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'rspec'
4
+ require 'hoptoad_zmq_notifier'
5
+
6
+ Rspec.configure do |c|
7
+ c.mock_with :rspec
8
+ end
9
+
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hoptoad_zmq_notifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nick Recobra
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-03-03 00:00:00.000000000 +03:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoptoad_notifier
17
+ requirement: &2153369360 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>'
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2153369360
26
+ - !ruby/object:Gem::Dependency
27
+ name: ffi-rzmq
28
+ requirement: &2153368940 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *2153368940
37
+ - !ruby/object:Gem::Dependency
38
+ name: ffi
39
+ requirement: &2153368480 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *2153368480
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
50
+ requirement: &2153367980 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: 2.5.0
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *2153367980
59
+ description: Hoptoad Notifier extension making hoptoad client speak to server via
60
+ 0MQ socket.
61
+ email:
62
+ - oruenu@gmail.com
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - .gitignore
68
+ - Gemfile
69
+ - MIT-LICENSE
70
+ - README.rdoc
71
+ - Rakefile
72
+ - hoptoad_notifier_zmq.gemspec
73
+ - lib/hoptoad_zmq_notifier.rb
74
+ - lib/hoptoad_zmq_notifier/configuration.rb
75
+ - lib/hoptoad_zmq_notifier/sender.rb
76
+ - lib/hoptoad_zmq_notifier/version.rb
77
+ - spec/lib/hoptoad_notifier_zmq/configuration_spec.rb
78
+ - spec/lib/hoptoad_notifier_zmq/sender_spec.rb
79
+ - spec/spec_helper.rb
80
+ has_rdoc: true
81
+ homepage: ''
82
+ licenses: []
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project: hoptoad_notifier_zmq
101
+ rubygems_version: 1.5.2
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: 0MQ client for Errbit
105
+ test_files:
106
+ - spec/lib/hoptoad_notifier_zmq/configuration_spec.rb
107
+ - spec/lib/hoptoad_notifier_zmq/sender_spec.rb
108
+ - spec/spec_helper.rb