Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.

Commit 2fe570d

Browse files
committed
raise exception when attempting to publish when server is not set
1 parent b4b9147 commit 2fe570d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/private_pub.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def publish_to(channel, data)
3030

3131
# Sends the given message hash to the Faye server using Net::HTTP.
3232
def publish_message(message)
33+
raise Error, "No server specified, ensure private_pub.yml was loaded properly." unless config[:server]
3334
Net::HTTP.post_form(URI.parse(config[:server]), :message => message.to_json)
3435
end
3536

@@ -45,7 +46,8 @@ def message(channel, data)
4546
end
4647

4748
# 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 = {})
4951
sub = {:server => config[:server], :timestamp => (Time.now.to_f * 1000).round}.merge(options)
5052
sub[:signature] = Digest::SHA1.hexdigest([config[:secret_token], sub[:channel], sub[:timestamp]].join)
5153
sub

spec/private_pub_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@
7777
PrivatePub.publish_message(message).should == :result
7878
end
7979

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+
8086
it "publish_to passes message to publish_message call" do
8187
PrivatePub.should_receive(:message).with("chan", "foo").and_return("message")
8288
PrivatePub.should_receive(:publish_message).with("message").and_return(:result)

0 commit comments

Comments
 (0)