Module: Slatan::Mouth

Includes:
Api, Auth, Channels, Chat, Emoji, Ext, Files, Groups, Im, Mpim, Pins, Reactions, Rtm, Stars, Team, Users
Defined in:
lib/slatan/mouth.rb,
lib/slatan/mouth/im.rb,
lib/slatan/mouth/api.rb,
lib/slatan/mouth/ext.rb,
lib/slatan/mouth/rtm.rb,
lib/slatan/mouth/auth.rb,
lib/slatan/mouth/chat.rb,
lib/slatan/mouth/mpim.rb,
lib/slatan/mouth/pins.rb,
lib/slatan/mouth/team.rb,
lib/slatan/mouth/emoji.rb,
lib/slatan/mouth/files.rb,
lib/slatan/mouth/stars.rb,
lib/slatan/mouth/users.rb,
lib/slatan/mouth/groups.rb,
lib/slatan/mouth/channels.rb,
lib/slatan/mouth/ext/chat.rb,
lib/slatan/mouth/reactions.rb

Overview

send and receive message to use Slack API

Defined Under Namespace

Modules: Api, Auth, Channels, Chat, Emoji, Ext, Files, Groups, Im, Mpim, Pins, Reactions, Rtm, Stars, Team, Users

Class Method Summary collapse

Methods included from Ext::Chat

mreply, reply

Methods included from Users

get_presence, info, list, set_presence

Methods included from Team

info

Methods included from Stars

add, remove

Methods included from Rtm

start

Methods included from Reactions

add, get, list, remove

Methods included from Pins

add, remove

Methods included from Mpim

close, list, mark, open

Methods included from Im

close, history, list, mark, open

Methods included from Groups

close, history, info, list, mark, open, set_purpose, set_topic

Methods included from Files

upload

Methods included from Emoji

list

Methods included from Chat

delete, post_message, update

Methods included from Channels

history, info, list, mark, set_purpose, set_topic

Methods included from Auth

test

Methods included from Api

test

Class Method Details

.send(category, method, msg) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/slatan/mouth.rb', line 45

def send(category, method, msg)
  base_url = Spirit.slack_api_url

  msg = {
    as_user: true,
    token: Spirit.slack_token
  }.merge(msg)

  uri = URI.parse("#{base_url}/#{category}.#{method}?#{URI.encode_www_form(msg)}")

  Buttocks.debug("sent request: #{uri.request_uri}")

  request = Net::HTTP::Post.new(uri.request_uri, {
    'Content-Type' =>'application/json'
  })
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  response = http.start do |h|
    h.request(request)
  end

  body = JSON.parse(response.try(:body) || '{"ok":false, "error": " request body is empty."}', symbolize_names: true)
  Buttocks.debug("received response: #{body}")
  body
end