Class: Async::Slack::Message

Inherits:
Representation show all
Defined in:
lib/async/slack/chat.rb

Direct Known Subclasses

Async::Slack::Messages::Message

Instance Method Summary collapse

Instance Method Details

#assign(value) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/async/slack/chat.rb', line 58

def assign(value)
  response = self.call(value)
  
  if body = response.read
    channel = body[:channel]
    
    if message = body[:message]
      message[:channel] ||= channel
      
      return message
    end
  end
  
  return value
end

#call(value) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/async/slack/chat.rb', line 48

def call(value)
  if value.nil?
    self.delete if self.timestamp
  elsif value.key?(:ts)
    self.with(path: 'chat.update').post(value)
  else
    self.with(path: 'chat.postMessage').post(value)
  end
end

#channelObject



28
29
30
# File 'lib/async/slack/chat.rb', line 28

def channel
  value[:channel]
end

#deleteObject



74
75
76
# File 'lib/async/slack/chat.rb', line 74

def delete
  self.with(path: 'chat.delete').post({ts: self.timestamp, channel: self.channel})
end

#inspectObject



78
79
80
# File 'lib/async/slack/chat.rb', line 78

def inspect
  "\#<#{self.class} timestamp=#{self.timestamp} text=#{self.text.inspect}>"
end

#textObject



32
33
34
# File 'lib/async/slack/chat.rb', line 32

def text
  value[:text]
end

#text=(text) ⇒ Object



36
37
38
# File 'lib/async/slack/chat.rb', line 36

def text= text
  value[:text] = text
end

#timestampObject



40
41
42
# File 'lib/async/slack/chat.rb', line 40

def timestamp
  value[:ts]
end

#usernameObject



44
45
46
# File 'lib/async/slack/chat.rb', line 44

def username
  value[:username]
end