class Spreedly::Connection

Attributes

endpoint[RW]

Public Class Methods

new(endpoint) click to toggle source
# File lib/spreedly/connection.rb, line 9
def initialize(endpoint)
  @endpoint = URI.parse(endpoint)
end

Public Instance Methods

request(method, body, headers = {}) click to toggle source
# File lib/spreedly/connection.rb, line 13
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)
  when :options
    http.request(OptionsWithResponseBody.new(endpoint.request_uri, headers))
  else
    raise ArgumentError, "Unsupported request method #{method.to_s.upcase}"
  end
end

Private Instance Methods

configure_ssl(http) click to toggle source
# File lib/spreedly/connection.rb, line 39
def configure_ssl(http)
  return unless endpoint.scheme == "https"

  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
end
http() click to toggle source
# File lib/spreedly/connection.rb, line 31
def http
  http = Net::HTTP.new(endpoint.host, endpoint.port)
  configure_ssl(http)
  http.open_timeout = 64
  http.read_timeout = 64
  http
end