Class: Pay::Asaas::ApiClient

Inherits:
Object
  • Object
show all
Defined in:
lib/pay/asaas/client.rb

Defined Under Namespace

Classes: ApiError, Configuration, ConfigurationError, Error

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject



25
26
27
# File 'lib/pay/asaas/client.rb', line 25

def configuration
  @configuration ||= Configuration.new
end

Class Method Details

.allObject



55
56
57
# File 'lib/pay/asaas/client.rb', line 55

def all
  request(:get, resource_key)
end

.configure {|configuration| ... } ⇒ Object

Yields:



29
30
31
# File 'lib/pay/asaas/client.rb', line 29

def configure
  yield(configuration)
end

.create(params:) ⇒ Object



59
60
61
# File 'lib/pay/asaas/client.rb', line 59

def create(params:)
  request(:post, resource_key, body: params.to_json)
end

.find(id:) ⇒ Object



67
68
69
# File 'lib/pay/asaas/client.rb', line 67

def find(id:)
  request(:get, "#{resource_key}/#{id}")
end

.headersObject



33
34
35
36
37
38
39
# File 'lib/pay/asaas/client.rb', line 33

def headers
  {
    access_token: configuration.api_key,
    "content-type": "application/json",
    accept: "application/json",
  }
end

.request(method, path, options = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/pay/asaas/client.rb', line 45

def request(method, path, options = {})
  configuration.validate!
  response = HTTParty.send(
    method,
    "#{configuration.base_url}/#{path}",
    { headers: headers }.merge(options),
  )
  handle_response(response)
end

.resource_keyObject

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/pay/asaas/client.rb', line 41

def resource_key
  raise NotImplementedError, "You must implement the resource_key method"
end

.update(id:, params:) ⇒ Object



63
64
65
# File 'lib/pay/asaas/client.rb', line 63

def update(id:, params:)
  request(:put, "#{resource_key}/#{id}", body: params.to_json)
end