Sha256: ec510e2353b3a50d96e7432218b498ee2c4ba29135b31e7bf6f7b1dd04dae3d9

Contents?: true

Size: 989 Bytes

Versions: 2

Compression:

Stored size: 989 Bytes

Contents

require 'net/http'
require 'net/https'

module Spreedly
  class Connection

    attr_accessor :endpoint

    def initialize(endpoint)
      @endpoint = URI.parse(endpoint)
    end

    def request(method, body, headers = {})
      case method
      when :get
        http.get(endpoint.request_uri, headers)
      when :post
        http.post(endpoint.request_uri, body, headers)
      when :put
        http.put(endpoint.request_uri, body, headers)
      when :delete
        http.delete(endpoint.request_uri, headers)
      else
        raise ArgumentError, "Unsupported request method #{method.to_s.upcase}"
      end
    end

    private
    def http
      http = Net::HTTP.new(endpoint.host, endpoint.port)
      configure_ssl(http)
      http.open_timeout = 64
      http.read_timeout = 64
      http
    end

    def configure_ssl(http)
      return unless endpoint.scheme == "https"

      http.use_ssl = true
      http.verify_mode = OpenSSL::SSL::VERIFY_PEER
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spreedly-2.0.28 lib/spreedly/connection.rb
spreedly-2.0.27 lib/spreedly/connection.rb