Module: SparkApi::Configuration

Includes:
OAuth2Configurable
Included in:
SparkApi, MultiClient
Defined in:
lib/spark_api/configuration.rb,
lib/spark_api/configuration/yaml.rb,
lib/spark_api/configuration/oauth2_configurable.rb

Defined Under Namespace

Modules: OAuth2Configurable Classes: YamlConfig

Constant Summary collapse

VALID_OPTION_KEYS =

valid configuration options

[:api_key, :api_secret, :api_user, :endpoint, 
:user_agent, :version, :ssl, :ssl_verify, :oauth2_provider, :authentication_mode, 
:auth_endpoint, :callback, :compress, :timeout, :middleware, :dictionary_version, :request_id_chain, :user_ip_address].freeze
OAUTH2_KEYS =
[:authorization_uri, :access_uri, :client_id, :client_secret,
  # Requirements for authorization_code grant type
  :redirect_uri,  
  # Requirements for password grant type
  :username, :password,
  # Requirements for single session keys
  :access_token,
  :sparkbar_uri
]
DEFAULT_API_KEY =
nil
DEFAULT_API_SECRET =
nil
DEFAULT_API_USER =
nil
DEFAULT_ENDPOINT =
'https://api.sparkapi.com'
DEFAULT_REDIRECT_URI =
"https://sparkplatform.com/oauth2/callback"
DEFAULT_AUTH_ENDPOINT =

Ignored for Spark API Auth

'https://sparkplatform.com/openid'
DEFAULT_AUTHORIZATION_URI =
'https://sparkplatform.com/oauth2'
DEFAULT_VERSION =
'v1'
DEFAULT_ACCESS_URI =
"#{DEFAULT_ENDPOINT}/#{DEFAULT_VERSION}/oauth2/grant"
DEFAULT_SESSION_PATH =
"/#{DEFAULT_VERSION}/session"
DEFAULT_USER_AGENT =
"Spark API Ruby Gem #{VERSION}"
DEFAULT_SSL =
true
DEFAULT_SSL_VERIFY =
true
DEFAULT_OAUTH2 =
nil
DEFAULT_COMPRESS =
false
DEFAULT_TIMEOUT =

seconds

5
DEFAULT_MIDDLEWARE =
'spark_api'
DEFAULT_DICTIONARY_VERSION =
nil
DEFAULT_REQUEST_ID_CHAIN =
nil
DEFAULT_USER_IP_ADDRESS =
nil
X_SPARK_API_USER_AGENT =
"X-SparkApi-User-Agent"
X_USER_IP_ADDRESS =
"X-User-IP-Address"

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OAuth2Configurable

#convert_to_oauth2?, #grant_uri, #oauth2_enabled?, #oauthify!

Class Method Details

.extended(base) ⇒ Object



60
61
62
# File 'lib/spark_api/configuration.rb', line 60

def self.extended(base)
  base.reset_configuration
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



55
56
57
58
# File 'lib/spark_api/configuration.rb', line 55

def configure
  yield(self)
  oauthify! if convert_to_oauth2?
end

#optionsObject



64
65
66
67
68
# File 'lib/spark_api/configuration.rb', line 64

def options
  VALID_OPTION_KEYS.inject({}) do |opt,key|
    opt.merge(key => send(key))
  end
end

#reset_configurationObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/spark_api/configuration.rb', line 70

def reset_configuration
  self.api_key     = DEFAULT_API_KEY
  self.api_secret  = DEFAULT_API_SECRET
  self.api_user    = DEFAULT_API_USER
  self.authentication_mode = SparkApi::Authentication::ApiAuth
  self.auth_endpoint  = DEFAULT_AUTH_ENDPOINT
  self.endpoint    = DEFAULT_ENDPOINT
  self.oauth2_provider = DEFAULT_OAUTH2
  self.user_agent  = DEFAULT_USER_AGENT
  self.ssl         = DEFAULT_SSL
  self.ssl_verify  = DEFAULT_SSL_VERIFY
  self.version     = DEFAULT_VERSION
  self.compress    = DEFAULT_COMPRESS
  self.timeout     = DEFAULT_TIMEOUT
  self.middleware = DEFAULT_MIDDLEWARE
  self.dictionary_version = DEFAULT_DICTIONARY_VERSION
  self.request_id_chain = DEFAULT_REQUEST_ID_CHAIN
  self.user_ip_address = DEFAULT_USER_IP_ADDRESS
  self
end