This repository was archived by the owner on Dec 12, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ def publish_to(channel, data)
30
30
31
31
# Sends the given message hash to the Faye server using Net::HTTP.
32
32
def publish_message ( message )
33
+ raise Error , "No server specified, ensure private_pub.yml was loaded properly." unless config [ :server ]
33
34
Net ::HTTP . post_form ( URI . parse ( config [ :server ] ) , :message => message . to_json )
34
35
end
35
36
@@ -45,7 +46,8 @@ def message(channel, data)
45
46
end
46
47
47
48
# Returns a subscription hash to pass to the PrivatePub.sign call in JavaScript.
48
- def subscription
49
+ # Any options passed are merged to the hash.
50
+ def subscription ( options = { } )
49
51
sub = { :server => config [ :server ] , :timestamp => ( Time . now . to_f * 1000 ) . round } . merge ( options )
50
52
sub [ :signature ] = Digest ::SHA1 . hexdigest ( [ config [ :secret_token ] , sub [ :channel ] , sub [ :timestamp ] ] . join )
51
53
sub
Original file line number Diff line number Diff line change 77
77
PrivatePub . publish_message ( message ) . should == :result
78
78
end
79
79
80
+ it "raises an exception if no server is specified when calling publish_message" do
81
+ lambda {
82
+ PrivatePub . publish_message ( "foo" )
83
+ } . should raise_error ( PrivatePub ::Error )
84
+ end
85
+
80
86
it "publish_to passes message to publish_message call" do
81
87
PrivatePub . should_receive ( :message ) . with ( "chan" , "foo" ) . and_return ( "message" )
82
88
PrivatePub . should_receive ( :publish_message ) . with ( "message" ) . and_return ( :result )
You can’t perform that action at this time.
0 commit comments