public List <string> GetRawList(int accountId, bool throwIfEmpty = false) { IRestRequest request = TDClient.BuildRequest(Method.GET, LIST, new { accountId }); IRestResponse response = TDClient.InnerExecute(request); if (response == null) { return(null); } if (response.StatusCode == HttpStatusCode.NoContent) { if (throwIfEmpty) { throw new HttpException(string.Format("Empty list response for {0}: {1} {2} {3}", typeof(LongCode).Name, request.Resource, response.StatusCode, response.StatusDescription)); } return(new List <string>()); } return(response.Deserialize <List <string> >()); }
internal TEntity ProcessOperationResponse <TEntity>(IRestRequest request, IRestResponse response, string operation) where TEntity : class, new() { if (response.StatusCode == HttpStatusCode.NoContent) { throw new HttpException(string.Format("Empty response on {0} operation {1}: {2} {3} {4}", operation, typeof(TEntity).Name, request.Resource, response.StatusCode, response.StatusDescription)); } return(response.Deserialize <TEntity>()); }
public List <ChatMessage> GetMessages(int accountId, int conversationId, int skip, int top) { IRestRequest request = TDClient.BuildRequest(Method.GET, CONVERSATION_ITEM, new { accountId, conversationId }, filter: string.Format("$skip={0}&$top={1}", skip, top)); IRestResponse response = TDClient.InnerExecute(request); if (response.StatusCode == HttpStatusCode.NoContent) { return(new List <ChatMessage>()); } var res = response.Deserialize <List <ChatMessage> >(); return(res); }
public List <ChatConversation> FindConversations(int accountId, string needle, int skip, int top, out int count) { IRestRequest request = TDClient.BuildRequest(Method.POST, SEARCH_CONVERSATION, new { accountId }, needle.Trim(), filter: string.Format("$skip={0}&$top={1}", skip, top)); IRestResponse response = TDClient.InnerExecute(request); if (response.StatusCode == HttpStatusCode.NoContent) { count = 0; return(new List <ChatConversation>()); } var rval = response.Deserialize <List <ChatConversation> >(); var countHeader = response.Headers.FirstOrDefault(p => p.Name == "X-TrueDialog-Count"); count = countHeader != null?int.Parse(countHeader.Value.ToString()) : rval.Count; return(rval); }
/// <summary> /// Attempts to deserialize a list of errors when we received an error response from the HTTP server. /// </summary> /// <remarks> /// Unlike the TryForSimpleErrors this method attempts to pull out more specific details. /// </remarks> /// <param name="response">The response to parse</param> private static void TryForDetailedErrors(IRestResponse response) { List <ErrorDetail> errors = null; try { errors = response.Deserialize <List <ErrorDetail> >(); } catch (Exception ex) { // We deliberately throw away the exception s_log.Debug("Unable to deserialize error message details", ex); } if (errors != null) { throw new RemoteException(response.StatusCode, errors); } }
/// <summary> /// Attempts to deserialize a list of errors when we received an error response from the HTTP server. /// </summary> /// <param name="response">The response to parse</param> private static void TryForSimpleErrors(IRestResponse response) { List <string> errorList = null; try { errorList = response.Deserialize <List <string> >(); } catch (Exception ex) { // We deliberately throw away the exception s_log.Debug("Unable to deserialize error message details", ex); } if (errorList != null) { throw new ValidationException(errorList.FirstOrDefault()); } }
private static IRestResponse ThrowIfException(this IRestResponse response) { if (response.ErrorException != null) { throw new Exception("There was an an exception thrown during the request.", response.ErrorException); } if (response.ResponseStatus != ResponseStatus.Completed) { throw response.ResponseStatus.ToWebException(); } if ((int)response.StatusCode >= 400) { throw new ApiException(response.StatusCode, response.Deserialize <Error>()); } return(response); }
internal TEntity ProcessItemResponse <TEntity>(IRestRequest request, IRestResponse response, bool throwIfEmpty) where TEntity : class, new() { if (response == null) { return(null); } if (response.StatusCode == HttpStatusCode.NoContent) { if (throwIfEmpty) { throw new HttpException(string.Format("Empty response for {0}: {1} {2} {3}", typeof(TEntity).Name, request.Resource, response.StatusCode, response.StatusDescription)); } return(default(TEntity)); } return(response.Deserialize <TEntity>()); }