public async Task CreateSheets(ICollection <string> names) { var urlBuilder = URLBuilder.BatchUpdate(ID); var value = AddSheetRequestBodyAdapter.GetAddSheetRequestBody(names); var responseHandler = new Action <string>(str => { var jObject = JObject.Parse(str); var replies = jObject["replies"]; var repliesArray = replies.Select(t => t); foreach (var addSheet in repliesArray) { var properties = addSheet["addSheet"]["properties"]; var id = properties["sheetId"]; var title = properties["title"]; var googleSheet = new Sheet(id.Value <int>(), title.Value <string>()); Sheets.Add(googleSheet); } Debug.Log(nameof(CreateSheets) + string.Join("\n", names.ToArray())); }); await RequestExecutor.SendRequestAsync(urlBuilder, value, responseHandler); }
public async Task Save() { var urlBuilder = URLBuilder.WriteMultipleRanges(ID) .AddApiKey(GoogleDataStorage.Instance.ApiKey) .AddValueInputOption("USER_ENTERED"); var value = GoogleSpreadsheetAdapter.GetBatchRequestBody(this); var responseHandler = new Action <string>(str => { Debug.Log(nameof(Save)); }); await RequestExecutor.SendRequestAsync(urlBuilder, value, responseHandler); }
public async Task Clear() { var urlBuilder = URLBuilder.ClearSpreadsheets(ID); var value = ClearRequestBodyAdapter.GetClearRequestBody(Sheets); var responseHandler = new Action <string>(str => { Debug.Log(nameof(Clear)); foreach (var googleSheet in Sheets) { googleSheet.Clear(); } }); await RequestExecutor.SendRequestAsync(urlBuilder, value, responseHandler); }
public async Task DeleteGoogleSheets(ICollection <int> ids) { var urlBuilder = URLBuilder.BatchUpdate(ID); var value = AddSheetRequestBodyAdapter.GetDeleteSheetRequestBody(ids); var responseHandler = new Action <string>(str => { Debug.Log(nameof(DeleteGoogleSheets)); foreach (var id in ids) { var googleSheet = Sheets.First(item => item.ID == id); Sheets.Remove(googleSheet); } }); await RequestExecutor.SendRequestAsync(urlBuilder, value, responseHandler); }