Class: Paymongo::PaymongoClient

Inherits:
Object
  • Object
show all
Defined in:
lib/paymongo/paymongo_client.rb

Class Method Summary collapse

Class Method Details

.execute_request(method:, params: {}, path:) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/paymongo/paymongo_client.rb', line 3

def self.execute_request(method:, params: {}, path:)
  uri = URI("#{Paymongo.config.api_base_url}/#{Paymongo.config.api_version}/#{path}")

  request = self.initiate_request(method: method, params: params, uri: uri)

  request.basic_auth Paymongo.config.api_key, ''

  response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
    http.request(request)
  end

  self.handle_error(response) unless self.successful?(response)

  json_response_body = JSON.parse(response.body)

  Paymongo::ApiResource.new(json_response_body)
end