Class: Slack::Notifier::Util::HTTPClient
- Inherits:
-
Object
- Object
- Slack::Notifier::Util::HTTPClient
- Defined in:
- lib/slack-notifier/util/http_client.rb
Instance Attribute Summary collapse
-
#http_options ⇒ Object
readonly
Returns the value of attribute http_options.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
Instance Method Summary collapse
-
#call ⇒ Object
rubocop:disable Layout/IndentHeredoc.
-
#initialize(uri, params) ⇒ HTTPClient
constructor
A new instance of HTTPClient.
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_options ⇒ Object (readonly)
Returns the value of attribute http_options.
17 18 19 |
# File 'lib/slack-notifier/util/http_client.rb', line 17 def @http_options end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
17 18 19 |
# File 'lib/slack-notifier/util/http_client.rb', line 17 def params @params end |
#uri ⇒ Object (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
#call ⇒ Object
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 |