Exemplo n.º 1
0
        /// <summary>
        /// Creates a spreadsheet, returning the newly created spreadsheet.
        /// </summary>
        public async Task <SpreadsheetRaw> Create(SpreadsheetRaw spreadsheet)
        {
            string address = "https://sheets.googleapis.com/v4/spreadsheets?{auth}";

            string token = authorization.ToString();

            if (authorization.Type == AuthorizationType.Key)
            {
                address = address.Replace("{auth}", "key=" + token);
            }
            else if (authorization.Type == AuthorizationType.AccessToken)
            {
                address = address.Replace("{auth}", "accessToken=" + token);
            }

            string data = SerializeObject(spreadsheet);

            using (WebClient webClient = new WebClient())
            {
                webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
                string response = await webClient.UploadStringTaskAsync(address, data);

                return(DeserializeObject <SpreadsheetRaw>(response));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the raw data that is contingent to the Google Sheets API.
        /// </summary>
        public async Task <SpreadsheetRaw> GetRaw(bool includeGridData)
        {
            string address = "https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId}?{auth}&includeGridData=" + includeGridData.ToString().ToLower();

            address = address.Replace("{spreadsheetId}", spreadsheetId);

            string token = authorization.ToString();

            if (authorization.Type == AuthorizationType.Key)
            {
                address = address.Replace("{auth}", "key=" + token);
            }
            else if (authorization.Type == AuthorizationType.AccessToken)
            {
                address = address.Replace("{auth}", "accessToken=" + token);
            }

            using (WebClient webClient = new WebClient())
            {
                string data = await webClient.DownloadStringTaskAsync(address);

                SpreadsheetRaw spreadsheet = DeserializeObject <SpreadsheetRaw>(data);
                return(spreadsheet);
            }
        }
Exemplo n.º 3
0
        public Spreadsheet(SpreadsheetRaw raw)
        {
            this.raw = raw;

            for (int i = 0; i < raw.sheets.Length; i++)
            {
                Sheet sheet = new Sheet(raw.sheets[i]);
                sheets.Add(sheet);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns the raw data that is contingent to the Google Sheets API.
        /// </summary>
        public static async Task <SpreadsheetRaw> Get(string spreadsheetId, Authorization authorization, bool includeGridData, SheetsSerializer serializer = null)
        {
            if (serializer == null)
            {
                serializer = SheetsSerializer.Serializer;
            }
            if (serializer == null)
            {
                throw new Exception("No serializer was given.");
            }

            SheetsClient   client = new SheetsClient(spreadsheetId, authorization, serializer);
            SpreadsheetRaw raw    = await client.GetRaw(includeGridData);

            return(raw);
        }