Class: Rocket::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rocket/client.rb

Overview

This Rocket client allows for triggering events via Rocket server.

rocket = Rocket::Client.new("ws://host.com:9772", "my-app", "my53cr37k3y")
rocket['my-channel'].trigger('event', { :hello => :world })

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, app_id, secret) ⇒ Client

Returns a new instance of Client.



15
16
17
18
# File 'lib/rocket/client.rb', line 15

def initialize(url, app_id, secret)
  @url    = File.join(url, 'app', app_id) + '?secret=' + secret
  @app_id = app_id
end

Instance Attribute Details

#app_idObject (readonly)

Returns the value of attribute app_id.



12
13
14
# File 'lib/rocket/client.rb', line 12

def app_id
  @app_id
end

#secretObject (readonly)

Returns the value of attribute secret.



13
14
15
# File 'lib/rocket/client.rb', line 13

def secret
  @secret
end

#urlObject (readonly)

Returns the value of attribute url.



11
12
13
# File 'lib/rocket/client.rb', line 11

def url
  @url
end

Instance Method Details

#[](channel) ⇒ Object



26
27
28
# File 'lib/rocket/client.rb', line 26

def [](channel)
  Channel.new(self, channel)
end

#connection {|socket| ... } ⇒ Object

Yields:

  • (socket)


20
21
22
23
24
# File 'lib/rocket/client.rb', line 20

def connection(&block)
  socket = WebSocket.new(url)
  yield(socket)
  socket.close if socket && !socket.tcp_socket.closed?
end