Class: GasfreeSdk::Client

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

Overview

Client for interacting with the GasFree API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

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.retry_options
    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

#connectionFaraday::Connection (readonly)

Returns The HTTP client.

Returns:

  • (Faraday::Connection)

    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

Parameters:

  • account_address (String)

    The user’s EOA address

Returns:

  • (GasFreeAddress)

    The GasFree account info



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

def address()
  response = get("api/v1/address/#{}")
  Models::GasFreeAddress.new(transform_address_data(response["data"]))
end

#providersArray<Provider>

Get all service providers

Returns:

  • (Array<Provider>)

    List of 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

Parameters:

  • request (TransferRequest)

    The transfer request

Returns:

  • (TransferResponse)

    The transfer response



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

#tokensArray<Token>

Get all supported tokens

Returns:

  • (Array<Token>)

    List of 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

Parameters:

  • trace_id (String)

    The transfer trace ID

Returns:

  • (TransferResponse)

    The 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