Sha256: d4efb01933558074f2e804b71dc05dcef1b6f688802c8cf62759d0dcfeaecf0e
Contents?: true
Size: 1.31 KB
Versions: 3
Compression:
Stored size: 1.31 KB
Contents
module SynapsePayments class Request HEADERS = { 'Accept' => 'application/json', 'User-Agent' => "SynapsePaymentsRubyGem/#{SynapsePayments::VERSION}", 'X-Ruby-Version' => RUBY_VERSION, 'X-Ruby-Platform' => RUBY_PLATFORM } def initialize(client:, method:, path:, oauth_key: nil, fingerprint: nil, json: nil) @client = client @method = method @path = path @oauth_key = oauth_key @fingerprint = fingerprint @json = json end def perform options_key = @method == :get ? :params : :json response = http_client.public_send(@method, "#{@client.api_base}#{@path}", options_key => @json) response_body = @client.symbolize_keys!(response.parse) fail_or_return_response_body(response.code, response_body) end private def http_client headers = HEADERS.merge({ 'X-SP-GATEWAY' => "#{@client.client_id}|#{@client.client_secret}", 'X-SP-USER' => "#{@oauth_key}|#{@fingerprint}", 'X-SP-USER-IP' => '' }) HTTP.headers(headers).timeout(@client.timeout_options) end def fail_or_return_response_body(code, body) if code < 200 || code >= 206 error = SynapsePayments::Error.error_from_response(body, code) fail(error) end body end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
synapse_payments-0.6.2 | lib/synapse_payments/request.rb |
synapse_payments-0.6.1 | lib/synapse_payments/request.rb |
synapse_payments-0.6.0 | lib/synapse_payments/request.rb |