Ejemplo n.º 1
0
        public async Task <ShopifyOrder[]> GetOrders(string username)
        {
            var creds = await GetCredentials(username);

            if (creds == null)
            {
                return(new ShopifyOrder[0]); //Not integrated into shopify
            }
            string endpoint = ShopifyEndpoints.BaseEndpoint(creds.Shop, "orders.json") + "?fulfillment_status=unshipped,partial";

            var response = await http.Get(endpoint, (client) =>
            {
                addAuthenticatoin(client, creds.AccessToken);
            });

            string message = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                var ordersResponse = JObject.Parse(message).SelectToken("orders").ToString();
                var ret            = JsonConvert.DeserializeObject <ShopifyOrder[]>(ordersResponse, jsonSettings);
                return(ret);
            }
            else
            {
                return(new ShopifyOrder[0]);
            }
        }
Ejemplo n.º 2
0
        public async Task <ShopifyProductModel[]> GetProductsByID(string username, string[] ids, OAuthShopifyModel creds)
        {
            string endpoint = ShopifyEndpoints.BaseEndpoint(creds.Shop, ShopifyEndpoints.Products) + $"?ids={String.Join(",", ids)}";

            var response = await http.Get(endpoint, (client) =>
            {
                addAuthenticatoin(client, creds.AccessToken);
            });

            string message = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                var productResponse = JObject.Parse(message).SelectToken("products").ToString();
                var ret             = JsonConvert.DeserializeObject <ShopifyProductModel[]>(productResponse, jsonSettings);

                foreach (var item in ret)
                {
                    item.Link = $"https://{creds.Shop}/admin/products/{item.ID}";
                }

                return(ret);
            }

            return(new ShopifyProductModel[0]);
        }
Ejemplo n.º 3
0
        public async Task <ShopifyProductModel> UpdateProduct(string username, ShopifyProductModel product, OAuthShopifyModel creds)
        {
            string endpoint = ShopifyEndpoints.BaseEndpoint(creds.Shop, "products") + $"/{product.ID}.json";

            var requestType = new
            {
                Product = product
            };

            var requestContent = JsonConvert.SerializeObject(requestType, jsonSettings);
            var content        = new StringContent(requestContent);

            content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

            var response = await http.Put(endpoint, content, (client) =>
            {
                addAuthenticatoin(client, creds.AccessToken);
            });

            string message = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                var productResponse = JObject.Parse(message).SelectToken("product").ToString();
                var ret             = JsonConvert.DeserializeObject <ShopifyProductModel>(productResponse, jsonSettings);
                return(ret);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 4
0
        public async Task <ShopifyProductModel[]> GetProducts(string username)
        {
            var creds = await GetCredentials(username);

            if (creds == null)
            {
                return(new ShopifyProductModel[0]); //Not integrated into shopify
            }
            string endpoint = ShopifyEndpoints.BaseEndpoint(creds.Shop, ShopifyEndpoints.Products);

            var response = await http.Get(endpoint, (client) =>
            {
                addAuthenticatoin(client, creds.AccessToken);
            });

            string message = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                var productResponse = JObject.Parse(message).SelectToken("product").ToString();
                var ret             = JsonConvert.DeserializeObject <ShopifyProductModel[]>(productResponse, jsonSettings);
                return(ret);
            }

            return(new ShopifyProductModel[0]);
        }