class Afterpay::Client
Client
object acting as the connection Enables the Client
to call get/post/patch/delete
Constants
- BASE_URL
- SANDBOX_BASE_URL
Public Class Methods
auth_token()
click to toggle source
Auth requires format to be Base64 encoded `<app_id>:<secret>`
# File lib/afterpay/client.rb, line 30 def self.auth_token auth_str = "#{Afterpay.config.app_id}:#{Afterpay.config.secret}" Base64.strict_encode64(auth_str) end
new(connection = nil)
click to toggle source
# File lib/afterpay/client.rb, line 35 def initialize(connection = nil) @connection = connection || default_connection end
server_url()
click to toggle source
Decides which URL to use based on env
# File lib/afterpay/client.rb, line 24 def self.server_url Afterpay.env == "sandbox" ? SANDBOX_BASE_URL : BASE_URL end
Public Instance Methods
default_connection()
click to toggle source
The connection object
# File lib/afterpay/client.rb, line 40 def default_connection # Use local thread to keep connection open to make use of connection reuse. Thread.current[:afterpay_default_connection] ||= Faraday.new(url: self.class.server_url) do |conn| conn.use ErrorMiddleware if Afterpay.config.raise_errors conn.authorization "Basic", self.class.auth_token conn.headers["User-Agent"] = "#{Afterpay.config.afterpay_plugin} (#{Afterpay.config.platform}; #{Afterpay.config.system_information}; Merchant/#{Afterpay.config.app_id}) #{Afterpay.config.merchant_website_url}" conn.request :json conn.response :json, content_type: "application/json", parser_options: { symbolize_names: true } conn.adapter Faraday.default_adapter end end