Sha256: f1a461d8f71f157ae4e3551c0d6d977ba0d5bff62b3c428588f099544edc618f
Contents?: true
Size: 1.16 KB
Versions: 7
Compression:
Stored size: 1.16 KB
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) when :options http.request(OptionsWithResponseBody.new(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) http.open_timeout = 64 http.read_timeout = 64 http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_PEER http.ca_file = File.dirname(__FILE__) + '/../certs/cacert.pem' http end end class OptionsWithResponseBody < Net::HTTPRequest METHOD = 'OPTIONS' REQUEST_HAS_BODY = false RESPONSE_HAS_BODY = true end end
Version data entries
7 entries across 7 versions & 1 rubygems