Module: LWS

Defined in:
lib/lws.rb,
lib/lws/version.rb

Overview

Main LeftClick web services module

This module is the main namespace for the web service/application libraries that are represented by submodules. The LWS module is used to load, set up and configure the supported application/web service libraries.

Defined Under Namespace

Modules: Auth, Generic, Maps, Presence Classes: Config

Constant Summary collapse

SUPPORTED_APPS =

The list of supported apps (web service libraries) loaded by setup.

[:generic, :auth, :maps, :presence]
VERSION =
Note:

This is not the API version!

The LWS library version.

'0.2.0'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load_app_modulesArray<Symbol>

(Re)loads the app modules (usually done by setup).

Returns:

  • (Array<Symbol>)

    the apps that were loaded (see also SUPPORTED_APPS)



187
188
189
190
191
192
# File 'lib/lws.rb', line 187

def self.load_app_modules
  app_module_path = File.dirname(__FILE__)
  SUPPORTED_APPS.each do |app|
    load "#{app_module_path}/lws/#{app}.rb"
  end
end

.setup {|config| ... } ⇒ LWS

Sets up the application API libraries using the provided configuration (see Config).

Examples:

Set up LWS with a token, an endpoint override, HTTP debugging and the Rails logger

LWS.setup do |config|
  config.api_token = "MY_TOKEN"
  config.endpoints = { maps: https://maps-dev.leftclick.eu }
  config.http_debug = true
  config.logger = Rails.logger
end

Yield Parameters:

  • config (Config)

    an API configuration object that can be configured

Returns:

  • (LWS)

    the module itself

Raises:

  • if API token is not configured



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/lws.rb', line 140

def self.setup(&block)
  @@config = Config.new
  yield @@config

  if config.api_token.blank? and config.api_token_middleware.blank?
    raise "API token or API token middleware is required"
  end

  # Override the environment if needed
  if ENV["LC_LWS_ENV"].present?
    @@config.environment = ENV["LC_LWS_ENV"].to_sym
  end

  load_app_modules

  return self
end

Instance Method Details

#configConfig

Returns the API configuration for the web services.

Returns:

  • (Config)

    the API configuration for the web services



82
# File 'lib/lws.rb', line 82

mattr_reader :config