Class: ScalarGalaxy::Client
- Inherits:
-
Internal::Transport::BaseClient
- Object
- Internal::Transport::BaseClient
- ScalarGalaxy::Client
- 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.
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://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
-
#api_key_cookie ⇒ String
readonly
API key browser cookie.
-
#api_key_header ⇒ String
readonly
API key request header.
-
#api_key_query ⇒ String?
readonly
API key query parameter.
-
#authentication ⇒ ScalarGalaxy::Resources::Authentication
readonly
Some endpoints are public, but some require authentication.
- #basic_auth_password ⇒ String readonly
- #basic_auth_username ⇒ String readonly
-
#bearer_auth ⇒ String
readonly
JWT Bearer token authentication.
-
#celestial_bodies ⇒ ScalarGalaxy::Resources::CelestialBodies
readonly
Celestial bodies are the planets and satellites in the Scalar Galaxy.
-
#o_auth2 ⇒ String?
readonly
OAuth 2.0 authentication.
-
#open_id_connect ⇒ String?
readonly
OpenID Connect Authentication.
-
#planets ⇒ ScalarGalaxy::Resources::Planets
readonly
Everything about planets.
-
#webhook_secret ⇒ String?
readonly
Secret used to verify incoming webhook signatures.
- #webhooks ⇒ ScalarGalaxy::Resources::Webhooks readonly
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
-
#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
constructor
Creates and returns a new client for interacting with the API.
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:
productioncorresponds tohttps://galaxy.scalar.comvoidcorresponds tohttps://void.scalar.com/
"https://api.example.com/v2/". Defaults to ENV["SCALAR_BASE_URL"]
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 = "environment must be one of #{ScalarGalaxy::Client::ENVIRONMENTS.keys}, got #{environment}" raise ArgumentError.new() 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 .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 = .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_cookie ⇒ String (readonly)
API key browser cookie
43 44 45 |
# File 'lib/galaxy-ruby/client.rb', line 43 def @api_key_cookie end |
#api_key_header ⇒ String (readonly)
API key request header
35 36 37 |
# File 'lib/galaxy-ruby/client.rb', line 35 def api_key_header @api_key_header end |
#api_key_query ⇒ String? (readonly)
API key query parameter
39 40 41 |
# File 'lib/galaxy-ruby/client.rb', line 39 def api_key_query @api_key_query end |
#authentication ⇒ ScalarGalaxy::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_password ⇒ String (readonly)
31 32 33 |
# File 'lib/galaxy-ruby/client.rb', line 31 def basic_auth_password @basic_auth_password end |
#basic_auth_username ⇒ String (readonly)
28 29 30 |
# File 'lib/galaxy-ruby/client.rb', line 28 def basic_auth_username @basic_auth_username end |
#bearer_auth ⇒ String (readonly)
JWT Bearer token authentication
25 26 27 |
# File 'lib/galaxy-ruby/client.rb', line 25 def bearer_auth @bearer_auth end |
#celestial_bodies ⇒ ScalarGalaxy::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_auth2 ⇒ String? (readonly)
OAuth 2.0 authentication
47 48 49 |
# File 'lib/galaxy-ruby/client.rb', line 47 def o_auth2 @o_auth2 end |
#open_id_connect ⇒ String? (readonly)
OpenID Connect Authentication
51 52 53 |
# File 'lib/galaxy-ruby/client.rb', line 51 def open_id_connect @open_id_connect end |
#planets ⇒ ScalarGalaxy::Resources::Planets (readonly)
Everything about planets
59 60 61 |
# File 'lib/galaxy-ruby/client.rb', line 59 def planets @planets end |
#webhook_secret ⇒ String? (readonly)
Secret used to verify incoming webhook signatures.
55 56 57 |
# File 'lib/galaxy-ruby/client.rb', line 55 def webhook_secret @webhook_secret end |
#webhooks ⇒ ScalarGalaxy::Resources::Webhooks (readonly)
71 72 73 |
# File 'lib/galaxy-ruby/client.rb', line 71 def webhooks @webhooks end |