Class: Alerty::Plugin::Slack::SlackClient::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/alerty/plugin/slack/slack_client.rb

Overview

The base framework of slack client

Direct Known Subclasses

IncomingWebhook, Slackbot, WebApi

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint = nil, https_proxy = nil) ⇒ Base

Returns a new instance of Base.

Parameters:



48
49
50
51
52
# File 'lib/alerty/plugin/slack/slack_client.rb', line 48

def initialize(endpoint = nil, https_proxy = nil)
  self.endpoint    = endpoint    if endpoint
  self.https_proxy = https_proxy if https_proxy
  @log = Logger.new(nil)
end

Instance Attribute Details

#debug_devObject

Returns the value of attribute debug_dev.



30
31
32
# File 'lib/alerty/plugin/slack/slack_client.rb', line 30

def debug_dev
  @debug_dev
end

#endpointObject

Returns the value of attribute endpoint.



31
32
33
# File 'lib/alerty/plugin/slack/slack_client.rb', line 31

def endpoint
  @endpoint
end

#https_proxyObject

Returns the value of attribute https_proxy.



31
32
33
# File 'lib/alerty/plugin/slack/slack_client.rb', line 31

def https_proxy
  @https_proxy
end

#logObject

Returns the value of attribute log.



30
31
32
# File 'lib/alerty/plugin/slack/slack_client.rb', line 30

def log
  @log
end

Instance Method Details

#post(endpoint, params) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/alerty/plugin/slack/slack_client.rb', line 67

def post(endpoint, params)
  http = proxy_class.new(endpoint.host, endpoint.port)
  http.use_ssl = (endpoint.scheme == 'https')
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  http.set_debug_output(debug_dev) if debug_dev
  # http.open_timeout = # default: 60s
  # http.read_timeout = # default: 60s

  req = Net::HTTP::Post.new(endpoint.request_uri)
  req['Host'] = endpoint.host
  req['Accept'] = 'application/json; charset=utf-8'
  req['User-Agent'] = 'fluent-plugin-slack'
  req.body = encode_body(params)

  res = http.request(req)
  response_check(res, params)
end

#proxy_classObject



63
64
65
# File 'lib/alerty/plugin/slack/slack_client.rb', line 63

def proxy_class
  @proxy_class ||= Net::HTTP
end