Class: Fluent::SlackClient::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/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:



29
30
31
32
33
# File 'lib/fluent/plugin/slack_client.rb', line 29

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

Instance Attribute Details

#debug_devObject

Returns the value of attribute debug_dev.



11
12
13
# File 'lib/fluent/plugin/slack_client.rb', line 11

def debug_dev
  @debug_dev
end

#endpointObject

Returns the value of attribute endpoint.



12
13
14
# File 'lib/fluent/plugin/slack_client.rb', line 12

def endpoint
  @endpoint
end

#https_proxyObject

Returns the value of attribute https_proxy.



12
13
14
# File 'lib/fluent/plugin/slack_client.rb', line 12

def https_proxy
  @https_proxy
end

#logObject

Returns the value of attribute log.



11
12
13
# File 'lib/fluent/plugin/slack_client.rb', line 11

def log
  @log
end

Instance Method Details

#post(endpoint, params) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fluent/plugin/slack_client.rb', line 48

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

  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



44
45
46
# File 'lib/fluent/plugin/slack_client.rb', line 44

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