class Scalingo::CoreClient
Attributes
config[R]
Public Class Methods
new(attributes = {})
click to toggle source
# File lib/scalingo/core_client.rb, line 14 def initialize(attributes = {}) @config = Configuration.new(attributes, Scalingo.config) end
Public Instance Methods
auth()
click to toggle source
Sub-clients accessors
# File lib/scalingo/core_client.rb, line 32 def auth raise NotImplementedError end
authenticate_with(access_token: nil, bearer_token: nil, expires_at: nil)
click to toggle source
Authentication helpers / Token management
# File lib/scalingo/core_client.rb, line 45 def authenticate_with(access_token: nil, bearer_token: nil, expires_at: nil) if !access_token && !bearer_token raise ArgumentError, "You must supply one of `access_token` or `bearer_token`" end if access_token && bearer_token raise ArgumentError, "You cannot supply both `access_token` and `bearer_token`" end if expires_at && !bearer_token raise ArgumentError, "`expires_at` can only be used with `bearer_token`. `access_token` have a 1 hour expiration." end if access_token expiration = Time.now + config.exchanged_token_validity response = auth.tokens.exchange(access_token) if response.successful? self.token = BearerToken.new( response.data[:token], expires_at: expiration, raise_on_expired: config.raise_on_expired_token, ) end return response.successful? end if bearer_token authenticate_with_bearer_token( bearer_token, expires_at: expires_at, raise_on_expired_token: config.raise_on_expired_token, ) true end end
billing()
click to toggle source
# File lib/scalingo/core_client.rb, line 36 def billing raise NotImplementedError end
inspect()
click to toggle source
# File lib/scalingo/core_client.rb, line 18 def inspect str = %(<#{self.class}:0x#{object_id.to_s(16)} version:"#{Scalingo::VERSION}" authenticated:) str << if token.present? (token.expired? ? "expired" : "true") else "false" end str << ">" str end
region(name = nil)
click to toggle source
# File lib/scalingo/core_client.rb, line 40 def region(name = nil) public_send(name || config.default_region) end