Class: Cpro::Configuration
- Inherits:
-
Object
- Object
- Cpro::Configuration
- 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
-
#account ⇒ Object
Returns the value of attribute account.
-
#adapter ⇒ Object
Returns the value of attribute adapter.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #api_host ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #token_provider ⇒ Object
- #token_url ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize ⇒ Configuration
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
#account ⇒ Object
Returns the value of attribute account.
20 21 22 |
# File 'lib/cpro/configuration.rb', line 20 def account @account end |
#adapter ⇒ Object
Returns the value of attribute adapter.
20 21 22 |
# File 'lib/cpro/configuration.rb', line 20 def adapter @adapter end |
#client_id ⇒ Object
Returns the value of attribute client_id.
21 22 23 |
# File 'lib/cpro/configuration.rb', line 21 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
21 22 23 |
# File 'lib/cpro/configuration.rb', line 21 def client_secret @client_secret end |
#environment ⇒ Object
Returns the value of attribute environment.
21 22 23 |
# File 'lib/cpro/configuration.rb', line 21 def environment @environment end |
#logger ⇒ Object
Returns the value of attribute logger.
20 21 22 |
# File 'lib/cpro/configuration.rb', line 20 def logger @logger end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
20 21 22 |
# File 'lib/cpro/configuration.rb', line 20 def open_timeout @open_timeout end |
#scope ⇒ Object
Returns the value of attribute scope.
21 22 23 |
# File 'lib/cpro/configuration.rb', line 21 def scope @scope end |
#timeout ⇒ Object
Returns the value of attribute timeout.
20 21 22 |
# File 'lib/cpro/configuration.rb', line 20 def timeout @timeout end |
Instance Method Details
#api_host ⇒ Object
62 63 64 |
# File 'lib/cpro/configuration.rb', line 62 def api_host ENVIRONMENTS.fetch(environment).fetch(:api_host) end |
#token_provider ⇒ Object
32 33 34 |
# File 'lib/cpro/configuration.rb', line 32 def token_provider @token_provider ||= Auth::TokenProvider.new(self) end |
#token_url ⇒ Object
66 67 68 |
# File 'lib/cpro/configuration.rb', line 66 def token_url ENVIRONMENTS.fetch(environment).fetch(:token_url) end |
#validate! ⇒ Object
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 |