Module: Justifi::APIOperations::ClassMethods

Included in:
JustifiOperations, OAuth::OAuthOperations
Defined in:
lib/justifi/api_operations.rb

Instance Method Summary collapse

Instance Method Details

#execute_get_request(path, query, headers) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
# File 'lib/justifi/api_operations.rb', line 17

def execute_get_request(path, query, headers)
  raise ArgumentError, "query should be a string" if query && !query.is_a?(String)
  raise ArgumentError, "headers should be a hash" if headers && !headers.is_a?(Hash)

  path = "#{path}?#{query}"
  response = execute_request(:get, path, nil, headers)

  JustifiObject.construct_from(path, response, headers)
end

#execute_patch_request(path, body, headers) ⇒ Object

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
34
# File 'lib/justifi/api_operations.rb', line 27

def execute_patch_request(path, body, headers)
  raise ArgumentError, "body should be a string" if body && !body.is_a?(String)
  raise ArgumentError, "headers should be a hash" if headers && !headers.is_a?(Hash)

  response = execute_request(:patch, path, body, headers)

  JustifiObject.construct_from(path, response, headers)
end

#execute_post_request(path, body, headers) ⇒ Object

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
# File 'lib/justifi/api_operations.rb', line 8

def execute_post_request(path, body, headers)
  raise ArgumentError, "body should be a string" if body && !body.is_a?(String)
  raise ArgumentError, "headers should be a hash" if headers && !headers.is_a?(Hash)

  response = execute_request(:post, path, body, headers)

  JustifiObject.construct_from(path, response, headers)
end

#http_connection(path) ⇒ Object



98
99
100
101
# File 'lib/justifi/api_operations.rb', line 98

def http_connection(path)
  uri = URI("#{Justifi.api_url}#{path}")
  Net::HTTP.start(uri.host, uri.port, use_ssl: true)
end

#idempotently_request(path, method:, params:, headers:, idempotency_key: nil) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/justifi/api_operations.rb', line 36

def idempotently_request(path, method:, params:, headers:, idempotency_key: nil)
  idempotency_key ||= Justifi.get_idempotency_key
  headers[:idempotency_key] = idempotency_key

  retryable_request do
    send("execute_#{method}_request", path, params, headers)
  end
end