Class: Fakturoid::Config
- Inherits:
-
Object
- Object
- Fakturoid::Config
- Defined in:
- lib/fakturoid/config.rb
Constant Summary collapse
- SUPPORTED_FLOWS =
%w[authorization_code client_credentials].freeze
- API_ENDPOINT =
"https://app.fakturoid.cz/api/v3"
- OAUTH_ENDPOINT =
API_ENDPOINT = “app.fakturoid.localhost/api/v3” # For development purposes
"#{API_ENDPOINT}/oauth".freeze
Instance Attribute Summary collapse
-
#account ⇒ Object
Returns the value of attribute account.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#credentials_updated_callback ⇒ Object
Returns the value of attribute credentials_updated_callback.
-
#email ⇒ Object
Returns the value of attribute email.
-
#oauth_flow ⇒ Object
Returns the value of attribute oauth_flow.
-
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
- #user_agent ⇒ Object
Instance Method Summary collapse
- #access_token_auth_header ⇒ Object
- #api_endpoint ⇒ Object
- #api_endpoint_without_account ⇒ Object
- #authorization_code_flow? ⇒ Boolean
- #authorization_uri(state: nil) ⇒ Object
- #client_credentials_flow? ⇒ Boolean
- #credentials ⇒ Object
- #credentials=(values) ⇒ Object
-
#duplicate(new_config) ⇒ Object
We can create multiple instances of the client, make sure we isolate the config for each as it contains credentials which must not be shared.
-
#initialize {|_self| ... } ⇒ Config
constructor
A new instance of Config.
- #oauth_endpoint ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Config
Returns a new instance of Config.
13 14 15 16 17 |
# File 'lib/fakturoid/config.rb', line 13 def initialize yield self validate_configuration end |
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account.
5 6 7 |
# File 'lib/fakturoid/config.rb', line 5 def account @account end |
#client_id ⇒ Object
Returns the value of attribute client_id.
5 6 7 |
# File 'lib/fakturoid/config.rb', line 5 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
5 6 7 |
# File 'lib/fakturoid/config.rb', line 5 def client_secret @client_secret end |
#credentials_updated_callback ⇒ Object
Returns the value of attribute credentials_updated_callback.
5 6 7 |
# File 'lib/fakturoid/config.rb', line 5 def credentials_updated_callback @credentials_updated_callback end |
#email ⇒ Object
Returns the value of attribute email.
5 6 7 |
# File 'lib/fakturoid/config.rb', line 5 def email @email end |
#oauth_flow ⇒ Object
Returns the value of attribute oauth_flow.
5 6 7 |
# File 'lib/fakturoid/config.rb', line 5 def oauth_flow @oauth_flow end |
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
5 6 7 |
# File 'lib/fakturoid/config.rb', line 5 def redirect_uri @redirect_uri end |
Instance Method Details
#access_token_auth_header ⇒ Object
61 62 63 |
# File 'lib/fakturoid/config.rb', line 61 def access_token_auth_header "#{credentials.token_type} #{credentials.access_token}" end |
#api_endpoint ⇒ Object
35 36 37 38 39 |
# File 'lib/fakturoid/config.rb', line 35 def api_endpoint raise ConfigurationError, "Account slug is required" if Utils.empty?(account) "#{API_ENDPOINT}/accounts/#{account}" end |
#api_endpoint_without_account ⇒ Object
41 42 43 |
# File 'lib/fakturoid/config.rb', line 41 def api_endpoint_without_account API_ENDPOINT end |
#authorization_code_flow? ⇒ Boolean
65 66 67 |
# File 'lib/fakturoid/config.rb', line 65 def oauth_flow == "authorization_code" end |
#authorization_uri(state: nil) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fakturoid/config.rb', line 49 def (state: nil) params = { client_id: client_id, redirect_uri: redirect_uri, response_type: "code" } params[:state] = state unless Utils.empty?(state) connection = Faraday::Connection.new(oauth_endpoint) connection.build_url(nil, params) end |
#client_credentials_flow? ⇒ Boolean
69 70 71 |
# File 'lib/fakturoid/config.rb', line 69 def client_credentials_flow? oauth_flow == "client_credentials" end |
#credentials ⇒ Object
19 20 21 |
# File 'lib/fakturoid/config.rb', line 19 def credentials @credentials ||= Oauth::Credentials.new end |
#credentials=(values) ⇒ Object
23 24 25 |
# File 'lib/fakturoid/config.rb', line 23 def credentials=(values) @credentials = values.is_a?(Hash) ? Oauth::Credentials.new(values) : values end |
#duplicate(new_config) ⇒ Object
We can create multiple instances of the client, make sure we isolate the config for each as it contains credentials which must not be shared.
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/fakturoid/config.rb', line 75 def duplicate(new_config) self.class.new do |config| config.email = email config.account = new_config[:account] || account config.user_agent = user_agent config.client_id = client_id config.client_secret = client_secret config.oauth_flow = oauth_flow # 'client_credentials', 'authorization_code' # only authorization_code config.redirect_uri = redirect_uri end end |
#oauth_endpoint ⇒ Object
45 46 47 |
# File 'lib/fakturoid/config.rb', line 45 def oauth_endpoint OAUTH_ENDPOINT end |