module GogoKit::Configuration

Configuration options for {GogoKit::Client} or falls back to {GogoKit::Default}

Attributes

access_token[RW]
api_root_endpoint[RW]
authorization_endpoint[RW]
client_id[RW]
client_secret[RW]
oauth_token_endpoint[RW]

Public Instance Methods

api_environment() click to toggle source

Gets the current API environment in use

@return [Symbol] @raise [GogoKit::Error::ConfigurationError] Error is raised when supplied environment is not :production or :sandbox.

# File lib/gogokit/configuration.rb, line 28
def api_environment
  @api_environment
end
api_environment=(api_environment) click to toggle source

Sets the API environment to be used. Setting this value will configure the values for {GogoKit::Configuration#api_root_endpoint}, {GogoKit::Configuration#oauth_token_endpoint} and {GogoKit::Configuration#authorization_endpoint}. See developer.viagogo.net/#sandbox-environment

# File lib/gogokit/configuration.rb, line 37
def api_environment=(api_environment)
  @api_environment = api_environment.to_sym
  validate_configuration_api_environment!

  self.api_root_endpoint =
    GogoKit::Default::API_ROOT_ENDPOINTS[@api_environment]
  self.oauth_token_endpoint =
    GogoKit::Default::OAUTH_TOKEN_ENDPOINTS[@api_environment]
  self.authorization_endpoint =
    GogoKit::Default::AUTHORIZATION_ENDPOINTS[@api_environment]
end
reset!() click to toggle source

Reset configuration options to default values

# File lib/gogokit/configuration.rb, line 16
def reset!
  keys.each do |key|
    instance_variable_set(:"@#{key}", GogoKit::Default.send(key))
  end
  self
end

Private Instance Methods

credentials() click to toggle source

@return [Hash]

# File lib/gogokit/configuration.rb, line 64
def credentials
  {
    client_id: client_id,
    client_secret: client_secret,
    access_token: access_token
  }
end
endpoints() click to toggle source
# File lib/gogokit/configuration.rb, line 72
def endpoints
  {
    api_root_endpoint: api_root_endpoint,
    oauth_token_endpoint: oauth_token_endpoint,
    authorization_endpoint: authorization_endpoint
  }
end
keys() click to toggle source
# File lib/gogokit/configuration.rb, line 51
def keys
  @keys ||= [
    :client_id,
    :client_secret,
    :access_token,
    :api_environment,
    :api_root_endpoint,
    :oauth_token_endpoint,
    :authorization_endpoint
  ]
end
validate_configuration_api_environment!() click to toggle source
# File lib/gogokit/configuration.rb, line 104
def validate_configuration_api_environment!
  return if api_environment.nil? ||
            api_environment == :production ||
            api_environment == :sandbox

  raise(ConfigurationError,
        'Invalid api_environment specified: ' \
        "#{api_environment.inspect} must be :production or :sandbox")
end
validate_configuration_credentials!() click to toggle source

Ensures that all credentials set during configuration are of a valid type. Valid types are String and Symbol.

@raise [GogoKit::Error::ConfigurationError] Error is raised when supplied credentials are not a String or Symbol.

# File lib/gogokit/configuration.rb, line 85
def validate_configuration_credentials!
  credentials.each do |credential, value|
    next if value.nil? || value.is_a?(String) || value.is_a?(Symbol)
    raise(ConfigurationError,
          "Invalid #{credential} specified: #{value.inspect} must be a" \
          ' string or symbol.')
  end
end
validate_configuration_endpoints!() click to toggle source
# File lib/gogokit/configuration.rb, line 94
def validate_configuration_endpoints!
  endpoints.each do |endpoint, value|
    next if !value.nil? && value =~ /\A#{URI.regexp}\z/

    raise(ConfigurationError,
          "Invalid #{endpoint} specified: " \
          "#{value.inspect} must be a valid URL")
  end
end