Class: Privy::Client

Inherits:
Internal::Transport::BaseClient show all
Defined in:
lib/privy/client.rb

Constant Summary collapse

DEFAULT_MAX_RETRIES =

Default max number of retries to attempt after a failed retryable request.

2
DEFAULT_TIMEOUT_IN_SECONDS =

Default per-request timeout.

60.0
DEFAULT_INITIAL_RETRY_DELAY =

Default initial retry delay in seconds. Overall delay is calculated using exponential backoff + jitter.

0.5
DEFAULT_MAX_RETRY_DELAY =

Default max retry delay in seconds.

8.0
ENVIRONMENTS =

rubocop:disable Style/MutableConstant

{production: "https://api.privy.io", staging: "https://api.staging.privy.io"}

Constants inherited from Internal::Transport::BaseClient

Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS

Instance Attribute Summary collapse

Attributes inherited from Internal::Transport::BaseClient

#base_url, #headers, #idempotency_header, #initial_retry_delay, #max_retries, #max_retry_delay, #requester, #timeout

Instance Method Summary collapse

Methods inherited from Internal::Transport::BaseClient

follow_redirect, #inspect, reap_connection!, #request, #send_request, should_retry?, validate!

Methods included from Internal::Util::SorbetRuntimeSupport

#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type

Constructor Details

#initialize(app_id: , app_secret: , environment: nil, base_url: , max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY) ⇒ Client

Creates and returns a new client for interacting with the API.

Each environment maps to a different base URL:

