Module: LWS
- Includes:
- Errors
- Defined in:
- lib/lws.rb,
lib/lws/config.rb,
lib/lws/errors.rb,
lib/lws/version.rb,
lib/lws/stubbing.rb,
lib/lws/middleware.rb,
lib/lws/middleware.rb,
lib/lws/middleware/http_logger.rb,
lib/lws/middleware/json_logger.rb,
lib/lws/middleware/json_parser.rb,
lib/lws/middleware/request_headers.rb,
lib/lws/middleware/raise_server_error.rb
Overview
Set up Faraday middleware portability using class aliases.
Defined Under Namespace
Modules: Auth, CorporateWebsite, DigitalSignage, Errors, Generic, Maps, Presence, Resource, Ticket Classes: Config, Stubbing
Constant Summary collapse
- RETRY_EXCEPTIONS =
The exceptions that warrant a retry.
Middleware::Retry::DEFAULT_EXCEPTIONS + [Errno::EALREADY, Faraday::ConnectionFailed, Faraday::SSLError].freeze
- SUPPORTED_APPS =
The list of supported apps (web service libraries) loaded by setup.
[:generic, :auth, :corporate_website, :digital_signage, :maps, :presence, :resource, :ticket].freeze
- VERSION =
Note:
The major and minor version parts match the LWS API version!
The LWS library version.
"13.0.0".freeze
Constants included from Middleware
Middleware::FollowRedirects, Middleware::JSONEncoder, Middleware::ObjectCaching, Middleware::Retry
Class Method Summary collapse
-
.app_module(app_name) ⇒ Module
Returns the app module for the given app name.
-
.load_app_modules ⇒ Array<Symbol>
(Re)loads the app modules (usually done by LWS.setup).
-
.load_stubbing ⇒ Stubbing?
(Re)loads the stubbing if enabled (usually done by LWS.setup).
-
.setup {|config| ... } ⇒ LWS
Sets up the application API libraries using the provided configuration (see Config).
Instance Method Summary collapse
-
#config ⇒ Config
The API configuration for the web services.
-
#stubbing ⇒ Stubbing
The stubbing setup for the web services.
Class Method Details
.app_module(app_name) ⇒ Module
Returns the app module for the given app name.
170 171 172 |
# File 'lib/lws.rb', line 170 def self.app_module(app_name) @app_modules[app_name.to_sym] end |
.load_app_modules ⇒ Array<Symbol>
(Re)loads the app modules (usually done by setup).
178 179 180 181 182 183 184 185 |
# File 'lib/lws.rb', line 178 def self.load_app_modules @app_modules = {} app_module_path = File.dirname(__FILE__) SUPPORTED_APPS.each do |app_name| load "#{app_module_path}/lws/apps/#{app_name}.rb" @app_modules[app_name] = LWS.const_get(app_name.to_s.camelize) end end |
.load_stubbing ⇒ Stubbing?
(Re)loads the stubbing if enabled (usually done by setup).
190 191 192 193 194 195 196 197 |
# File 'lib/lws.rb', line 190 def self.load_stubbing if config.stubbing.present? @@stubbing = Stubbing.new(config.stubbing) else @@stubbing.disable! if @@stubbing @@stubbing = nil end end |
.setup {|config| ... } ⇒ LWS
Sets up the application API libraries using the provided configuration (see Config).
The API token can be overridden using the LC_LWS_API_TOKEN environment variable. The LWS environment can be overriden using the LC_LWS_ENV environment variable.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/lws.rb', line 92 def self.setup(&block) @@config = Config.new # Override the environment if needed if ENV["LC_LWS_ENV"].present? @@config.environment = ENV["LC_LWS_ENV"] end # Override the API token if needed (and no custom API token middleware # is used) if ENV["LC_LWS_API_TOKEN"].present? @@config.api_token = ENV["LC_LWS_API_TOKEN"] end yield @@config if config.api_token.blank? and config.api_token_middleware.blank? raise LWS::Errors::ConfigError, "API token or API token middleware is required" end load_app_modules load_stubbing return self end |