Class: Slack::Notifier::Util::HTTPClient

Inherits:
Object
  • Object
show all
Defined in:
lib/slack-notifier/util/http_client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, params) ⇒ HTTPClient

Returns a new instance of HTTPClient.



19
20
21
22
23
# File 'lib/slack-notifier/util/http_client.rb', line 19

def initialize uri, params
  @uri          = uri
  @http_options = params.delete(:http_options) || {}
  @params       = params
end

Instance Attribute Details

#http_optionsObject (readonly)

Returns the value of attribute http_options.



17
18
19
# File 'lib/slack-notifier/util/http_client.rb', line 17

def http_options
  @http_options
end

#paramsObject (readonly)

Returns the value of attribute params.



17
18
19
# File 'lib/slack-notifier/util/http_client.rb', line 17

def params
  @params
end

#uriObject (readonly)

Returns the value of attribute uri.



17
18
19
# File 'lib/slack-notifier/util/http_client.rb', line 17

def uri
  @uri
end

Class Method Details

.post(uri, params) ⇒ Object



12
13
14
# File 'lib/slack-notifier/util/http_client.rb', line 12

def post uri, params
  HTTPClient.new(uri, params).call
end

Instance Method Details

#callObject

rubocop:disable Layout/IndentHeredoc



26
27
28
29
30
31
32
33
34
35
# File 'lib/slack-notifier/util/http_client.rb', line 26

def call
  http_obj.request(request_obj).tap do |response|
    unless response.is_a?(Net::HTTPSuccess)
      raise Slack::Notifier::APIError, <<-MSG
The slack API returned an error: #{response.body} (HTTP Code #{response.code})
Check the "Handling Errors" section on https://api.slack.com/incoming-webhooks for more information
MSG
    end
  end
end