module AppManager class Client module Connection def get(path, options = {}) request :get, path, options end def post(path, options = {}) request :post, path, options end def put(path, options = {}) request :put, path, options end def delete(path, options = {}) request :delete, path, options end private def request(http_method, path, options) response = self.class.send(http_method, path, { body: options }) if path.include? "/get-status" data = response elsif path.include? "/sync-charge" data = response.parsed_response data = parse_data(response.parsed_response) else if response.code.to_s.start_with?('2') or response.code.to_s.start_with?('4') data = response.parsed_response data = parse_data(response.parsed_response) else data = response_from_failsafe(path,options) end end end def parse_data(original_data) return unless original_data if (original_data.class == Hash) && original_data.key?("headers") && original_data.key?("footers") && original_data.key?("modal") return {"banners" => original_data} else return original_data end end def response_from_failsafe(path,options) params = Rack::Utils.parse_query URI(path).query path = path.delete_prefix('/') path = path[/[^?]+/] @fs = AppManager::FailSafe.new case path when "static-contents" return @fs.get_local_app_structures when 'plans' return @fs.get_local_plans when 'plan' return @fs.get_local_plan(params) when 'store-charge' return @fs.store_local_charge(params,options) when 'cancel-charge' return @fs.store_cancel_charge(params,options) when 'get-remaining-days' return @fs.get_local_remaining_days(params,options) when 'get-charge' return @fs.get_local_charge(params,options) else return nil end end end end end