/// <summary> /// Get a resource from SmartsheetClient REST API. /// /// Parameters: - path : the relative path of the resource - objectClass : the resource object class /// /// Returns: the resource (note that if there is no such resource, this method will throw ResourceNotFoundException /// rather than returning null). /// /// Exceptions: - /// InvalidRequestException : if there is any problem with the REST API request /// AuthorizationException : if there is any problem with the REST API authorization(access token) /// ResourceNotFoundException : if the resource can not be found /// ServiceUnavailableException : if the REST API service is not available (possibly due To rate limiting) /// SmartsheetRestException : if there is any other REST API related error occurred during the operation /// SmartsheetException : if there is any other error occurred during the operation /// </summary> /// <param name="path"> the relative path of the resource. </param> /// <param name="objectClass"> the object class </param> /// <returns> the resource </returns> /// <exception cref="SmartsheetException"> the SmartsheetClient exception </exception> protected internal virtual T GetResource <T>(string path, Type objectClass) { Utils.ThrowIfNull(path, objectClass); if (path == null || path.Length == 0) { Api.Models.Error error = new Api.Models.Error(); error.Message = "An empty path was provided."; throw new ResourceNotFoundException(error); } HttpRequest request = null; try { request = CreateHttpRequest(new Uri(smartsheet.BaseURI, path), HttpMethod.GET); } catch (Exception e) { throw new SmartsheetException(e); } HttpResponse response = this.smartsheet.HttpClient.Request(request); Object obj = null; switch (response.StatusCode) { case HttpStatusCode.OK: try { obj = this.smartsheet.JsonSerializer.deserialize <T>(response.Entity.GetContent()); } catch (JsonSerializationException ex) { throw new SmartsheetException(ex); } catch (Newtonsoft.Json.JsonException ex) { throw new SmartsheetException(ex); } catch (IOException ex) { throw new SmartsheetException(ex); } break; default: HandleError(response); break; } smartsheet.HttpClient.ReleaseConnection(); return((T)obj); }
/// <summary> /// Gets the exception. /// </summary> /// <param name="error"> the error </param> /// <returns> the exception </returns> /// <exception cref="SmartsheetException"> the SmartsheetClient exception </exception> public SmartsheetRestException getException(Api.Models.Error error) { object[] args = new object[] { error }; return((SmartsheetRestException)Activator.CreateInstance(exceptionClass, args)); }