/// <summary> /// Updates the asynchronous with custom params /// </summary> /// <param name="obj">The object.</param> /// <returns></returns> protected virtual async Task <T> updateParamAsync(String resourceId, Object param) { var encoder = new UrlEncoder(); var content = new StringContent(encoder.EncodeObject(param)); content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); string requestUri = _apiUrl + "/" + _resource.ToString().ToLower() + "/" + resourceId; HttpResponseMessage response = httpClient.PutAsync(requestUri, content).Result; String data = await readReponseMessage(response); return(ReadResult <T>(data)); }
public virtual async Task <Offer> UpdateAsync(Offer obj, Boolean updateSubscriptions) { var encoder = new UrlEncoder(); String param = encoder.EncodeObject(new { update_subscriptions = updateSubscriptions.ToString().ToLower() }); var content = encoder.EncodeUpdate(obj); return(await updateWithContentAsync(obj.Id, String.Format("{0}&{1}", content, param))); }
public void EncodeNullableObject() { UrlEncoder urlEncoder = new UrlEncoder(); DateTime? trialEnd = null; String encodedObject = urlEncoder.EncodeObject(new { Offer = "OfferId", Payment = "PaymentId", Client = "clientId", Start_At = "1395266400", End_At = trialEnd }); Assert.IsNotNull(encodedObject); Assert.AreEqual(encodedObject, "offer=OfferId&payment=PaymentId&client=clientId&start_at=1395266400"); }
/// <summary> /// Delete object the asynchronous. /// </summary> /// <param name="obj">The object.</param> /// <returns></returns> protected async Task <Boolean> deleteParamBoolAsync(String resourceId, Object param) { var encoder = new UrlEncoder(); string requestUri = _apiUrl + "/" + _resource.ToString().ToLower() + "/" + resourceId; HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Delete, requestUri); ; request.Content = new StringContent(encoder.EncodeObject(param)); request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); HttpResponseMessage response = httpClient.SendAsync(request).Result; await readReponseMessage(response); return(true); }
public void EncodeNullableIntObject() { UrlEncoder urlEncoder = new UrlEncoder(); int? trialPeriodDays = 100; int? trialPeriodMinutes = null; String encodedObject = urlEncoder.EncodeObject(new { Amount = "amount", Currency = "currency", Interval = "interval", Name = "name", Trial_Period_Days = trialPeriodDays, Trial_Period_Minutes = trialPeriodMinutes }); Assert.IsNotNull(encodedObject); Assert.AreEqual(encodedObject, "amount=amount¤cy=currency&interval=interval&name=name&trial_period_days=100"); }