public async Task <OrdersListType> GetAllReleasedOrders(DateTime createdStartDate, DateTime createdEndDate, int limit = 20)
        {
            // to avoid deadlock if this method is executed synchronously
            await new ContextRemover();

            Base.Http.Request request = CreateRequest();

            request.EndpointUri = "/v2/orders/released";

            if (limit < 1)
            {
                limit = 1;
            }

            if (limit > 200)
            {
                limit = 200;
            }

            request.QueryParams.Add("limit", limit.ToString());
            request.QueryParams.Add("createdStartDate", createdStartDate.ToString("yyyy-MM-dd"));
            request.QueryParams.Add("createdEndDate", createdEndDate.ToString("yyyy-MM-dd"));

            IResponse response = await client.GetAsync(request);

            OrdersListType result = await ProcessResponse <OrdersListType>(response);

            return(result);
        }
Exemplo n.º 2
0
        public async Task <PartnerFeedResponse> GetFeedStatus(string feedId, bool includeDetails = false, int offset = 0, int limit = 0)
        {
            // to avoid deadlock if this method is executed synchronously
            await new ContextRemover();

            Base.Http.Request request = CreateRequest();
            request.EndpointUri = string.Format("/v2/feeds/{0}", feedId);

            request.QueryParams.Add("feedId", feedId);
            if (includeDetails)
            {
                request.QueryParams.Add("includeDetails", "true");
                if (offset > 0)
                {
                    request.QueryParams.Add("offset", offset.ToString());
                }

                if (limit > 0)
                {
                    if (limit > 1000)
                    {
                        throw new System.Exception("Parameter 'limit' can't be more than 1000!");
                    }

                    request.QueryParams.Add("limit", limit.ToString());
                }
            }

            Base.Http.IResponse response = await client.GetAsync(request);

            PartnerFeedResponse result = await ProcessResponse <PartnerFeedResponse>(response);

            return(result);
        }
        public async Task <PartnerFeedResponse> GetFeedStatus(string feedId, bool includeDetails = false, int offset = 0, int limit = 0)
        {
            // to avoid deadlock if this method is executed synchronously
            await new ContextRemover();

            Base.Http.Request request = CreateRequest();
            request.EndpointUri = string.Format("/v3/feeds/{0}", feedId);

            // by default it's false and we don't need to send it
            if (includeDetails)
            {
                request.QueryParams.Add("includeDetails", "true");
            }

            if (offset > 0)
            {
                request.QueryParams.Add("offset", offset.ToString());
            }

            if (limit > 0)
            {
                request.QueryParams.Add("limit", limit.ToString());
            }

            Base.Http.IResponse response = await client.GetAsync(request);

            PartnerFeedResponse result = await ProcessResponse <PartnerFeedResponse>(response);

            return(result);
        }
        private async Task <IResponse> UpdateOrder(string purchaseOrderId, OrderAction desiredAction, System.IO.Stream stream = null)
        {
            var action = "";

            switch (desiredAction)
            {
            case OrderAction.Ack:
                action = "acknowledge";
                break;

            case OrderAction.Cancel:
                action = "cancel";
                break;

            case OrderAction.Refund:
                action = "refund";
                break;

            case OrderAction.Shipping:
                action = "shipping";
                break;

            default:
                throw new Base.Exception.InvalidValueException("Unknown order action provided >" + action.ToString() + "<");
            }
            Base.Http.Request request = CreateRequest();
            if (stream != null)
            {
                request.AddMultipartContent(stream);
            }
            request.EndpointUri = string.Format("/v2/orders/{0}/{1}", purchaseOrderId, action);
            IResponse response = await client.PostAsync(request);

            return(response);
        }
        public async Task <string> GetCPAReport(string folderName)
        {
            Base.Http.Request request = CreateRequest();
            request.EndpointUri = "/v2/getReport?type=cpa";
            Base.Http.IResponse response = await client.GetAsync(request);

            return(await parseResponse(response, folderName));
        }
