lib/eco/api/session_config/apis.rb in eco-helpers-0.6.2 vs lib/eco/api/session_config/apis.rb in eco-helpers-0.6.3

- old
+ new

@@ -8,11 +8,10 @@ @root = root end def apis self["apis"] ||= {} - self["apis"] end def apis? apis.keys.length > 0 end @@ -56,21 +55,33 @@ def active_api self["active-api"] end - def api(logger = ::Logger.new(IO::NULL)) + def service_up? + api_klass = (active_api.version == :external)? Ecoportal::API::External : Ecoportal::API::Internal + @api_test ||= api_klass.new("foobar", host: active_api.host, logger: ::Logger.new(IO::NULL)) + status = @api_test.client.get("/policy_groups").status + # 401 Unauthorized "Permission denied. API key may be invalid." + status == 401 + end + + def api(logger = ::Logger.new(IO::NULL), force_new: false) key = active_api.key host = active_api.host mode = active_api.mode version = active_api.version - return @api if @api && key == @key && host == @host && @mode == mode && version == @version + return @api if (!force_new) && @api && key == @key && host == @host && @mode == mode && version == @version api_klass = (version == :external)? Ecoportal::API::External : Ecoportal::API::Internal @api = api_klass.new(key, host: host, logger: logger) @key = key; @host = host; @mode = mode; @version = version @api + end + + def new_api(logger = ::Logger.new(IO::NULL)) + api(logger, force_new: true) end end end end