nodevent 3.1.2 → 3.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rvmrc +38 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +102 -0
- data/lib/nodevent/net_publisher.rb +56 -0
- data/lib/nodevent/version.rb +1 -1
- data/lib/nodevent.rb +22 -4
- data/nodevent.gemspec +1 -0
- data/spec/base_spec.rb +167 -114
- data/spec/net_publisher_spec.rb +23 -0
- metadata +25 -3
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.idea
|
data/.rvmrc
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 1.9.3" > .rvmrc
|
9
|
+
environment_id="ruby-1.9.3-p194@nodevent-gem"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.14.5 (stable)" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
27
|
+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
28
|
+
if [[ $- == *i* ]] # check for interactive shells
|
29
|
+
then echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
|
30
|
+
else echo "Using: $GEM_HOME" # don't use colors in non-interactive shells
|
31
|
+
fi
|
32
|
+
else
|
33
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
34
|
+
rvm --create use "$environment_id" || {
|
35
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
36
|
+
return 1
|
37
|
+
}
|
38
|
+
fi
|
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
actionmailer (3.2.6)
|
5
|
+
actionpack (= 3.2.6)
|
6
|
+
mail (~> 2.4.4)
|
7
|
+
actionpack (3.2.6)
|
8
|
+
activemodel (= 3.2.6)
|
9
|
+
activesupport (= 3.2.6)
|
10
|
+
builder (~> 3.0.0)
|
11
|
+
erubis (~> 2.7.0)
|
12
|
+
journey (~> 1.0.1)
|
13
|
+
rack (~> 1.4.0)
|
14
|
+
rack-cache (~> 1.2)
|
15
|
+
rack-test (~> 0.6.1)
|
16
|
+
sprockets (~> 2.1.3)
|
17
|
+
activemodel (3.2.6)
|
18
|
+
activesupport (= 3.2.6)
|
19
|
+
builder (~> 3.0.0)
|
20
|
+
activerecord (3.2.6)
|
21
|
+
activemodel (= 3.2.6)
|
22
|
+
activesupport (= 3.2.6)
|
23
|
+
arel (~> 3.0.2)
|
24
|
+
tzinfo (~> 0.3.29)
|
25
|
+
activeresource (3.2.6)
|
26
|
+
activemodel (= 3.2.6)
|
27
|
+
activesupport (= 3.2.6)
|
28
|
+
activesupport (3.2.6)
|
29
|
+
i18n (~> 0.6)
|
30
|
+
multi_json (~> 1.0)
|
31
|
+
arel (3.0.2)
|
32
|
+
builder (3.0.0)
|
33
|
+
diff-lcs (1.1.3)
|
34
|
+
erubis (2.7.0)
|
35
|
+
hike (1.2.1)
|
36
|
+
httparty (0.9.0)
|
37
|
+
multi_json (~> 1.0)
|
38
|
+
multi_xml
|
39
|
+
i18n (0.6.0)
|
40
|
+
journey (1.0.4)
|
41
|
+
json (1.7.5)
|
42
|
+
mail (2.4.4)
|
43
|
+
i18n (>= 0.4.0)
|
44
|
+
mime-types (~> 1.16)
|
45
|
+
treetop (~> 1.4.8)
|
46
|
+
mime-types (1.19)
|
47
|
+
multi_json (1.0.4)
|
48
|
+
multi_xml (0.5.1)
|
49
|
+
polyglot (0.3.3)
|
50
|
+
rack (1.4.1)
|
51
|
+
rack-cache (1.2)
|
52
|
+
rack (>= 0.4)
|
53
|
+
rack-ssl (1.3.2)
|
54
|
+
rack
|
55
|
+
rack-test (0.6.1)
|
56
|
+
rack (>= 1.0)
|
57
|
+
rails (3.2.6)
|
58
|
+
actionmailer (= 3.2.6)
|
59
|
+
actionpack (= 3.2.6)
|
60
|
+
activerecord (= 3.2.6)
|
61
|
+
activeresource (= 3.2.6)
|
62
|
+
activesupport (= 3.2.6)
|
63
|
+
bundler (~> 1.0)
|
64
|
+
railties (= 3.2.6)
|
65
|
+
railties (3.2.6)
|
66
|
+
actionpack (= 3.2.6)
|
67
|
+
activesupport (= 3.2.6)
|
68
|
+
rack-ssl (~> 1.3.2)
|
69
|
+
rake (>= 0.8.7)
|
70
|
+
rdoc (~> 3.4)
|
71
|
+
thor (>= 0.14.6, < 2.0)
|
72
|
+
rake (0.9.2.2)
|
73
|
+
rdoc (3.12)
|
74
|
+
json (~> 1.4)
|
75
|
+
redis (3.0.1)
|
76
|
+
rspec (2.11.0)
|
77
|
+
rspec-core (~> 2.11.0)
|
78
|
+
rspec-expectations (~> 2.11.0)
|
79
|
+
rspec-mocks (~> 2.11.0)
|
80
|
+
rspec-core (2.11.1)
|
81
|
+
rspec-expectations (2.11.2)
|
82
|
+
diff-lcs (~> 1.1.3)
|
83
|
+
rspec-mocks (2.11.1)
|
84
|
+
sprockets (2.1.3)
|
85
|
+
hike (~> 1.2)
|
86
|
+
rack (~> 1.0)
|
87
|
+
tilt (~> 1.1, != 1.3.0)
|
88
|
+
thor (0.15.4)
|
89
|
+
tilt (1.3.3)
|
90
|
+
treetop (1.4.10)
|
91
|
+
polyglot
|
92
|
+
polyglot (>= 0.3.1)
|
93
|
+
tzinfo (0.3.33)
|
94
|
+
|
95
|
+
PLATFORMS
|
96
|
+
ruby
|
97
|
+
|
98
|
+
DEPENDENCIES
|
99
|
+
httparty
|
100
|
+
rails
|
101
|
+
redis
|
102
|
+
rspec
|
@@ -0,0 +1,56 @@
|
|
1
|
+
|
2
|
+
module NoDevent
|
3
|
+
class NetPublisher
|
4
|
+
include HTTParty
|
5
|
+
|
6
|
+
# HTTParty settings
|
7
|
+
headers 'ContentType' => 'application/json' ,'Accept' => 'application/json'
|
8
|
+
|
9
|
+
format :json
|
10
|
+
default_timeout 5
|
11
|
+
|
12
|
+
HOSTNAME="nodevent.com"
|
13
|
+
|
14
|
+
attr_accessor :namespace
|
15
|
+
attr_accessor :secret
|
16
|
+
attr_accessor :api_key
|
17
|
+
|
18
|
+
def initialize(opts)
|
19
|
+
self.api_key = opts["spigot.io"]["api_key"]
|
20
|
+
self.namespace = opts["namespace"]
|
21
|
+
self.secret = opts["secret"]
|
22
|
+
|
23
|
+
unless self.namespace
|
24
|
+
resp = JSON.parse generate_namespace.body
|
25
|
+
self.namespace = "/" + resp["id"]
|
26
|
+
self.secret = resp["secret"]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def publish(where, message)
|
31
|
+
req = {
|
32
|
+
:body => {
|
33
|
+
:api_key => api_key,
|
34
|
+
:event => message[:event],
|
35
|
+
:room => message[:room],
|
36
|
+
:message => message[:message]
|
37
|
+
}
|
38
|
+
}
|
39
|
+
self.class.post("http://#{HOSTNAME}/namespaces#{where}/emit",req)
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
def generate_namespace
|
44
|
+
require "socket"
|
45
|
+
hostname = Socket.gethostname
|
46
|
+
suffix = " (#{Rails.env})" if defined?(Rails)
|
47
|
+
req = {
|
48
|
+
:body => {
|
49
|
+
:api_key => api_key,
|
50
|
+
:namespace => {"name" => "#{hostname}#{suffix}"}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
self.class.post("http://#{HOSTNAME}/namespaces",req)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/nodevent/version.rb
CHANGED
data/lib/nodevent.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
require 'digest/sha2'
|
2
2
|
require 'json'
|
3
|
+
require 'redis'
|
4
|
+
require 'nodevent/net_publisher'
|
3
5
|
|
4
6
|
module NoDevent
|
7
|
+
|
5
8
|
def self.included(base)
|
6
9
|
raise "No longer supported, Please include NoDevent::Base instead"
|
7
10
|
end
|
@@ -58,10 +61,22 @@ module NoDevent
|
|
58
61
|
ActionView::Base.send :include, Helper if defined?(ActionView::Base)
|
59
62
|
|
60
63
|
module Emitter
|
61
|
-
@@config = nil
|
62
64
|
class << self
|
63
65
|
def config= obj
|
66
|
+
@@config = nil
|
67
|
+
@@publisher = nil
|
64
68
|
@@config = config.merge(obj)
|
69
|
+
if @@config.keys.include?("redis")
|
70
|
+
r_config = @@config["redis"]
|
71
|
+
|
72
|
+
@@publisher = Redis.new(:host => r_config["host"], :port => r_config["port"], :db => r_config["db"])
|
73
|
+
end
|
74
|
+
|
75
|
+
if @@config.keys.include?("api_key")
|
76
|
+
@@publisher = NoDevent::NetPublisher.new(config)
|
77
|
+
config["namespace"] = @@publisher.namespace
|
78
|
+
config["secret"] = @@publisher.secret
|
79
|
+
end
|
65
80
|
end
|
66
81
|
|
67
82
|
def config
|
@@ -72,10 +87,13 @@ module NoDevent
|
|
72
87
|
@@config
|
73
88
|
end
|
74
89
|
|
90
|
+
def publisher
|
91
|
+
@@publisher || $redis
|
92
|
+
end
|
93
|
+
|
75
94
|
def emit(room, name, message)
|
76
95
|
room = NoDevent::Emitter.room(room)
|
77
|
-
|
78
|
-
$redis.publish(@@config["namespace"],
|
96
|
+
publisher.publish(config["namespace"],
|
79
97
|
{ :room => room,
|
80
98
|
:event => name,
|
81
99
|
:message => message}.to_json)
|
@@ -91,7 +109,7 @@ module NoDevent
|
|
91
109
|
def room_key(obj, expires)
|
92
110
|
r = room(obj)
|
93
111
|
ts = (expires.to_f*1000).to_i
|
94
|
-
hash = (Digest::SHA2.new <<
|
112
|
+
hash = (Digest::SHA2.new << r << ts.to_s<< config["secret"]).to_s
|
95
113
|
"#{hash}:#{ts}"
|
96
114
|
end
|
97
115
|
end
|
data/nodevent.gemspec
CHANGED
data/spec/base_spec.rb
CHANGED
@@ -17,149 +17,202 @@ class ModelMock < ActiveRecord::Base
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
NoDevent::Emitter.config = {
|
21
|
-
"host" => "http://thehost",
|
22
|
-
"namespace" => "/nodevent",
|
23
|
-
"secret" => "asdf"
|
24
|
-
}
|
25
|
-
|
26
20
|
describe NoDevent do
|
27
|
-
describe "
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
21
|
+
describe "#publisher" do
|
22
|
+
subject {NoDevent::Emitter.publisher }
|
23
|
+
describe "with a redis publisher" do
|
24
|
+
before do
|
25
|
+
NoDevent::Emitter.config = {
|
26
|
+
"host" => "http://thehost",
|
27
|
+
"namespace" => "/nodevent",
|
28
|
+
"secret" => "asdf",
|
29
|
+
"redis" => {"host" => "localhost", "port" => 6379, "db" => 1}
|
30
|
+
}
|
31
|
+
end
|
32
|
+
it { should be_an_instance_of(Redis)}
|
33
|
+
it { should_not == $redis}
|
39
34
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
35
|
+
|
36
|
+
describe "without a publisher" do
|
37
|
+
before do
|
38
|
+
NoDevent::Emitter.config = {
|
39
|
+
"host" => "http://thehost",
|
40
|
+
"namespace" => "/nodevent",
|
41
|
+
"secret" => "asdf"
|
42
|
+
}
|
43
|
+
end
|
44
|
+
it { should be_an_instance_of($redis.class)}
|
45
|
+
it { should == $redis}
|
46
|
+
|
46
47
|
end
|
47
|
-
|
48
|
-
describe "with
|
49
|
-
before
|
50
|
-
|
48
|
+
|
49
|
+
describe "with an api_key" do
|
50
|
+
before do
|
51
|
+
NoDevent::Emitter.config = {
|
52
|
+
"host" => "http://thehost",
|
53
|
+
"namespace" => "/nodevent",
|
54
|
+
"secret" => "asdf",
|
55
|
+
"api_key"=> "bar",
|
56
|
+
}
|
57
|
+
end
|
58
|
+
it { should be_an_instance_of(NoDevent::NetPublisher)}
|
59
|
+
it { should_not == $redis}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
describe ".config=" do
|
63
|
+
describe "the class" do
|
64
|
+
before do
|
65
|
+
NoDevent::Emitter.config = {
|
66
|
+
"host" => "http://thehost",
|
67
|
+
"namespace" => "/nodevent",
|
68
|
+
"secret" => "asdf",
|
69
|
+
"redis" => {:host => "localhost", :port => 6379, :db => 1}
|
70
|
+
}
|
51
71
|
end
|
52
|
-
|
53
|
-
it { ModelMock.room.should == "
|
54
|
-
|
72
|
+
|
73
|
+
it { ModelMock.room.should == "ModelMock" }
|
74
|
+
|
55
75
|
it "should emit to the right room" do
|
56
|
-
|
76
|
+
NoDevent::Emitter.publisher.should_receive(:publish).with("/nodevent",
|
57
77
|
{
|
58
|
-
:room => "
|
59
|
-
:event => 'theevent',
|
78
|
+
:room => "ModelMock",
|
79
|
+
:event => 'theevent',
|
60
80
|
:message => 'themessage'}.to_json)
|
61
|
-
|
81
|
+
|
62
82
|
ModelMock.emit('theevent', 'themessage')
|
63
83
|
end
|
64
|
-
|
84
|
+
|
65
85
|
it "should create a key from the right room" do
|
66
86
|
t = Time.now
|
67
87
|
ts = (t.to_f*1000).to_i
|
68
|
-
ModelMock.room_key(t).should ==
|
69
|
-
(Digest::SHA2.new << ModelMock
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe "an instance of the class" do
|
75
|
-
let(:instance) {ModelMock.new( 'theparam') }
|
76
|
-
|
77
|
-
it { instance.room.should == "ModelMock_theparam" }
|
78
|
-
it "should emit to the right room" do
|
79
|
-
$redis.should_receive(:publish).with("/nodevent",
|
80
|
-
{
|
81
|
-
:room => "ModelMock_theparam",
|
82
|
-
:event => 'theevent',
|
83
|
-
:message => 'themessage'}.to_json)
|
84
|
-
|
85
|
-
instance.emit('theevent', 'themessage')
|
86
|
-
end
|
87
|
-
|
88
|
-
describe "#nodevent_create" do
|
89
|
-
it "should emit to the right room" do
|
90
|
-
$redis.should_receive(:publish).with("/nodevent",
|
91
|
-
{
|
92
|
-
:room => "ModelMock",
|
93
|
-
:event => 'create',
|
94
|
-
:message => instance}.to_json)
|
95
|
-
instance.nodevent_create
|
96
|
-
|
88
|
+
ModelMock.room_key(t).should ==
|
89
|
+
(Digest::SHA2.new << "ModelMock" << ts.to_s << NoDevent::Emitter.config["secret"]).to_s + ":" + ts.to_s
|
97
90
|
end
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
91
|
+
|
92
|
+
describe "with a custom room name" do
|
93
|
+
before do
|
94
|
+
ModelMock.stub(:room => "otherRoom")
|
95
|
+
end
|
96
|
+
|
97
|
+
it { ModelMock.room.should == "otherRoom" }
|
98
|
+
|
99
|
+
it "should emit to the right room" do
|
100
|
+
NoDevent::Emitter.publisher.should_receive(:publish).with("/nodevent",
|
101
|
+
{
|
102
|
+
:room => "otherRoom",
|
103
|
+
:event => 'theevent',
|
104
|
+
:message => 'themessage'}.to_json)
|
105
|
+
|
106
|
+
ModelMock.emit('theevent', 'themessage')
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should create a key from the right room" do
|
110
|
+
t = Time.now
|
111
|
+
ts = (t.to_f*1000).to_i
|
112
|
+
ModelMock.room_key(t).should ==
|
113
|
+
(Digest::SHA2.new << ModelMock.room << ts.to_s << NoDevent::Emitter.config["secret"]).to_s + ":" + ts.to_s
|
114
|
+
end
|
108
115
|
end
|
109
116
|
end
|
110
117
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
before do
|
120
|
-
instance.stub(:room => "otherRoom")
|
118
|
+
describe "an instance of the class" do
|
119
|
+
before do
|
120
|
+
NoDevent::Emitter.config = {
|
121
|
+
"host" => "http://thehost",
|
122
|
+
"namespace" => "/nodevent",
|
123
|
+
"secret" => "asdf",
|
124
|
+
"redis" => {:host => "localhost", :port => 6379, :db => 1}
|
125
|
+
}
|
121
126
|
end
|
122
|
-
|
123
|
-
|
124
|
-
|
127
|
+
let(:instance) {ModelMock.new( 'theparam') }
|
128
|
+
|
129
|
+
it { instance.room.should == "ModelMock_theparam" }
|
125
130
|
it "should emit to the right room" do
|
126
|
-
|
131
|
+
NoDevent::Emitter.publisher.should_receive(:publish).with("/nodevent",
|
127
132
|
{
|
128
|
-
:room => "
|
129
|
-
:event => 'theevent',
|
133
|
+
:room => "ModelMock_theparam",
|
134
|
+
:event => 'theevent',
|
130
135
|
:message => 'themessage'}.to_json)
|
131
|
-
|
136
|
+
|
132
137
|
instance.emit('theevent', 'themessage')
|
133
138
|
end
|
134
|
-
|
135
|
-
it "should create a key from the right room" do
|
136
|
-
t = Time.now
|
137
|
-
ts = (t.to_f*1000).to_i
|
138
|
-
instance.room_key(t).should ==
|
139
|
-
(Digest::SHA2.new << "otherRoom" << ts.to_s << NoDevent::Emitter.config["secret"]).to_s + ":" + ts.to_s
|
140
|
-
end
|
139
|
+
|
141
140
|
describe "#nodevent_create" do
|
142
141
|
it "should emit to the right room" do
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
142
|
+
NoDevent::Emitter.publisher.should_receive(:publish).with("/nodevent",
|
143
|
+
{
|
144
|
+
:room => "ModelMock",
|
145
|
+
:event => 'create',
|
146
|
+
:message => instance}.to_json)
|
148
147
|
instance.nodevent_create
|
149
|
-
|
148
|
+
|
150
149
|
end
|
151
150
|
end
|
152
151
|
describe "#nodevent_update" do
|
153
152
|
it "should emit to the right room" do
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
153
|
+
NoDevent::Emitter.publisher.should_receive(:publish).with("/nodevent",
|
154
|
+
{
|
155
|
+
:room => "ModelMock_theparam",
|
156
|
+
:event => 'update',
|
157
|
+
:message => instance}.to_json)
|
159
158
|
instance.nodevent_update
|
160
|
-
|
159
|
+
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should create a key from the right room" do
|
164
|
+
t = Time.now
|
165
|
+
ts = (t.to_f*1000).to_i
|
166
|
+
instance.room_key(t).should ==
|
167
|
+
(Digest::SHA2.new << instance.room << ts.to_s << NoDevent::Emitter.config["secret"]).to_s + ":" + ts.to_s
|
168
|
+
end
|
169
|
+
|
170
|
+
describe "with a custom room name" do
|
171
|
+
before do
|
172
|
+
instance.stub(:room => "otherRoom")
|
173
|
+
end
|
174
|
+
|
175
|
+
it { instance.room.should == "otherRoom" }
|
176
|
+
|
177
|
+
it "should emit to the right room" do
|
178
|
+
NoDevent::Emitter.publisher.should_receive(:publish).with("/nodevent",
|
179
|
+
{
|
180
|
+
:room => "otherRoom",
|
181
|
+
:event => 'theevent',
|
182
|
+
:message => 'themessage'}.to_json)
|
183
|
+
|
184
|
+
instance.emit('theevent', 'themessage')
|
161
185
|
end
|
162
|
-
|
186
|
+
|
187
|
+
it "should create a key from the right room" do
|
188
|
+
t = Time.now
|
189
|
+
ts = (t.to_f*1000).to_i
|
190
|
+
instance.room_key(t).should ==
|
191
|
+
(Digest::SHA2.new << "otherRoom" << ts.to_s << NoDevent::Emitter.config["secret"]).to_s + ":" + ts.to_s
|
192
|
+
end
|
193
|
+
describe "#nodevent_create" do
|
194
|
+
it "should emit to the right room" do
|
195
|
+
NoDevent::Emitter.publisher.should_receive(:publish).with("/nodevent",
|
196
|
+
{
|
197
|
+
:room => instance.class.room,
|
198
|
+
:event => 'create',
|
199
|
+
:message => instance}.to_json)
|
200
|
+
instance.nodevent_create
|
201
|
+
|
202
|
+
end
|
203
|
+
end
|
204
|
+
describe "#nodevent_update" do
|
205
|
+
it "should emit to the right room" do
|
206
|
+
NoDevent::Emitter.publisher.should_receive(:publish).with("/nodevent",
|
207
|
+
{
|
208
|
+
:room => instance.room,
|
209
|
+
:event => 'update',
|
210
|
+
:message => instance}.to_json)
|
211
|
+
instance.nodevent_update
|
212
|
+
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
163
216
|
end
|
164
|
-
|
165
|
-
|
217
|
+
end
|
218
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::NoDevent::NetPublisher do
|
4
|
+
let(:net_publisher) {NoDevent::NetPublisher.new(params)}
|
5
|
+
subject { net_publisher }
|
6
|
+
|
7
|
+
pending "a running service" do
|
8
|
+
context "without a namespace" do
|
9
|
+
let(:params) do
|
10
|
+
{
|
11
|
+
"spigot.io" => {"api_key" => "f2343b5d54557ee368a37a5d77ccd0c6"}
|
12
|
+
}
|
13
|
+
end
|
14
|
+
it "does something" do
|
15
|
+
subject.namespace.should be_present
|
16
|
+
end
|
17
|
+
context "#publish" do
|
18
|
+
subject {net_publisher.publish(net_publisher.namespace, {:room => "the_room", :event => "the_event", :message => "the_message"})}
|
19
|
+
it {should be_success}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nodevent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.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: 2012-
|
12
|
+
date: 2012-10-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 2.0.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: httparty
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.9.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.9.0
|
30
46
|
description: Write a gem description
|
31
47
|
email:
|
32
48
|
- cconstan@gmail.com
|
@@ -34,16 +50,21 @@ executables: []
|
|
34
50
|
extensions: []
|
35
51
|
extra_rdoc_files: []
|
36
52
|
files:
|
53
|
+
- .gitignore
|
54
|
+
- .rvmrc
|
37
55
|
- .travis.yml
|
38
56
|
- Gemfile
|
57
|
+
- Gemfile.lock
|
39
58
|
- LICENSE
|
40
59
|
- README.md
|
41
60
|
- Rakefile
|
42
61
|
- lib/nodevent.rb
|
62
|
+
- lib/nodevent/net_publisher.rb
|
43
63
|
- lib/nodevent/version.rb
|
44
64
|
- nodevent.gemspec
|
45
65
|
- spec/base_spec.rb
|
46
66
|
- spec/emitter_spec.rb
|
67
|
+
- spec/net_publisher_spec.rb
|
47
68
|
- spec/spec_helper.rb
|
48
69
|
homepage: https://github.com/cconstantine/NoDevent-gem
|
49
70
|
licenses: []
|
@@ -65,11 +86,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
86
|
version: '0'
|
66
87
|
requirements: []
|
67
88
|
rubyforge_project:
|
68
|
-
rubygems_version: 1.8.
|
89
|
+
rubygems_version: 1.8.24
|
69
90
|
signing_key:
|
70
91
|
specification_version: 3
|
71
92
|
summary: Write a gem summary
|
72
93
|
test_files:
|
73
94
|
- spec/base_spec.rb
|
74
95
|
- spec/emitter_spec.rb
|
96
|
+
- spec/net_publisher_spec.rb
|
75
97
|
- spec/spec_helper.rb
|