module ApiCache
Public Instance Methods
api_config()
click to toggle source
# File lib/apl-library/api_cache.rb, line 84 def api_config @@api_config end
api_config=(api_config)
click to toggle source
# File lib/apl-library/api_cache.rb, line 88 def api_config=(api_config) @@api_config = api_config end
check_api_disabled(bu, method, uri)
click to toggle source
# File lib/apl-library/api_cache.rb, line 57 def check_api_disabled(bu, method, uri) bu = bu.downcase if bu method = method.downcase if method uri = uri.downcase if uri # Specific URI is blocked return true if (@@api_config.select {|c| c['bu'] == bu and c['method'] == method and c['uri'] == uri}).size > 0 # Specific URI across BU is blocked return true if (@@api_config.select {|c| c['bu'] == nil and c['method'] == method and c['uri'] == uri}).size > 0 # One entire type of HTTP method is blocked return true if (@@api_config.select {|c| c['bu'] == bu and c['method'] == method and c['uri'] == nil}).size > 0 # One entire type of HTTP method is blocked across BU return true if (@@api_config.select {|c| c['bu'] == nil and c['method'] == method and c['uri'] == nil}).size > 0 # Entire BU is blocked return true if (@@api_config.select {|c| c['bu'] == bu and c['method'] == nil and c['uri'] == nil}).size > 0 # Entire service is blocked return true if (@@api_config.select {|c| c['bu'] == nil and c['method'] == nil and c['uri'] == nil}).size > 0 return false end
get_api_config_cache()
click to toggle source
# File lib/apl-library/api_cache.rb, line 53 def get_api_config_cache @@api_config end
get_api_configurations()
click to toggle source
# File lib/apl-library/api_cache.rb, line 43 def get_api_configurations url = "/api_configurator/configurations/#{SERVICE_NAME}" @connector.get(url) end
setup_api_config_cache(sleep_time = 30)
click to toggle source
# File lib/apl-library/api_cache.rb, line 8 def setup_api_config_cache(sleep_time = 30) @@sleep_time = sleep_time @connector = RemoteServiceConnector.new(@@apl_config_service) is_initialization = true @@api_sync_thread = Thread.new do while true begin unless is_initialization response = get_api_configurations logger.info "debug response we get is #{ response }" update_api_config_cache(response) end is_initialization = false rescue Exception => e logger.error "Exception while running api_sync_thread. Message - #{e.message}" @@error_count = @@error_count + 1; if(@@error_count == 10) @@api_config = [] @@error_count = 0 end end sleep(@@sleep_time) end end logger.info "Started api_sync_thread - #{@@api_sync_thread}" # Graceful termination of api_sync_thread at_exit do logger.info "Shutting down api_sync_thread - #{@@api_sync_thread}" @@api_sync_thread.exit if @@api_sync_thread end end
update_api_config_cache(api_config)
click to toggle source
# File lib/apl-library/api_cache.rb, line 48 def update_api_config_cache(api_config) @@api_config = api_config logger.info "debug updating The cache config with#{@@api_config}" end