class Bearychat::Notifier::HttpClient

Attributes

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

Public Class Methods

new(url, params) click to toggle source
# File lib/bearychat-notifier/http_client.rb, line 13
def initialize(url, params) 
  @uri = url
  @http_options = params.delete(:http_options) || {}
  @params = params
end
post(uri, params) click to toggle source
# File lib/bearychat-notifier/http_client.rb, line 6
def post(uri, params)
  HttpClient.new(uri, params).call
end

Public Instance Methods

call() click to toggle source
# File lib/bearychat-notifier/http_client.rb, line 19
def call
  http_post
end

Private Instance Methods

http_post() click to toggle source
# File lib/bearychat-notifier/http_client.rb, line 24
def http_post
  url = URI.parse(uri)
  post_obj = Net::HTTP::Post.new(url.path)
  post_obj.set_form_data(params)

  socket = Net::HTTP.new(url.host, url.port)
  socket.use_ssl = true if url.scheme.downcase == "https"
  
  http_options.each do |opt, val|
    if socket.respond_to? "#{opt}="
      socket.send "#{opt}=", val
    else
      warn "Net::HTTP doesn't respond to `#{opt}=`, ignoring that option"
    end
  end

  response = socket.start {|http| http.request(post_obj) }
end