public async Task UpdateUserAsync(UserUpdate userUpdate) { string url = string.Format("{0}/{1}", URL.RESTRoot, "user"); string authzHeader = AuthorizationHeader.CreateForREST(Config.ConsumerKey, Config.ConsumerSecret, AuthToken.Token, AuthToken.TokenSecret, url, "PUT"); string serializeObject = JsonConvert.SerializeObject(userUpdate); HttpContent httpContent = new StringContent(serializeObject); HttpRequestItem httpRequestItem = new HttpRequestItem() { URL = url, HttpMethod = HttpMethod.Put, AuthzHeader = authzHeader, HttpContent = httpContent, IsDataRequest = true }; HttpRequestHandler httpRequestHandler = new HttpRequestHandler(); string executeAsync = await httpRequestHandler.ReadAsStringAsync(httpRequestItem); //TODO : Investigate //return JsonConvert.DeserializeObject<User>(executeAsync); }
public async Task<HttpResponseMessage> ExecuteAsync(HttpRequestItem httpRequestItem) { HttpRequestMessage httpRequest = new HttpRequestMessage() { RequestUri = new Uri(httpRequestItem.URL), Method = httpRequestItem.HttpMethod, Content = httpRequestItem.HttpContent }; httpRequest.Headers.Add("Authorization", httpRequestItem.AuthzHeader); if (httpRequestItem.IsDataRequest) { httpRequest.Headers.Add("X-Api-Version", "1"); httpRequest.Headers.Add("Accept", "application/json"); } //if (httpRequestItem.IsFileUpload) //{ // httpRequest.Headers.TryAddWithoutValidation("Content-Type", "multipart/form-data"); //} HttpResponseMessage httpResponse = await _client.SendAsync(httpRequest, HttpCompletionOption.ResponseContentRead); return httpResponse; }
public async Task<string> ReadAsStringAsync(HttpRequestItem httpRequestItem) { HttpResponseMessage httpResponse = await ExecuteAsync(httpRequestItem); return await httpResponse.Content.ReadAsStringAsync(); }
public async Task<User> GetUserAsync() { string url = string.Format("{0}/{1}", URL.RESTRoot, "user"); string authzHeader = AuthorizationHeader.CreateForREST(Config.ConsumerKey, Config.ConsumerSecret, AuthToken.Token, AuthToken.TokenSecret, url, "GET"); HttpRequestItem httpRequestItem = new HttpRequestItem() { URL = url, HttpMethod = HttpMethod.Get, AuthzHeader = authzHeader, HttpContent = null, IsDataRequest = true }; HttpRequestHandler httpRequestHandler = new HttpRequestHandler(); string executeAsync = await httpRequestHandler.ReadAsStringAsync(httpRequestItem); return JsonConvert.DeserializeObject<User>(executeAsync); }
public async Task<byte[]> ReadAsByteArrayAsync(HttpRequestItem httpRequestItem) { HttpResponseMessage httpResponse = await ExecuteAsync(httpRequestItem); return await httpResponse.Content.ReadAsByteArrayAsync(); }