class SlackMsgr::Chat

Handles all chat functionality and methods corresponding with Slack API

Constants

CHAT_METHODS
PERMITTED_ARGUMENTS
REQUIRED_ARGUMENTS

Attributes

body[R]
method[R]
opts[R]

Public Class Methods

call(method, opts = {}) click to toggle source
# File lib/slack_msgr/chat.rb, line 30
def call(method, opts = {})
  chat = new(method, opts)
  send_post_request_to_slack(chat)
end
new(method, opts) click to toggle source
# File lib/slack_msgr/chat.rb, line 40
def initialize(method, opts)
  chat_method = CHAT_METHODS[method]
  ErrorHandling.raise(:unknown_method, method: method) unless chat_method

  @method = "chat.#{chat_method}"
  @opts   = opts
  @body   = sanitize_body
end

Private Instance Methods

req_args_missing?() click to toggle source
# File lib/slack_msgr/chat.rb, line 60
def req_args_missing?
  !(REQUIRED_ARGUMENTS - opts.keys).empty?
end
sanitize_body() click to toggle source
# File lib/slack_msgr/chat.rb, line 51
def sanitize_body
  ErrorHandling.raise(:req_args_missing, req_args: REQUIRED_ARGUMENTS, method: method) if req_args_missing?

  opts.keys.each_with_object({}) do |key, body|
    body[key] ||= opts[key] if PERMITTED_ARGUMENTS.include?(key)
    body
  end.to_json
end