Method: LWS.setup

Defined in:
lib/lws.rb

.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.

Examples:

Set up LWS with a token and the development environment

LWS.setup do |config|
  config.api_token = "MY_TOKEN"
  config.environment = :development
end

Set up LWS with API token middleware, caching, the development environment, an map endpoint override and logging to the Rails logger

LWS.setup do |config|
  config.api_token_middleware = TokenAuthenticator
  config.caching_object = MyRedisCache.new
  config.environment = :development
  config.endpoints = { maps: "https://maps.leftclick.cloud" }
  config.http_debug = true
  config.json_debug = true
  config.logger = Rails.logger
end

Yield Parameters:

  • config (Config)

    an API configuration object that can be configured

Raises:



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/lws.rb', line 78

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

  # Override the environment if needed
  if ENV["LC_LWS_ENV"].present?
    @@config.environment = ENV["LC_LWS_ENV"].to_sym
  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