Class: PayOS::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/payOS/client.rb', line 5

def initialize(config)
  @config = config
  @http_client = Faraday.new(url: BASE_URL) do |faraday|
    # Set default headers
    faraday.headers["Content-Type"] = "application/json"
    faraday.headers["x-client-id"] = config.client_id
    faraday.headers["x-api-key"] = config.api_key
    faraday.headers["x-partner-code"] = config.partner_code

    # Add middleware for JSON parsing
    faraday.request :json
    faraday.response :json

    # Add middleware for logging (optional)
    # faraday.response :logger if config.debug_mode

    # Use default adapter
    faraday.adapter Faraday.default_adapter
  end
end

Instance Method Details

#get(path) ⇒ Object



34
35
36
37
# File 'lib/payOS/client.rb', line 34

def get(path)
  response = @http_client.get(path)
  handle_response(response)
end

#post(path, payload) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/payOS/client.rb', line 26

def post(path, payload)
  response = @http_client.post(path) do |req|
    req.body = payload.to_json
  end

  handle_response(response)
end