Class: ScalarGalaxy::Client

Inherits:
Internal::Transport::BaseClient show all
Defined in:
lib/galaxy-ruby/client.rb,
sig/galaxy-ruby/client.rbs

Constant Summary collapse

DEFAULT_MAX_RETRIES =

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

Returns:

  • (2)
2
DEFAULT_TIMEOUT_IN_SECONDS =

Default per-request timeout.

Returns:

  • (Float)
60.0
DEFAULT_INITIAL_RETRY_DELAY =

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

Returns:

  • (Float)
0.5
DEFAULT_MAX_RETRY_DELAY =

Default max retry delay in seconds.

Returns:

  • (Float)
8.0
ENVIRONMENTS =

rubocop:disable Style/MutableConstant

Returns:

  • ({)
{production: "https://galaxy.scalar.com", void: "https://void.scalar.com/"}

Constants inherited from Internal::Transport::BaseClient

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

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(bearer_auth: , basic_auth_username: , basic_auth_password: , api_key_header: , api_key_query: , api_key_cookie: , o_auth2: , open_id_connect: , webhook_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.

ENV["SCALAR_WEBHOOK_SECRET"]

Each environment maps to a different base URL:

  • production corresponds to https://galaxy.scalar.com
  • void corresponds to https://void.scalar.com/

"https://api.example.com/v2/". Defaults to ENV["SCALAR_BASE_URL"]

Parameters:

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

    JWT Bearer token authentication Defaults to ENV["BEARER_AUTH"]

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

    Defaults to ENV["BASIC_AUTH_USERNAME"]

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

    Defaults to ENV["BASIC_AUTH_PASSWORD"]

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

    API key request header Defaults to ENV["API_KEY_HEADER"]

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

    API key query parameter Defaults to ENV["API_KEY_QUERY"]

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

    API key browser cookie Defaults to ENV["API_KEY_COOKIE"]

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

    OAuth 2.0 authentication Defaults to ENV["SCALAR_O_AUTH2"]

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

    OpenID Connect Authentication Defaults to ENV["SCALAR_OPEN_ID_CONNECT"]

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

    Secret used to verify incoming webhook signatures. Defaults to

  • environment (:production, :void, 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)


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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/galaxy-ruby/client.rb', line 172

def initialize(
  bearer_auth: ENV["BEARER_AUTH"],
  basic_auth_username: ENV["BASIC_AUTH_USERNAME"],
  basic_auth_password: ENV["BASIC_AUTH_PASSWORD"],
  api_key_header: ENV["API_KEY_HEADER"],
  api_key_query: ENV["API_KEY_QUERY"],
  api_key_cookie: ENV["API_KEY_COOKIE"],
  o_auth2: ENV["SCALAR_O_AUTH2"],
  open_id_connect: ENV["SCALAR_OPEN_ID_CONNECT"],
  webhook_secret: ENV["SCALAR_WEBHOOK_SECRET"],
  environment: nil,
  base_url: ENV["SCALAR_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 ||=
    ScalarGalaxy::Client::ENVIRONMENTS.fetch(environment&.to_sym || :production) do
      message =
        "environment must be one of #{ScalarGalaxy::Client::ENVIRONMENTS.keys}, got #{environment}"
      raise ArgumentError.new(message)
    end

  if bearer_auth.nil?
    raise ArgumentError.new("bearer_auth is required, and can be set via environ: \"BEARER_AUTH\"")
  end
  if basic_auth_username.nil?
    raise ArgumentError.new(
      "basic_auth_username is required, and can be set via environ: \"BASIC_AUTH_USERNAME\""
    )
  end
  if basic_auth_password.nil?
    raise ArgumentError.new(
      "basic_auth_password is required, and can be set via environ: \"BASIC_AUTH_PASSWORD\""
    )
  end
  if api_key_header.nil?
    raise ArgumentError.new("api_key_header is required, and can be set via environ: \"API_KEY_HEADER\"")
  end
  if api_key_cookie.nil?
    raise ArgumentError.new("api_key_cookie is required, and can be set via environ: \"API_KEY_COOKIE\"")
  end

  headers = {}
  custom_headers_env = ENV["SCALAR_CUSTOM_HEADERS"]
  unless custom_headers_env.nil?
    parsed = {}
    custom_headers_env
      .split("\n")
      .each do |line|
        colon = line.index(":")
        parsed[line[0...colon].strip] = line[(colon + 1)..].strip unless colon.nil?
      end
    headers = parsed.merge(headers)
  end

  @bearer_auth = bearer_auth.to_s
  @basic_auth_username = basic_auth_username.to_s
  @basic_auth_password = basic_auth_password.to_s
  @api_key_header = api_key_header.to_s
  @api_key_query = api_key_query&.to_s
  @api_key_cookie = api_key_cookie.to_s
  @o_auth2 = o_auth2&.to_s
  @open_id_connect = open_id_connect&.to_s
  @webhook_secret = webhook_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
  )

  @planets = ScalarGalaxy::Resources::Planets.new(client: self)
  @celestial_bodies = ScalarGalaxy::Resources::CelestialBodies.new(client: self)
  @authentication = ScalarGalaxy::Resources::Authentication.new(client: self)
  @webhooks = ScalarGalaxy::Resources::Webhooks.new(client: self)
end

Instance Attribute Details

API key browser cookie

Returns:

  • (String)


43
44
45
# File 'lib/galaxy-ruby/client.rb', line 43

def api_key_cookie
  @api_key_cookie
end

#api_key_headerString (readonly)

API key request header

Returns:

  • (String)


35
36
37
# File 'lib/galaxy-ruby/client.rb', line 35

def api_key_header
  @api_key_header
end

#api_key_queryString? (readonly)

API key query parameter

Returns:

  • (String, nil)


39
40
41
# File 'lib/galaxy-ruby/client.rb', line 39

def api_key_query
  @api_key_query
end

#authenticationScalarGalaxy::Resources::Authentication (readonly)

Some endpoints are public, but some require authentication. We provide all the required endpoints to create an account and authorize yourself.



68
69
70
# File 'lib/galaxy-ruby/client.rb', line 68

def authentication
  @authentication
end

#basic_auth_passwordString (readonly)

Returns:

  • (String)


31
32
33
# File 'lib/galaxy-ruby/client.rb', line 31

def basic_auth_password
  @basic_auth_password
end

#basic_auth_usernameString (readonly)

Returns:

  • (String)


28
29
30
# File 'lib/galaxy-ruby/client.rb', line 28

def basic_auth_username
  @basic_auth_username
end

#bearer_authString (readonly)

JWT Bearer token authentication

Returns:

  • (String)


25
26
27
# File 'lib/galaxy-ruby/client.rb', line 25

def bearer_auth
  @bearer_auth
end

#celestial_bodiesScalarGalaxy::Resources::CelestialBodies (readonly)

Celestial bodies are the planets and satellites in the Scalar Galaxy.



63
64
65
# File 'lib/galaxy-ruby/client.rb', line 63

def celestial_bodies
  @celestial_bodies
end

#o_auth2String? (readonly)

OAuth 2.0 authentication

Returns:

  • (String, nil)


47
48
49
# File 'lib/galaxy-ruby/client.rb', line 47

def o_auth2
  @o_auth2
end

#open_id_connectString? (readonly)

OpenID Connect Authentication

Returns:

  • (String, nil)


51
52
53
# File 'lib/galaxy-ruby/client.rb', line 51

def open_id_connect
  @open_id_connect
end

#planetsScalarGalaxy::Resources::Planets (readonly)

Everything about planets



59
60
61
# File 'lib/galaxy-ruby/client.rb', line 59

def planets
  @planets
end

#webhook_secretString? (readonly)

Secret used to verify incoming webhook signatures.

Returns:

  • (String, nil)


55
56
57
# File 'lib/galaxy-ruby/client.rb', line 55

def webhook_secret
  @webhook_secret
end

#webhooksScalarGalaxy::Resources::Webhooks (readonly)



71
72
73
# File 'lib/galaxy-ruby/client.rb', line 71

def webhooks
  @webhooks
end