Class: Cpro::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/cpro/configuration.rb

Constant Summary collapse

ENVIRONMENTS =
{
  sandbox: {
    api_host: "https://sandbox-api.piste.gouv.fr",
    token_url: "https://sandbox-oauth.piste.gouv.fr/api/oauth/token"
  },
  production: {
    api_host: "https://api.piste.gouv.fr",
    token_url: "https://oauth.piste.gouv.fr/api/oauth/token"
  }
}.freeze
DEFAULT_SCOPE =
"openid"
DEFAULT_TIMEOUT =
30
DEFAULT_OPEN_TIMEOUT =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



23
24
25
26
27
28
29
30
# File 'lib/cpro/configuration.rb', line 23

def initialize
  @environment = :sandbox
  @scope = DEFAULT_SCOPE
  @timeout = DEFAULT_TIMEOUT
  @open_timeout = DEFAULT_OPEN_TIMEOUT
  @adapter = Faraday.default_adapter
  @token_provider = nil
end

Instance Attribute Details

#accountObject

Returns the value of attribute account.



20
21
22
# File 'lib/cpro/configuration.rb', line 20

def 
  @account
end

#adapterObject

Returns the value of attribute adapter.



20
21
22
# File 'lib/cpro/configuration.rb', line 20

def adapter
  @adapter
end

#client_idObject

Returns the value of attribute client_id.



21
22
23
# File 'lib/cpro/configuration.rb', line 21

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



21
22
23
# File 'lib/cpro/configuration.rb', line 21

def client_secret
  @client_secret
end

#environmentObject

Returns the value of attribute environment.



21
22
23
# File 'lib/cpro/configuration.rb', line 21

def environment
  @environment
end

#loggerObject

Returns the value of attribute logger.



20
21
22
# File 'lib/cpro/configuration.rb', line 20

def logger
  @logger
end

#open_timeoutObject

Returns the value of attribute open_timeout.



20
21
22
# File 'lib/cpro/configuration.rb', line 20

def open_timeout
  @open_timeout
end

#scopeObject

Returns the value of attribute scope.



21
22
23
# File 'lib/cpro/configuration.rb', line 21

def scope
  @scope
end

#timeoutObject

Returns the value of attribute timeout.



20
21
22
# File 'lib/cpro/configuration.rb', line 20

def timeout
  @timeout
end

Instance Method Details

#api_hostObject



62
63
64
# File 'lib/cpro/configuration.rb', line 62

def api_host
  ENVIRONMENTS.fetch(environment).fetch(:api_host)
end

#token_providerObject



32
33
34
# File 'lib/cpro/configuration.rb', line 32

def token_provider
  @token_provider ||= Auth::TokenProvider.new(self)
end

#token_urlObject



66
67
68
# File 'lib/cpro/configuration.rb', line 66

def token_url
  ENVIRONMENTS.fetch(environment).fetch(:token_url)
end

#validate!Object

Raises:



70
71
72
73
74
75
# File 'lib/cpro/configuration.rb', line 70

def validate!
  raise ConfigurationError, "client_id est requis" if blank?(client_id)
  raise ConfigurationError, "client_secret est requis" if blank?(client_secret)

  self
end