Sha256: eba64e041e7ac08064ccb154a2bfc8cac2cd5e845eba3d97b0fdeff7f00e4301

Contents?: true

Size: 809 Bytes

Versions: 1

Compression:

Stored size: 809 Bytes

Contents

# encoding: utf-8
require 'json'
require 'net/http'
require 'net/https'

# @api private
module Pagerduty::HttpTransport
  extend self

  HOST = "events.pagerduty.com"
  PORT = 443
  PATH = "/generic/2010-04-15/create_event.json"

  def send(payload = {})
    response = post payload.to_json
    response.error! unless transported?(response)
    JSON.parse(response.body)
  end

private

  def post(payload)
    post = Net::HTTP::Post.new(PATH)
    post.body = payload
    http.request(post)
  end

  def http
    http = Net::HTTP.new(HOST, PORT)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_PEER
    http.open_timeout = 60
    http.read_timeout = 60
    http
  end

  def transported?(response)
    response.kind_of? Net::HTTPSuccess or response.kind_of? Net::HTTPRedirection
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pagerduty-2.0.0 lib/pagerduty/http_transport.rb