Class: MicroFire

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

Constant Summary collapse

VERSION =
'1.0.1'

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, token, room) ⇒ MicroFire

Returns a new instance of MicroFire.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/micro_fire.rb', line 30

def initialize uri, token, room
  @stream = self.class.stream
  @json   = self.class.json
  @token  = token
  @http   = Net::HTTP::Persistent.new
  # Don't do anything if not supported by net/http/persistent version or
  # socket.so. Helps when they deploy.
  if @http.respond_to? :socket_options
    @http.socket_options << [Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1]
  end
  @pass   = 'x'
  @uri    = find_uri uri
  @room   = find_room room
end

Class Attribute Details

.jsonObject

Returns the value of attribute json.



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

def json
  @json
end

.streamObject

Returns the value of attribute stream.



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

def stream
  @stream
end

Instance Attribute Details

#httpObject (readonly)

Returns the value of attribute http.



27
28
29
# File 'lib/micro_fire.rb', line 27

def http
  @http
end

#jsonObject

Returns the value of attribute json.



28
29
30
# File 'lib/micro_fire.rb', line 28

def json
  @json
end

#passObject

Returns the value of attribute pass.



28
29
30
# File 'lib/micro_fire.rb', line 28

def pass
  @pass
end

#roomObject (readonly)

Returns the value of attribute room.



27
28
29
# File 'lib/micro_fire.rb', line 27

def room
  @room
end

#streamObject

Returns the value of attribute stream.



28
29
30
# File 'lib/micro_fire.rb', line 28

def stream
  @stream
end

#tokenObject (readonly)

Returns the value of attribute token.



27
28
29
# File 'lib/micro_fire.rb', line 27

def token
  @token
end

#uriObject (readonly)

Returns the value of attribute uri.



27
28
29
# File 'lib/micro_fire.rb', line 27

def uri
  @uri
end

Instance Method Details

#join(&block) ⇒ Object



45
46
47
48
# File 'lib/micro_fire.rb', line 45

def join &block
  req action('join'), &block
  self
end

#speak(message, &block) ⇒ Object



50
51
52
53
# File 'lib/micro_fire.rb', line 50

def speak message, &block
  req action('speak'), :message => { :body => message }, &block
  self
end

#watch(&block) ⇒ Object



55
56
57
58
# File 'lib/micro_fire.rb', line 55

def watch &block
  req action('live'), {}, :Get, stream, &block
  self
end