class FDE::Slack::Util::HTTPClient

Attributes

http_options[R]
params[R]
uri[R]

Public Class Methods

new(uri, params) click to toggle source
# File lib/slack/util/http_client.rb, line 36
def initialize uri, params
  @uri          = uri
  @http_options = params.delete(:http_options) || {}
  @params       = params
end
post(uri, params) click to toggle source
# File lib/slack/util/http_client.rb, line 29
def post uri, params
  HTTPClient.new(uri, params).call
end

Public Instance Methods

call() click to toggle source
# File lib/slack/util/http_client.rb, line 42
def call
  http_obj.request(request_obj).tap do |response|
    unless response.is_a?(Net::HTTPSuccess)
      raise FDE::Slack::APIError.new(response)
    end
  end
end

Private Instance Methods

http_obj() click to toggle source
# File lib/slack/util/http_client.rb, line 59
def http_obj
  http = Net::HTTP.new uri.host, uri.port
  http.use_ssl = (uri.scheme == "https")

  http_options.each do |opt, val|
    if http.respond_to? "#{opt}="
      http.send "#{opt}=", val
    else
      warn "Net::HTTP doesn't respond to `#{opt}=`, ignoring that option"
    end
  end

  http
end
request_obj() click to toggle source
# File lib/slack/util/http_client.rb, line 52
def request_obj
  req = Net::HTTP::Post.new uri.request_uri
  req.set_form_data params

  req
end