Class: Sinatra::Slack::Helpers::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/slack/helpers/channel.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Channel

Returns a new instance of Channel.



7
8
9
10
11
# File 'lib/sinatra/slack/helpers/channel.rb', line 7

def initialize(opts = {})
  @id = opts["channel_id"]
  @name = opts["channel_name"]
  @url = opts["response_url"]
end

Class Method Details

.parse(params) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/sinatra/slack/helpers/channel.rb', line 27

def self.parse(params)
  payload = params.clone
  if payload["payload"]
    payload = JSON.parse(payload["payload"])
    payload["channel_id"] = payload.dig("channel", "id")
    payload["channel_name"] = payload.dig("channel", "name")
  end

  self.new(payload)
end

Instance Method Details

#send(response) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/sinatra/slack/helpers/channel.rb', line 13

def send(response)
  options = {
    headers: {
      "Content-type": "application/json"
    },
    body: response.to_json
  }
  HTTParty.post(@url, options)
end

#to_sObject



23
24
25
# File 'lib/sinatra/slack/helpers/channel.rb', line 23

def to_s
  "Slack Channel: #{@name}"
end