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.



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

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.



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

def http_options
  @http_options
end

#paramsObject (readonly)

Returns the value of attribute params.



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

def params
  @params
end

#uriObject (readonly)

Returns the value of attribute uri.



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

def uri
  @uri
end

Class Method Details

.post(uri, params) ⇒ Object



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

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

Instance Method Details

#callObject



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