class Pagerduty::HttpTransport

@private

Constants

HOST
PORT

Public Class Methods

new(config) click to toggle source
# File lib/pagerduty/http_transport.rb, line 13
def initialize(config)
  @path = config.fetch(:path)
  @proxy = config[:proxy] || {}
end

Public Instance Methods

send_payload(payload) click to toggle source
# File lib/pagerduty/http_transport.rb, line 18
def send_payload(payload)
  response = post(payload.to_json)
  response.error! unless transported?(response)
  JSON.parse(response.body)
end

Private Instance Methods

http() click to toggle source
# File lib/pagerduty/http_transport.rb, line 32
def http
  http = http_proxy.new(HOST, PORT)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
  http.open_timeout = 60
  http.read_timeout = 60
  http
end
http_proxy() click to toggle source
# File lib/pagerduty/http_transport.rb, line 41
def http_proxy
  Net::HTTP.Proxy(
    @proxy[:host],
    @proxy[:port],
    @proxy[:username],
    @proxy[:password],
  )
end
post(payload) click to toggle source
# File lib/pagerduty/http_transport.rb, line 26
def post(payload)
  post = Net::HTTP::Post.new(@path)
  post.body = payload
  http.request(post)
end
transported?(response) click to toggle source
# File lib/pagerduty/http_transport.rb, line 50
def transported?(response)
  response.is_a?(Net::HTTPSuccess) || response.is_a?(Net::HTTPRedirection)
end