Ejemplo n.º 1
0
        /// <summary>
        /// Reads the sheet data for the given sheet
        /// </summary>
        /// <param name="sheetId">Id for the sheet in question</param>
        /// <returns>Returns a subset of the information for the given sheet, or an error for non-200 status codes</returns>
        public async Task <SmartSheetResponse <SmartSheetResponseResult> > ReadSheet(double sheetId)
        {
            var response = await HttpClient.GetAsync($"sheets/{sheetId:R}");

            string responseContent = await response.Content.ReadAsStringAsync();

            SmartSheetResponse <SmartSheetResponseResult> sheetResponse = new SmartSheetResponse <SmartSheetResponseResult>
            {
                StatusCode = response.StatusCode,
                Content    = response.StatusCode == HttpStatusCode.OK ? JsonConvert.DeserializeObject <SmartSheetResponseResult>(responseContent) : null,
                Error      = response.StatusCode != HttpStatusCode.OK ? responseContent : null
            };

            return(sheetResponse);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a sheet by calling the CreateSheet endpoint with the requested sheet data
        /// </summary>
        /// <param name="sheetToCreate">Representation of the sheet the user wants to create.</param>
        /// <returns>Response object containing StatusCode, Content (on OK status code) and Error Message (on non-OK status codes)</returns>
        public async Task <SmartSheetResponse <SmartSheetCreateResponse> > CreateSheet(CreateSmartSheetRequestObject sheetToCreate)
        {
            HttpContent content  = new StringContent(JsonConvert.SerializeObject(sheetToCreate), Encoding.UTF8, "application/json");
            var         response = await HttpClient.PostAsync("sheets", content);

            string responseContent = await response.Content.ReadAsStringAsync();

            SmartSheetResponse <SmartSheetCreateResponse> sheetResponse = new SmartSheetResponse <SmartSheetCreateResponse>
            {
                StatusCode = response.StatusCode,
                Content    = response.StatusCode == HttpStatusCode.OK ? JsonConvert.DeserializeObject <SmartSheetCreateResponse>(responseContent) : null,
                Error      = response.StatusCode != HttpStatusCode.OK ? responseContent : null
            };

            return(sheetResponse);
        }
Ejemplo n.º 3
0
        public void CreateSheet_ValidateContents()
        {
            SmartSheetRestClient client = new SmartSheetRestClient();

            // Set up SmartSheet request object
            CreateSmartSheetRequestObject sheet = new CreateSmartSheetRequestObject();

            sheet.Name = "Kevin Test Sheet";
            sheet.Columns.Add(new CreateSmartSheetRequestColumn
            {
                Title  = "favorite",
                Type   = ColumnTypes.CHECKBOX.ToString(),
                Symbol = "STAR"
            });
            sheet.Columns.Add(new CreateSmartSheetRequestColumn
            {
                Title   = "Primary Column",
                Type    = ColumnTypes.TEXT_NUMBER.ToString(),
                Primary = true
            });

            // Create the SmartSheet
            SmartSheetResponse <SmartSheetCreateResponse> createResponse = client.CreateSheet(sheet).Result;

            // Verify that the create request was successful
            Assert.AreEqual(HttpStatusCode.OK, createResponse.StatusCode, "Create sheet returned a non-200 response.");
            VerificationHelpers.CreateSheetValidation(sheet, createResponse.Content.Result);

            // Get Sheet from endpoint and compare data
            // I noticed that there are instances where the Read would return NotFound, but in my investigation of these instances, the sheet was created eventually.
            // Adding this retry as a quick fix. Normally I would investigate this further to see if there were better ways to handle this.
            SmartSheetResponse <SmartSheetResponseResult> readResponse = null;

            for (int i = 0; i < 3; i++)
            {
                readResponse = client.ReadSheet(createResponse.Content.Result.Id).Result;
                if (readResponse.StatusCode == HttpStatusCode.OK)
                {
                    break;
                }
                Thread.Sleep(1000);
            }

            // Verify that the read request was successful
            Assert.AreEqual(HttpStatusCode.OK, readResponse.StatusCode, $"Read response for sheet {createResponse.Content.Result.Id.ToString()} returned a non-200 response.");
            VerificationHelpers.CompareCreatedVsRead(createResponse.Content.Result, readResponse.Content);
        }