Class: NoDevent::NetPublisher
- Inherits:
-
Object
- Object
- NoDevent::NetPublisher
- Includes:
- HTTParty
- Defined in:
- lib/nodevent/net_publisher.rb
Constant Summary collapse
- HOSTNAME =
"nodevent.com"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#secret ⇒ Object
Returns the value of attribute secret.
Instance Method Summary collapse
- #generate_namespace ⇒ Object
-
#initialize(opts) ⇒ NetPublisher
constructor
A new instance of NetPublisher.
- #publish(where, message) ⇒ Object
Constructor Details
#initialize(opts) ⇒ NetPublisher
Returns a new instance of NetPublisher.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/nodevent/net_publisher.rb', line 18 def initialize(opts) self.api_key = opts["spigot.io"]["api_key"] self.namespace = opts["namespace"] self.secret = opts["secret"] unless self.namespace resp = JSON.parse generate_namespace.body self.namespace = "/" + resp["id"] self.secret = resp["secret"] end end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
16 17 18 |
# File 'lib/nodevent/net_publisher.rb', line 16 def api_key @api_key end |
#namespace ⇒ Object
Returns the value of attribute namespace.
14 15 16 |
# File 'lib/nodevent/net_publisher.rb', line 14 def namespace @namespace end |
#secret ⇒ Object
Returns the value of attribute secret.
15 16 17 |
# File 'lib/nodevent/net_publisher.rb', line 15 def secret @secret end |
Instance Method Details
#generate_namespace ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/nodevent/net_publisher.rb', line 43 def generate_namespace require "socket" hostname = Socket.gethostname suffix = " (#{Rails.env})" if defined?(Rails) req = { :body => { :api_key => api_key, :namespace => {"name" => "#{hostname}#{suffix}"} } } self.class.post("http://#{HOSTNAME}/namespaces",req) end |
#publish(where, message) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/nodevent/net_publisher.rb', line 30 def publish(where, ) req = { :body => { :api_key => api_key, :event => [:event], :room => [:room], :message => [:message] } } self.class.post("http://#{HOSTNAME}/namespaces#{where}/emit",req) end |