Class: GasfreeSdk::Client
- Inherits:
-
Object
- Object
- GasfreeSdk::Client
- Defined in:
- lib/gasfree_sdk/client.rb
Overview
Client for interacting with the GasFree API
Instance Attribute Summary collapse
-
#connection ⇒ Faraday::Connection
readonly
The HTTP client.
Instance Method Summary collapse
-
#address(account_address) ⇒ GasFreeAddress
Get GasFree account info.
-
#initialize ⇒ Client
constructor
Initialize a new GasFree client.
-
#providers ⇒ Array<Provider>
Get all service providers.
-
#submit_transfer(request) ⇒ TransferResponse
Submit a GasFree transfer.
-
#tokens ⇒ Array<Token>
Get all supported tokens.
-
#transfer_status(trace_id) ⇒ TransferResponse
Get transfer status.
Constructor Details
#initialize ⇒ Client
Initialize a new GasFree client
15 16 17 18 19 20 21 22 23 |
# File 'lib/gasfree_sdk/client.rb', line 15 def initialize @connection = Faraday.new(url: GasfreeSdk.config.api_endpoint) do |f| f.request :json f.request :retry, GasfreeSdk.config. f.response :json f.adapter Faraday.default_adapter f.response :logger, ::Logger.new($stdout), bodies: true if ENV["DEBUG_GASFREE_SDK"] end end |
Instance Attribute Details
#connection ⇒ Faraday::Connection (readonly)
Returns The HTTP client.
12 13 14 |
# File 'lib/gasfree_sdk/client.rb', line 12 def connection @connection end |
Instance Method Details
#address(account_address) ⇒ GasFreeAddress
Get GasFree account info
46 47 48 49 |
# File 'lib/gasfree_sdk/client.rb', line 46 def address(account_address) response = get("api/v1/address/#{account_address}") Models::GasFreeAddress.new(transform_address_data(response["data"])) end |
#providers ⇒ Array<Provider>
Get all service providers
36 37 38 39 40 41 |
# File 'lib/gasfree_sdk/client.rb', line 36 def providers response = get("api/v1/config/provider/all") response.dig("data", "providers").map do |provider| Models::Provider.new(transform_provider_data(provider)) end end |
#submit_transfer(request) ⇒ TransferResponse
Submit a GasFree transfer
54 55 56 57 |
# File 'lib/gasfree_sdk/client.rb', line 54 def submit_transfer(request) response = post("api/v1/gasfree/submit", transform_transfer_request_data(request.to_h)) Models::TransferResponse.new(transform_transfer_response_data(response["data"])) end |
#tokens ⇒ Array<Token>
Get all supported tokens
27 28 29 30 31 32 |
# File 'lib/gasfree_sdk/client.rb', line 27 def tokens response = get("api/v1/config/token/all") response.dig("data", "tokens").map do |token| Models::Token.new(transform_token_data(token)) end end |
#transfer_status(trace_id) ⇒ TransferResponse
Get transfer status
62 63 64 65 |
# File 'lib/gasfree_sdk/client.rb', line 62 def transfer_status(trace_id) response = get("api/v1/gasfree/#{trace_id}") Models::TransferResponse.new(transform_transfer_response_data(response["data"])) end |