public object GetResponse(IApiRequest request) { string url = GetFullResource(this, request); string fPath = url.Replace(".json?", ".json-"); fPath = fPath.Replace("/", "\\"); string path = Path.Combine(_baseDir, fPath); string jsonString = "{}"; if (File.Exists(path)) { Console.WriteLine("File Found - " + path); Console.WriteLine(); jsonString = File.ReadAllText(path); } else { // If the json string isn't stored in our test bed // attempt to get a real response from the real api // Save the response to our test bed Console.WriteLine("File not Found - " + path); Console.WriteLine("Getting real api response"); Console.WriteLine(url); Console.WriteLine(); jsonString = handler.GetResponse <IRestResponse>(request).Content; File.WriteAllText(path, jsonString); } return(new RestResponse() { RawBytes = Encoding.UTF8.GetBytes(jsonString) }); }
public override object GetResponse(IApiRequest request) { RestResponse response = new RestResponse(); int id = (int)request.Parameters["recipe_id"]; string filePath = @".\Recipes\" + id + ".txt"; if (File.Exists(filePath)) { response.Content = File.ReadAllText(filePath); } else { Debug.WriteLine(id + " not found, download from GW2"); response = _netHandler.GetResponse(request) as RestResponse; File.WriteAllText(filePath, response.Content); } return(response); }