lib/private_pub.rb in private_pub-1.0.1 vs lib/private_pub.rb in private_pub-1.0.2
- old
+ new
@@ -29,10 +29,17 @@
end
# Sends the given message hash to the Faye server using Net::HTTP.
def publish_message(message)
raise Error, "No server specified, ensure private_pub.yml was loaded properly." unless config[:server]
- Net::HTTP.post_form(URI.parse(config[:server]), :message => message.to_json)
+ url = URI.parse(config[:server])
+
+ form = Net::HTTP::Post.new(url.path.empty? ? '/' : url.path)
+ form.set_form_data(:message => message.to_json)
+
+ http = Net::HTTP.new(url.host, url.port)
+ http.use_ssl = url.scheme == "https"
+ http.start {|h| h.request(form)}
end
# Returns a message hash for sending to Faye
def message(channel, data)
message = {:channel => channel, :data => {:channel => channel}, :ext => {:private_pub_token => config[:secret_token]}}