Class: Suc::Message

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_json(json) ⇒ Object



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

def from_json(json)
  JSON.parse(json).map{|m| new(m)}
end

.liveObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/message.rb', line 15

def live
  EM.run do
    source = EventMachine::EventSource.new(Suc.resource_url('api/flows'), {}, { authorization: Suc.token_auth })
    source.message do |message|
      message = Suc::Message.new(JSON.parse(message))
      puts message
    end
    source.start
  end
end

Instance Method Details

#body_from_userObject



2
3
4
5
6
7
# File 'lib/message.rb', line 2

def body_from_user
  Tempfile.open('suflow', '/tmp') do |f|
    system('vi', f.path)
    self.body = f.read
  end
end

#publish!Object



9
10
11
# File 'lib/message.rb', line 9

def publish!
  RestClient.post(Suc.resource_url('api/messages').to_s, { message: self.to_h } , authorization: Suc.token_auth )
end