Class: Bearychat::Incoming

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

Constant Summary collapse

DEFAULT_PARAMS =
{
  text: "text, this field may accept markdown",
  markdown: true,
  channel: "",
  attachments: []
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hook, info = {}) ⇒ Incoming



17
18
19
20
# File 'lib/bearychat/incoming.rb', line 17

def initialize(hook, info={})
  @http_client = HttpClient.new(hook)
  super(DEFAULT_PARAMS.merge(info))
end

Instance Attribute Details

#http_clientObject (readonly)

Returns the value of attribute http_client.



15
16
17
# File 'lib/bearychat/incoming.rb', line 15

def http_client
  @http_client
end

Instance Method Details

#reset(info) ⇒ Object



22
23
24
25
# File 'lib/bearychat/incoming.rb', line 22

def reset(info)
  info.each { |key, value| self[key] = value }
  self
end

#send(body = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/bearychat/incoming.rb', line 27

def send(body = {})
  if block_given?
    yield self
    send()
  elsif !body.empty?
    http_client.post_json(body.to_json)
  else
    http_client.post_json(as_json)
  end
end

#switch(channel) ⇒ Object



38
39
40
41
# File 'lib/bearychat/incoming.rb', line 38

def switch(channel)
  self.channel = channel
  self
end