Class: BookingSync::Engine
- Inherits:
-
Rails::Engine
- Object
- Rails::Engine
- BookingSync::Engine
- Defined in:
- lib/bookingsync/engine.rb,
lib/bookingsync/engine/models.rb
Defined Under Namespace
Modules: AuthHelpers, Helpers, Models, SessionHelpers Classes: APIClient, ApplicationCredentials, CredentialsResolver, Retryable
Class Method Summary collapse
- .application_token(client_id: ENV["BOOKINGSYNC_APP_ID"], client_secret: ENV["BOOKINGSYNC_APP_SECRET"]) ⇒ Object
-
.embedded! ⇒ Object
Set the engine into embedded mode.
-
.oauth_client(client_id: ENV["BOOKINGSYNC_APP_ID"], client_secret: ENV["BOOKINGSYNC_APP_SECRET"]) ⇒ OAuth2::Client
OAuth client configured for the application.
-
.standalone! ⇒ Object
Set the engine into standalone mode.
Instance Method Summary collapse
- #embedded ⇒ Boolean
-
#sign_out_after ⇒ Fixnum
Duration of inactivity after which the authorization will be reset.
Class Method Details
.application_token(client_id: ENV["BOOKINGSYNC_APP_ID"], client_secret: ENV["BOOKINGSYNC_APP_SECRET"]) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/bookingsync/engine.rb', line 92 def self.application_token(client_id: ENV["BOOKINGSYNC_APP_ID"], client_secret: ENV["BOOKINGSYNC_APP_SECRET"]) token_refresh_timeout_attempts_allowed = ::BookingSyncEngine.token_refresh_timeout_retry_count + 1 BookingSync::Engine::Retryable.perform(times: token_refresh_timeout_attempts_allowed, errors: [Faraday::TimeoutError]) do oauth_client(client_id: client_id, client_secret: client_secret).client_credentials.get_token end end |
.embedded! ⇒ Object
Set the engine into embedded mode.
Embedded apps are loaded from within the BookingSync app store, and have a different method to redirect during the OAuth authorization process. This method will not work when the app is not embedded.
60 61 62 |
# File 'lib/bookingsync/engine.rb', line 60 def self. self. = true end |
.oauth_client(client_id: ENV["BOOKINGSYNC_APP_ID"], client_secret: ENV["BOOKINGSYNC_APP_SECRET"]) ⇒ OAuth2::Client
OAuth client configured for the application.
The ENV variables used for configuration are described in README.
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/bookingsync/engine.rb', line 79 def self.oauth_client(client_id: ENV["BOOKINGSYNC_APP_ID"], client_secret: ENV["BOOKINGSYNC_APP_SECRET"]) = { headers: { accept: "application/vnd.api+json" } }.merge(::BookingSyncEngine.) = { site: ENV["BOOKINGSYNC_URL"] || 'https://www.bookingsync.com', connection_opts: } [:ssl] = { verify: ENV['BOOKINGSYNC_VERIFY_SSL'] != 'false' } OAuth2::Client.new(client_id, client_secret, ) end |
.standalone! ⇒ Object
Set the engine into standalone mode.
This setting is requried for the applications using this Engine to work outside of the BookingSync app store.
Restores the normal mode of redirecting during OAuth authorization.
70 71 72 |
# File 'lib/bookingsync/engine.rb', line 70 def self.standalone! self. = false end |
Instance Method Details
#embedded ⇒ Boolean
46 |
# File 'lib/bookingsync/engine.rb', line 46 cattr_accessor :embedded |
#sign_out_after ⇒ Fixnum
Duration of inactivity after which the authorization will be reset. See BookingSync::Engine::SessionHelpers#sign_out_if_inactive.
52 |
# File 'lib/bookingsync/engine.rb', line 52 cattr_accessor :sign_out_after |