Exemplo n.º 6
0
 /// <summary>
 /// Perform OPTIONS and return response from URL.
 /// </summary>
 /// <param name="url"></param>
 /// <returns></returns>
 public static Energy.Base.Http.Response Options(string url)
 {
     Energy.Base.Http.Request request = new Base.Http.Request()
     {
         Method = "OPTIONS",
         Url    = url,
     };
     return(Execute(request));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Perform DELETE and return response from URL.
 /// </summary>
 /// <param name="url"></param>
 /// <returns></returns>
 public static Energy.Base.Http.Response Delete(string url)
 {
     Energy.Base.Http.Request request = new Base.Http.Request()
     {
         Method = "DELETE",
         Url    = url,
     };
     return(Execute(request));
 }
Exemplo n.º 8
0
 /// <summary>
 /// Perform HEAD and return response from URL.
 /// </summary>
 /// <param name="url"></param>
 /// <returns></returns>
 public static Energy.Base.Http.Response Head(string url)
 {
     Energy.Base.Http.Request request = new Base.Http.Request()
     {
         Method = "HEAD",
         Url    = url,
     };
     return(Execute(request));
 }
        public async Task <LagTime> GetLagTime(string merchantSku)
        {
            Base.Http.Request request = CreateRequest();
            request.EndpointUri = string.Format("/v2/lagtime?sku={0}", merchantSku);
            Base.Http.IResponse response = await client.GetAsync(request);

            LagTime result = await ProcessResponse <LagTime>(response);

            return(result);
        }
        public async Task <OrdersListType> GetAllOrders(string nextCursor)
        {
            Base.Http.Request request = CreateRequest();
            request.EndpointUri = string.Format("/v2/orders/{0}", nextCursor);
            IResponse response = await client.GetAsync(request);

            OrdersListType result = await ProcessResponse <OrdersListType>(response);

            return(result);
        }
Exemplo n.º 11
0
        public void FullfilRequest(Base.Http.Request request)
        {
            if (!string.IsNullOrEmpty(Sku))
            {
                request.QueryParams.Add("sku", Sku);
            }

            if (!string.IsNullOrEmpty(CustomerOrderId))
            {
                request.QueryParams.Add("customerOrderId", CustomerOrderId);
            }

            if (!string.IsNullOrEmpty(PurchaseOrderId))
            {
                request.QueryParams.Add("purchaseOrderId", PurchaseOrderId);
            }

            if (Status != null)
            {
                request.QueryParams.Add("status", Status.ToString());
            }

            if (CreatedStartDate != null)
            {
                request.QueryParams.Add("createdStartDate", CreatedStartDate?.ToString("yyyy-MM-dd"));
            }

            if (CreatedEndDate != null)
            {
                request.QueryParams.Add("createdEndDate", CreatedEndDate?.ToString("yyyy-MM-dd"));
            }

            if (FromExpectedShipDate != null)
            {
                request.QueryParams.Add("fromExpectedShipDate", FromExpectedShipDate?.ToString("yyyy-MM-dd"));
            }

            if (ToExpectedShipDate != null)
            {
                request.QueryParams.Add("toExpectedShipDate", ToExpectedShipDate?.ToString("yyyy-MM-dd"));
            }

            if (Limit < 1)
            {
                request.QueryParams.Add("limit", "1");
            }
            else if (Limit > 200)
            {
                request.QueryParams.Add("limit", "200");
            }
            else
            {
                request.QueryParams.Add("limit", Limit.ToString());
            }
        }
        public async Task <OrdersListType> GetAllOrders(OrderFilter filter)
        {
            Base.Http.Request request = CreateRequest();
            filter.FullfilRequest(request);
            request.EndpointUri = "/v2/orders";
            IResponse response = await client.GetAsync(request);

            OrdersListType result = await ProcessResponse <OrdersListType>(response);

            return(result);
        }
Exemplo n.º 13
0
        public void InvalidCredentialsResultsInException()
        {
            var config = new Mock <Base.Primitive.Config.IRequestConfig>();

            config.Setup(t => t.UserAgent).Returns("test user-agent");
            config.Setup(t => t.BaseUrl).Returns("http://www.test.com");
            config.Setup(t => t.Credentials).Returns(new Credentials("test", "invalid-key"));
            var request = new Base.Http.Request(config.Object);

            Assert.Throws <Base.Exception.SignatureException>(
                () => request.FinalizePreparation());
        }
        public async Task <Order> GetOrderById(string purchaseOrderId)
        {
            // avoiding deadlock if client execute this method synchronously
            await new ContextRemover();

            Base.Http.Request request = CreateRequest();
            request.EndpointUri = string.Format("/v2/orders/{0}", purchaseOrderId);
            IResponse response = await client.GetAsync(request);

            Order result = await ProcessResponse <Order>(response);

            return(result);
        }
        public async Task <OrdersListType> GetAllReleasedOrders(string nextCursor)
        {
            // to avoid deadlock if this method is executed synchronously
            await new ContextRemover();

            Base.Http.Request request = CreateRequest();
            request.EndpointUri = string.Format("/v2/orders/released/{0}", nextCursor);
            IResponse response = await client.GetAsync(request);

            OrdersListType result = await ProcessResponse <OrdersListType>(response);

            return(result);
        }
Exemplo n.º 16
0
        public async Task <ServiceResponse> GetPromotionPrice(string merchantSku)
        {
            // to avoid deadlock if this method is executed synchronously
            await new ContextRemover();

            Base.Http.Request request = CreateRequest();
            request.EndpointUri = string.Format("/v3/promo/sku/{0}", merchantSku);
            Base.Http.IResponse response = await client.GetAsync(request);

            ServiceResponse result = await ProcessResponse <ServiceResponse>(response);

            return(result);
        }
Exemplo n.º 17
0
        public async Task <Inventory> UpdateInventory(string merchantSku, string bodyContent)
        {
            // avoiding deadlock if client execute this method synchronously
            await new ContextRemover();

            Base.Http.Request request = PrepareUpdateInventoryRequest(merchantSku, bodyContent);

            Base.Http.IResponse response = await client.PutAsync(request);

            Inventory result = await ProcessResponse <Inventory>(response);

            return(result);
        }
        public async Task <ItemRetireResponse> RetireItem(string merchantSku)
        {
            await new ContextRemover();

            Base.Http.Request request = CreateRequest();
            request.EndpointUri = string.Format("/v3/items/{0}", merchantSku);

            Base.Http.IResponse response = await client.DeleteAsync(request);

            ItemRetireResponse result = await ProcessResponse <ItemRetireResponse>(response);

            return(result);
        }
Exemplo n.º 19
0
        private Base.Http.Request PrepareUpdateInventoryRequest(string merchantSku, string content)
        {
            if (string.IsNullOrEmpty(merchantSku))
            {
                throw new Base.Exception.InvalidValueException("Sku can't be empty for inventory update!");
            }

            Base.Http.Request request = CreateRequest();
            request.EndpointUri = "/v2/inventory";

            request.AddPayload(content);
            request.QueryParams.Add("sku", merchantSku);
            return(request);
        }
Exemplo n.º 20
0
        public async Task <ItemRetireResponse> RetireItem(string merchantSku)
        {
            // avoiding deadlock if client execute this method synchronously
            await new ContextRemover();

            Base.Http.Request request = CreateRequest();
            request.EndpointUri = string.Format("/v2/items/{0}", merchantSku);

            Base.Http.IResponse response = await client.DeleteAsync(request);

            ItemRetireResponse result = await ProcessResponse <ItemRetireResponse>(response);

            return(result);
        }
        public async Task <OrdersListType> GetAllOrders(OrderFilter filter)
        {
            // to avoid deadlock if this method is executed synchronously
            await new ContextRemover();

            Base.Http.Request request = CreateRequest();
            filter.FullfilRequest(request);
            request.EndpointUri = "/v3/orders";
            IResponse response = await client.GetAsync(request);

            OrdersListType result = await ProcessResponse <OrdersListType>(response);

            return(result);
        }
        public async Task <ItemResponse> GetItem(string merchantSku)
        {
            // to avoid deadlock if this method is executed synchronously
            await new ContextRemover();

            Base.Http.Request request = CreateRequest();
            request.EndpointUri = string.Format("/v3/items/{0}", merchantSku);

            Base.Http.IResponse response = await client.GetAsync(request);

            ItemResponses result = await ProcessResponse <ItemResponses>(response);

            return(result.ItemResponse[0]);
        }
Exemplo n.º 23
0
        public async Task <Inventory> GetInventory(string merchantSku)
        {
            // to avoid deadlock if this method is executed synchronously
            await new ContextRemover();

            Base.Http.Request request = CreateRequest();
            request.EndpointUri = "/v2/inventory";
            request.QueryParams.Add("sku", merchantSku);

            Base.Http.IResponse response = await client.GetAsync(request);

            Inventory result = await ProcessResponse <Inventory>(response);

            return(result);
        }
Exemplo n.º 24
0
        public async Task <AvailableReconFilesResponse> GetAvailableReconFiles()
        {
            // to avoid deadlock if this method is executed synchronously
            await new ContextRemover();

            Base.Http.Request request = CreateRequest();

            request.EndpointUri = "/v3/report/reconreport/availableReconFiles";

            IResponse response = await client.GetAsync(request);

            AvailableReconFilesResponse result = await ProcessResponse <AvailableReconFilesResponse>(response);

            return(result);
        }
Exemplo n.º 25
0
        public async Task <Inventory> UpdateInventory(string merchantSku, System.IO.Stream stream)
        {
            // avoiding deadlock if client execute this method synchronously
            await new ContextRemover();

            var content = new StreamReader(stream).ReadToEnd();

            Base.Http.Request request = PrepareUpdateInventoryRequest(merchantSku, content);

            Base.Http.IResponse response = await client.PutAsync(request);

            Inventory result = await ProcessResponse <Inventory>(response);

            return(result);
        }
Exemplo n.º 26
0
        public async Task <Inventory> UpdateInventory(Inventory inventory)
        {
            // to avoid deadlock if this method is executed synchronously
            await new ContextRemover();

            // enforce XML serializer here, API doesn't support JSON in requests
            var content = payloadFactory.GetSerializer(ApiFormat.XML).Serialize <Inventory>(inventory);

            Base.Http.Request request = PrepareUpdateInventoryRequest(inventory.Sku, content);

            Base.Http.IResponse response = await client.PutAsync(request);

            Inventory result = await ProcessResponse <Inventory>(response);

            return(result);
        }
        public async Task <RefundResponse> IssueRefund(string returnOrderId, RefundRequest refundRequest)
        {
            // to avoid deadlock if this method is executed synchronously
            await new ContextRemover();

            Base.Http.Request request = CreateRequest();

            request.EndpointUri = string.Format("/v3/returns/{0}/refund", returnOrderId);
            request.AddPayload(GetSerializer().Serialize(refundRequest));

            IResponse response = await client.PostAsync(request);

            RefundResponse result = await ProcessResponse <RefundResponse>(response);

            return(result);
        }
Exemplo n.º 28
0
        public async Task <string> SaveReconFile(string date, string directoryToSaveCsvTo)
        {
            // to avoid deadlock if this method is executed synchronously
            await new ContextRemover();

            Base.Http.Request request = CreateRequest();

            request.EndpointUri = string.Format("/v3/report/reconreport/reconFile?reportDate={0}", date);
            request.HttpRequest.Headers.Add("Accept", "application/octet-stream");

            IResponse response = await client.GetAsync(request);

            var destinationFilePath = await SaveReportFile(response, directoryToSaveCsvTo);

            return(destinationFilePath);
        }
Exemplo n.º 29
0
        public async Task <byte[]> GetReconFile(string date)
        {
            // to avoid deadlock if this method is executed synchronously
            await new ContextRemover();

            Base.Http.Request request = CreateRequest();

            request.EndpointUri = string.Format("/v3/report/reconreport/reconFile?reportDate={0}", date);
            request.HttpRequest.Headers.Add("Accept", "application/octet-stream");

            IResponse response = await client.GetAsync(request);

            var result = await response.RawResponse.Content.ReadAsByteArrayAsync();

            return(result);
        }
        public async Task <FeedAcknowledgement> UploadFeed(System.IO.Stream file, V3.Payload.FeedType feedType)
        {
            // to avoid deadlock if this method is executed synchronously
            await new ContextRemover();

            Base.Http.Request request = CreateRequest();
            request.EndpointUri = "/v3/feeds";

            request.QueryParams.Add("feedType", feedType.ToString());
            request.AddMultipartContent(file);

            Base.Http.IResponse response = await client.PostAsync(request);

            FeedAcknowledgement result = await ProcessResponse <FeedAcknowledgement>(response);

            return(result);
        }