public async Task <MessengerResponse> SendActionAsync(string senderAction, MessengerUser recipient, String accessToken) { var url = String.Format(UrlTemplate, accessToken); var request = new MessengerSendActionRequest { Recipient = recipient, SenderAction = senderAction }; var strings = serializer.Serialize(request); var content = new StringContent(strings); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); try { var response = await client.PostAsync(url, content); var result = new MessengerResponse { Succeed = response.IsSuccessStatusCode, RawResponse = await response.Content.ReadAsStringAsync() }; return(result); } catch (Exception exc) { throw new MessengerException(exc); } }
protected async Task <MessengerResponse> Post(string url, object data) { var content = new StringContent(serializer.Serialize(data)); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var httpResponse = await client.PostAsync(url, content); var response = new MessengerResponse(); response.Succeed = httpResponse.IsSuccessStatusCode; response.RawResponse = await httpResponse.Content.ReadAsStringAsync(); return(response); }
public async Task <MessengerResponse <TResponse> > Post <TResponse, TRequest>(string url, TRequest data) { var content = new StringContent(serializer.Serialize(data)); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var response = await client.PostAsync(url, content); var result = new MessengerResponse <TResponse>(); result.RawResponse = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { result.Succeed = false; return(result); } if (typeof(TResponse) == typeof(string)) { object raw = result.RawResponse; result.Result = (TResponse)raw; } else { result.Result = serializer.Deserialize <TResponse>(result.RawResponse); } return(result); }
private async Task <MessengerResponse> SendMessage <TRequest>(TRequest request, string accessToken) { var url = String.Format(UrlTemplate, accessToken); var content = new StringContent(serializer.Serialize(request)); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); try { var response = await client.PostAsync(url, content); var result = new MessengerResponse { Succeed = response.IsSuccessStatusCode, RawResponse = await response.Content.ReadAsStringAsync() }; return(result); } catch (Exception exc) { throw new MessengerException(exc); } }