Class: Malipopay::HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/malipopay/http_client.rb

Constant Summary collapse

BASE_URLS =
{
  production: "https://core-prod.malipopay.co.tz",
  uat: "https://core-uat.malipopay.co.tz"
}.freeze
RETRYABLE_STATUS_CODES =
[429, 500, 502, 503, 504].freeze

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, environment: :production, base_url: nil, timeout: 30, retries: 2) ⇒ HttpClient

Returns a new instance of HttpClient.



16
17
18
19
20
21
22
23
# File 'lib/malipopay/http_client.rb', line 16

def initialize(api_key:, environment: :production, base_url: nil, timeout: 30, retries: 2)
  @api_key = api_key
  @base_url = base_url || BASE_URLS.fetch(environment.to_sym) do
    raise ArgumentError, "Invalid environment: #{environment}. Use :production or :uat"
  end
  @timeout = timeout
  @retries = retries
end

Instance Method Details

#delete(path, params: {}) ⇒ Object



37
38
39
# File 'lib/malipopay/http_client.rb', line 37

def delete(path, params: {})
  execute(:delete, path, params: params)
end

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



25
26
27
# File 'lib/malipopay/http_client.rb', line 25

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

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



29
30
31
# File 'lib/malipopay/http_client.rb', line 29

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

#put(path, body: {}) ⇒ Object



33
34
35
# File 'lib/malipopay/http_client.rb', line 33

def put(path, body: {})
  execute(:put, path, body: body)
end