示例#1
0
        /// <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));
        }
示例#2
0
        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)));
        }
示例#3
0
        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");
        }
示例#4
0
        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");
        }
示例#5
0
        /// <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);
        }
示例#6
0
        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&currency=currency&interval=interval&name=name&trial_period_days=100");
        }
示例#7
0
        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&currency=currency&interval=interval&name=name&trial_period_days=100");
        }