Class: ZaiPayment::Client

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

Overview

Base API client that handles HTTP requests to Zai API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config: nil, token_provider: nil, base_endpoint: nil) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
# File 'lib/zai_payment/client.rb', line 10

def initialize(config: nil, token_provider: nil, base_endpoint: nil)
  @config = config || ZaiPayment.config
  @token_provider = token_provider || ZaiPayment.auth
  @base_endpoint = base_endpoint
end

Instance Attribute Details

#base_endpointObject (readonly)

Returns the value of attribute base_endpoint.



8
9
10
# File 'lib/zai_payment/client.rb', line 8

def base_endpoint
  @base_endpoint
end

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/zai_payment/client.rb', line 8

def config
  @config
end

#token_providerObject (readonly)

Returns the value of attribute token_provider.



8
9
10
# File 'lib/zai_payment/client.rb', line 8

def token_provider
  @token_provider
end

Instance Method Details

#delete(path) ⇒ Response

Perform a DELETE request

Parameters:

  • path (String)

    the API endpoint path

Returns:



47
48
49
# File 'lib/zai_payment/client.rb', line 47

def delete(path)
  request(:delete, path)
end

#get(path, params: {}) ⇒ Response

Perform a GET request

Parameters:

  • path (String)

    the API endpoint path

  • params (Hash) (defaults to: {})

    query parameters

Returns:



21
22
23
# File 'lib/zai_payment/client.rb', line 21

def get(path, params: {})
  request(:get, path, params: params)
end

#patch(path, body: {}) ⇒ Response

Perform a PATCH request

Parameters:

  • path (String)

    the API endpoint path

  • body (Hash) (defaults to: {})

    request body

Returns:



39
40
41
# File 'lib/zai_payment/client.rb', line 39

def patch(path, body: {})
  request(:patch, path, body: body)
end

#post(path, body: {}) ⇒ Response

Perform a POST request

Parameters:

  • path (String)

    the API endpoint path

  • body (Hash) (defaults to: {})

    request body

Returns:



30
31
32
# File 'lib/zai_payment/client.rb', line 30

def post(path, body: {})
  request(:post, path, body: body)
end