module Access class Request include HTTParty # debug_output $stdout # enable this to log all the requests def get(path, api_type, options={}) set_format results = self.class.get(set_base(api_type) + path, headers: headers, query: options) handle_results(results) end def get_json(path, api_type, options={}) set_format results = self.class.get(set_base(api_type) + path, headers: headers.merge({ 'Content-Type' => 'application/json', 'Accept' => 'application/json'}), body: options) handle_results(results) end private def handle_results(results) Access.config.hashify == "true" ? results.hashify : results end def set_base(api_type) "https://#{ api_type }#{ Access::Config::DOMAINS[Access.config.api_environment] }.adcrws.com/#{Access.config.api_version}" end def set_format raise Access::Error::InvalidResponseFormat unless [:json, :xml].include?(Access.config.format.to_sym) self.class.format Access.config.format.to_sym end def headers raise Access::Error::NoAccessToken unless Access.config.access_token {"Access-Token" => Access.config.access_token} end end end