Module: GasfreeSdk

Extended by:
Dry::Configurable
Defined in:
lib/gasfree_sdk.rb,
lib/gasfree_sdk/types.rb,
lib/gasfree_sdk/base58.rb,
lib/gasfree_sdk/client.rb,
lib/gasfree_sdk/crypto.rb,
lib/gasfree_sdk/errors.rb,
lib/gasfree_sdk/models.rb,
lib/gasfree_sdk/version.rb,
lib/gasfree_sdk/models/token.rb,
lib/gasfree_sdk/models/provider.rb,
lib/gasfree_sdk/tron_eip712_signer.rb,
lib/gasfree_sdk/models/gas_free_address.rb,
lib/gasfree_sdk/models/transfer_request.rb,
lib/gasfree_sdk/models/transfer_response.rb

Overview

GasFree SDK error classes and utilities

Defined Under Namespace

Modules: Base58, Crypto, Models, Types Classes: APIError, AddressNotFoundError, AuthenticationError, Client, DeadlineExceededError, Error, InsufficientBalanceError, InvalidSignatureError, TransferNotFoundError, TronEIP712Signer

Constant Summary collapse

ERROR_CODE_MAP =

Map error codes to specific error classes

{
  "INVALID_SIGNATURE" => InvalidSignatureError,
  "DEADLINE_EXCEEDED" => DeadlineExceededError,
  "INSUFFICIENT_BALANCE" => InsufficientBalanceError,
  "ADDRESS_NOT_FOUND" => AddressNotFoundError,
  "TRANSFER_NOT_FOUND" => TransferNotFoundError
}.freeze
VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.build_error(code:, reason:, message:) ⇒ Error

Factory method to create appropriate error instances

Parameters:

  • code (String)

    Error code from API

  • reason (String)

    Error reason from API

  • message (String)

    Error message from API

Returns:

  • (Error)

    Appropriate error instance



52
53
54
55
# File 'lib/gasfree_sdk/errors.rb', line 52

def build_error(code:, reason:, message:)
  error_class = determine_error_class(code, reason)
  error_class.new(message, code: code, reason: reason)
end

.clientGasfreeSdk::Client

Create a new client instance

Returns:



53
54
55
# File 'lib/gasfree_sdk.rb', line 53

def client
  @client ||= Client.new
end

.configure {|config| ... } ⇒ Object

Configure the SDK

Examples:

GasfreeSdk.configure do |config|
  config.api_key = "your-api-key"
  config.api_secret = "your-api-secret"
  config.api_endpoint = "https://open.gasfree.io/tron/"
end

Yields:

  • (config)

    Configuration block



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

def configure
  yield config
end

.reset_client!void

This method returns an undefined value.

Reset the client instance



59
60
61
# File 'lib/gasfree_sdk.rb', line 59

def reset_client!
  @client = nil
end