‘“api.example.com/v2/”`. Defaults to `ENV`

Parameters:

  • app_id (String, nil) (defaults to: )

    App secret authentication. Defaults to ‘ENV`

  • app_secret (String, nil) (defaults to: )

    App secret authentication. Defaults to ‘ENV`

  • environment (:production, :staging, nil) (defaults to: nil)

    Specifies the environment to use for the API.

  • base_url (String, nil) (defaults to: )

    Override the default base URL for the API, e.g.,

  • max_retries (Integer) (defaults to: self.class::DEFAULT_MAX_RETRIES)

    Max number of retries to attempt after a failed retryable request.

  • timeout (Float) (defaults to: self.class::DEFAULT_TIMEOUT_IN_SECONDS)
  • initial_retry_delay (Float) (defaults to: self.class::DEFAULT_INITIAL_RETRY_DELAY)
  • max_retry_delay (Float) (defaults to: self.class::DEFAULT_MAX_RETRY_DELAY)


132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/privy/client.rb', line 132

def initialize(
  app_id: ENV["PRIVY_APP_ID"],
  app_secret: ENV["PRIVY_APP_SECRET"],
  environment: nil,
  base_url: ENV["PRIVY_API_BASE_URL"],
  max_retries: self.class::DEFAULT_MAX_RETRIES,
  timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
  initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
  max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY
)
  base_url ||= Privy::Client::ENVIRONMENTS.fetch(environment&.to_sym || :production) do
    message = "environment must be one of #{Privy::Client::ENVIRONMENTS.keys}, got #{environment}"
    raise ArgumentError.new(message)
  end

  if app_id.nil?
    raise ArgumentError.new("app_id is required, and can be set via environ: \"PRIVY_APP_ID\"")
  end
  if app_secret.nil?
    raise ArgumentError.new("app_secret is required, and can be set via environ: \"PRIVY_APP_SECRET\"")
  end

  headers = {
    "privy-app-id" => (@app_id = app_id.to_s)
  }
  custom_headers_env = ENV["PRIVY_API_CUSTOM_HEADERS"]
  unless custom_headers_env.nil?
    parsed = {}
    custom_headers_env.split("\n").each do |line|
      colon = line.index(":")
      unless colon.nil?
        parsed[line[0...colon].strip] = line[(colon + 1)..].strip
      end
    end
    headers = parsed.merge(headers)
  end

  @app_secret = app_secret.to_s

  super(
    base_url: base_url,
    timeout: timeout,
    max_retries: max_retries,
    initial_retry_delay: initial_retry_delay,
    max_retry_delay: max_retry_delay,
    headers: headers
  )

  @wallets = Privy::Resources::Wallets.new(client: self)
  @users = Privy::Resources::Users.new(client: self)
  @policies = Privy::Resources::Policies.new(client: self)
  @transactions = Privy::Resources::Transactions.new(client: self)
  @key_quorums = Privy::Resources::KeyQuorums.new(client: self)
  @intents = Privy::Resources::Intents.new(client: self)
  @apps = Privy::Resources::Apps.new(client: self)
  @webhooks = Privy::Resources::Webhooks.new(client: self)
  @accounts = Privy::Resources::Accounts.new(client: self)
  @aggregations = Privy::Resources::Aggregations.new(client: self)
  @embedded_wallets = Privy::Resources::EmbeddedWallets.new(client: self)
  @analytics = Privy::Resources::Analytics.new(client: self)
  @client_auth = Privy::Resources::ClientAuth.new(client: self)
  @funding = Privy::Resources::Funding.new(client: self)
  @organizations = Privy::Resources::Organizations.new(client: self)
  @cross_app = Privy::Resources::CrossApp.new(client: self)
  @shared = Privy::Resources::Shared.new(client: self)
  @wallet_actions = Privy::Resources::WalletActions.new(client: self)
  @yield_ = Privy::Resources::Yield.new(client: self)
  @kraken_embed = Privy::Resources::KrakenEmbed.new(client: self)
  @swaps = Privy::Resources::Swaps.new(client: self)
end

Instance Attribute Details

#accountsPrivy::Resources::Accounts (readonly)



61
62
63
# File 'lib/privy/client.rb', line 61

def accounts
  @accounts
end

#aggregationsPrivy::Resources::Aggregations (readonly)



64
65
66
# File 'lib/privy/client.rb', line 64

def aggregations
  @aggregations
end

#analyticsPrivy::Resources::Analytics (readonly)



70
71
72
# File 'lib/privy/client.rb', line 70

def analytics
  @analytics
end

#app_idString (readonly)

App secret authentication.

Returns:

  • (String)


25
26
27
# File 'lib/privy/client.rb', line 25

def app_id
  @app_id
end

#app_secretString (readonly)

App secret authentication.

Returns:

  • (String)


29
30
31
# File 'lib/privy/client.rb', line 29

def app_secret
  @app_secret
end

#appsPrivy::Resources::Apps (readonly)

Operations related to app settings and allowlist management



55
56
57
# File 'lib/privy/client.rb', line 55

def apps
  @apps
end

#client_authPrivy::Resources::ClientAuth (readonly)



73
74
75
# File 'lib/privy/client.rb', line 73

def client_auth
  @client_auth
end

#cross_appPrivy::Resources::CrossApp (readonly)



82
83
84
# File 'lib/privy/client.rb', line 82

def cross_app
  @cross_app
end

#embedded_walletsPrivy::Resources::EmbeddedWallets (readonly)



67
68
69
# File 'lib/privy/client.rb', line 67

def embedded_wallets
  @embedded_wallets
end

#fundingPrivy::Resources::Funding (readonly)



76
77
78
# File 'lib/privy/client.rb', line 76

def funding
  @funding
end

#intentsPrivy::Resources::Intents (readonly)



51
52
53
# File 'lib/privy/client.rb', line 51

def intents
  @intents
end

#key_quorumsPrivy::Resources::KeyQuorums (readonly)

Operations related to key quorums



48
49
50
# File 'lib/privy/client.rb', line 48

def key_quorums
  @key_quorums
end

#kraken_embedPrivy::Resources::KrakenEmbed (readonly)



94
95
96
# File 'lib/privy/client.rb', line 94

def kraken_embed
  @kraken_embed
end

#organizationsPrivy::Resources::Organizations (readonly)



79
80
81
# File 'lib/privy/client.rb', line 79

def organizations
  @organizations
end

#policiesPrivy::Resources::Policies (readonly)

Operations related to policies



40
41
42
# File 'lib/privy/client.rb', line 40

def policies
  @policies
end

#sharedPrivy::Resources::Shared (readonly)



85
86
87
# File 'lib/privy/client.rb', line 85

def shared
  @shared
end

#swapsPrivy::Resources::Swaps (readonly)



97
98
99
# File 'lib/privy/client.rb', line 97

def swaps
  @swaps
end

#transactionsPrivy::Resources::Transactions (readonly)

Operations related to transactions



44
45
46
# File 'lib/privy/client.rb', line 44

def transactions
  @transactions
end

#usersPrivy::Resources::Users (readonly)

Operations related to users



36
37
38
# File 'lib/privy/client.rb', line 36

def users
  @users
end

#wallet_actionsPrivy::Resources::WalletActions (readonly)



88
89
90
# File 'lib/privy/client.rb', line 88

def wallet_actions
  @wallet_actions
end

#walletsPrivy::Resources::Wallets (readonly)



32
33
34
# File 'lib/privy/client.rb', line 32

def wallets
  @wallets
end

#webhooksPrivy::Resources::Webhooks (readonly)



58
59
60
# File 'lib/privy/client.rb', line 58

def webhooks
  @webhooks
end

#yield_Privy::Resources::Yield (readonly)



91
92
93
# File 'lib/privy/client.rb', line 91

def yield_
  @yield_
end