Beispiel #1
0
        /// <summary>
        /// Returns the shop's <see cref="ShopifyShop"/> information.
        /// </summary>
        /// <returns></returns>
        public virtual async Task <ShopifyShop> GetAsync()
        {
            IRestRequest request = RequestEngine.CreateRequest("shop.json", Method.GET, "shop");

            //Make request
            return(await RequestEngine.ExecuteRequestAsync <ShopifyShop>(_RestClient, request));
        }
Beispiel #2
0
        /// <summary>
        /// Creates a <see cref="ShopifyUsageCharge"/>.
        /// </summary>
        /// <param name="recurringChargeId">The id of the <see cref="ShopifyUsageCharge"/> that this usage charge belongs to.</param>
        /// <param name="description">The name or description of the usage charge.</param>
        /// <param name="price">The price of the usage charge.</param>
        /// <returns>The new <see cref="ShopifyUsageCharge"/>.</returns>
        public async Task <ShopifyUsageCharge> CreateAsync(long recurringChargeId, string description, double price)
        {
            var req = RequestEngine.CreateRequest($"recurring_application_charges/{recurringChargeId}/usage_charges.json", Method.POST, "usage_charge");

            req.AddJsonBody(new { usage_charge = new { description = description, price = price } });

            return(await RequestEngine.ExecuteRequestAsync <ShopifyUsageCharge>(_RestClient, req));
        }
        /// <summary>
        /// Updates the given <see cref="ShopifyPage"/>. Id must not be null.
        /// </summary>
        /// <param name="page">The <see cref="ShopifyPage"/> to update.</param>
        /// <returns>The updated <see cref="ShopifyPage"/>.</returns>
        public virtual async Task <ShopifyPage> UpdateAsync(ShopifyPage page)
        {
            IRestRequest req = RequestEngine.CreateRequest($"pages/{page.Id.Value}.json", Method.PUT, "page");

            req.AddJsonBody(new { page });

            return(await RequestEngine.ExecuteRequestAsync <ShopifyPage>(_RestClient, req));
        }
Beispiel #4
0
        /// <summary>
        /// Updates the given <see cref="ShopifyProductImage"/>. Id must not be null.
        /// </summary>
        /// <param name="productId">The id of the product that counted images belong to.</param>
        /// <param name="image">The <see cref="ShopifyProductImage"/> to update.</param>
        /// <returns>The updated <see cref="ShopifyProductImage"/>.</returns>
        public virtual async Task <ShopifyProductImage> UpdateAsync(long productId, ShopifyProductImage image)
        {
            var req = RequestEngine.CreateRequest($"products/{productId}/images/{image.Id.Value}.json", Method.PUT, "image");

            req.AddJsonBody(new { image });

            return(await RequestEngine.ExecuteRequestAsync <ShopifyProductImage>(_RestClient, req));
        }
Beispiel #5
0
        /// <summary>
        /// Gets a count of all of the shop's customers.
        /// </summary>
        /// <returns>The count of all customers for the shop.</returns>
        public async Task <int> CountAsync()
        {
            IRestRequest req            = RequestEngine.CreateRequest("customers/count.json", Method.GET);
            JToken       responseObject = await RequestEngine.ExecuteRequestAsync(_RestClient, req);

            //Response looks like { "count" : 123 }. Does not warrant its own class.
            return(responseObject.Value <int>("count"));
        }
        /// <summary>
        /// Creates a <see cref="ShopifyCharge"/>.
        /// </summary>
        /// <param name="charge">The <see cref="ShopifyCharge"/> to create.</param>
        /// <returns>The new <see cref="ShopifyCharge"/>.</returns>
        public async Task <ShopifyCharge> CreateAsync(ShopifyCharge charge)
        {
            IRestRequest req = RequestEngine.CreateRequest("application_charges.json", Method.POST, "application_charge");

            req.AddJsonBody(new { application_charge = charge });

            return(await RequestEngine.ExecuteRequestAsync <ShopifyCharge>(_RestClient, req));
        }
Beispiel #7
0
        /// <summary>
        /// Updates the given <see cref="ShopifyWebhook"/>. Id must not be null.
        /// </summary>
        /// <param name="webhook">The <see cref="ShopifyWebhook"/> to update.</param>
        /// <returns>The updated <see cref="ShopifyWebhook"/>.</returns>
        public virtual async Task <ShopifyWebhook> UpdateAsync(ShopifyWebhook webhook)
        {
            IRestRequest req = RequestEngine.CreateRequest($"webhooks/{webhook.Id.Value}.json", Method.PUT, "webhook");

            req.AddJsonBody(new { webhook });

            return(await RequestEngine.ExecuteRequestAsync <ShopifyWebhook>(_RestClient, req));
        }
Beispiel #8
0
        /// <summary>
        /// Updates the given <see cref="ShopifyMetaField"/>. Id must not be null.
        /// </summary>
        /// <param name="metafield">The <see cref="ShopifyMetaField"/> to update.</param>
        /// <returns>The updated <see cref="ShopifyMetaField"/>.</returns>
        public async Task <ShopifyMetaField> UpdateAsync(ShopifyMetaField metafield)
        {
            IRestRequest req = RequestEngine.CreateRequest($"metafields/{metafield.Id.Value}.json", Method.PUT, "metafield");

            req.AddJsonBody(new { metafield });

            return(await RequestEngine.ExecuteRequestAsync <ShopifyMetaField>(_RestClient, req));
        }
Beispiel #9
0
        /// <summary>
        /// Updates the given <see cref="ShopifySmartCollection"/>. Id must not be null.
        /// </summary>
        /// <param name="collection">The smart collection to update.</param>
        public virtual async Task <ShopifySmartCollection> UpdateAsync(ShopifySmartCollection collection)
        {
            var req = RequestEngine.CreateRequest($"smart_collections/{collection.Id.Value}.json", Method.PUT, "smart_collection");

            req.AddJsonBody(new { smart_collection = collection });

            return(await RequestEngine.ExecuteRequestAsync <ShopifySmartCollection>(_RestClient, req));
        }
Beispiel #10
0
        /// <summary>
        /// Creates a new <see cref="ShopifyTransaction"/> of the given kind.
        /// </summary>
        /// <param name="orderId">The order id to which the fulfillments belong.</param>
        /// <param name="transaction">The transaction.</param>
        /// <returns>The new <see cref="ShopifyTransaction"/>.</returns>
        public virtual async Task <ShopifyTransaction> CreateAsync(long orderId, ShopifyTransaction transaction)
        {
            var req = RequestEngine.CreateRequest($"orders/{orderId}/transactions.json", Method.POST, "transaction");

            req.AddJsonBody(new { transaction = transaction });

            return(await RequestEngine.ExecuteRequestAsync <ShopifyTransaction>(_RestClient, req));
        }
Beispiel #11
0
        /// <summary>
        /// Gets a count of all of the shop's transactions.
        /// </summary>
        /// <param name="orderId">The order id to which the fulfillments belong.</param>
        /// <returns>The count of all fulfillments for the shop.</returns>
        public virtual async Task <int> CountAsync(long orderId)
        {
            var req            = RequestEngine.CreateRequest($"orders/{orderId}/transactions/count.json", Method.GET);
            var responseObject = await RequestEngine.ExecuteRequestAsync(_RestClient, req);

            //Response looks like { "count" : 123 }. Does not warrant its own class.
            return(responseObject.Value <int>("count"));
        }
        /// <summary>
        /// Updates the given <see cref="ShopifyProductVariant"/>. Id must not be null.
        /// </summary>
        /// <param name="variant">The variant to update.</param>
        public async Task <ShopifyProductVariant> UpdateAsync(ShopifyProductVariant variant)
        {
            var req = RequestEngine.CreateRequest($"variants/{variant.Id.Value}.json", Method.PUT, "variant");

            req.AddJsonBody(new { variant });

            return(await RequestEngine.ExecuteRequestAsync <ShopifyProductVariant>(_RestClient, req));
        }
        /// <summary>
        /// Creates a new <see cref="ShopifyProductVariant"/>.
        /// </summary>
        /// <param name="productId">The product that the new variant will belong to.</param>
        /// <param name="variant">A new <see cref="ShopifyProductVariant"/>. Id should be set to null.</param>
        public async Task <ShopifyProductVariant> CreateAsync(long productId, ShopifyProductVariant variant)
        {
            var req = RequestEngine.CreateRequest($"products/{productId}/variants.json", Method.POST, "variant");

            req.AddJsonBody(new { variant });

            return(await RequestEngine.ExecuteRequestAsync <ShopifyProductVariant>(_RestClient, req));
        }
Beispiel #14
0
        /// <summary>
        /// Creates a new <see cref="ShopifySmartCollection"/>.
        /// </summary>
        /// <param name="collection">A new <see cref="ShopifySmartCollection"/>. Id should be set to null.</param>
        public async Task <ShopifySmartCollection> CreateAsync(ShopifySmartCollection collection)
        {
            var req = RequestEngine.CreateRequest($"smart_collections.json", Method.POST, "smart_collection");

            req.AddJsonBody(new { smart_collection = collection });

            return(await RequestEngine.ExecuteRequestAsync <ShopifySmartCollection>(_RestClient, req));
        }
Beispiel #15
0
        /// <summary>
        /// Cancels an order.
        /// </summary>
        /// <param name="orderId">The order's id.</param>
        /// <returns>The cancelled <see cref="ShopifyOrder"/>.</returns>
        public virtual async Task CancelAsync(long orderId, ShopifyOrderCancelOptions options = null)
        {
            IRestRequest req = RequestEngine.CreateRequest($"orders/{orderId}/cancel.json", Method.POST);

            req.AddJsonBody(options);

            await RequestEngine.ExecuteRequestAsync(_RestClient, req);
        }
Beispiel #16
0
        /// <summary>
        /// Updates the given <see cref="ShopifyProduct"/>. Id must not be null.
        /// </summary>
        /// <param name="product">The <see cref="ShopifyProduct"/> to update.</param>
        /// <returns>The updated <see cref="ShopifyProduct"/>.</returns>
        public virtual async Task <ShopifyProduct> UpdateAsync(ShopifyProduct product)
        {
            IRestRequest req = RequestEngine.CreateRequest($"products/{product.Id.Value}.json", Method.PUT, "product");

            req.AddJsonBody(new { product });

            return(await RequestEngine.ExecuteRequestAsync <ShopifyProduct>(_RestClient, req));
        }
        /// <summary>
        /// Updates the given <see cref="ShopifyOrderRisk"/>. Id must not be null.
        /// </summary>
        /// <param name="orderId">The order the risk belongs to.</param>
        /// <param name="risk">The risk to update.</param>
        public virtual async Task <ShopifyOrderRisk> UpdateAsync(long orderId, ShopifyOrderRisk risk)
        {
            var req = RequestEngine.CreateRequest($"orders/{orderId}/risks/{risk.Id.Value}.json", Method.PUT, "risk");

            req.AddJsonBody(new { risk });

            return(await RequestEngine.ExecuteRequestAsync <ShopifyOrderRisk>(_RestClient, req));
        }
        /// <summary>
        /// Creates a new <see cref="ShopifyRedirect"/> on the store. The redirect always starts out with a role of
        /// "unpublished." If the redirect has a different role, it will be assigned that only after all of its
        /// files have been extracted and stored by Shopify (which might take a couple of minutes).
        /// </summary>
        /// <param name="redirect">The new <see cref="ShopifyRedirect"/>.</param>
        /// <returns>The new <see cref="ShopifyRedirect"/>.</returns>
        public async Task <ShopifyRedirect> CreateAsync(ShopifyRedirect redirect)
        {
            IRestRequest req = RequestEngine.CreateRequest("redirects.json", Method.POST, "redirect");

            req.AddJsonBody(new { redirect });

            return(await RequestEngine.ExecuteRequestAsync <ShopifyRedirect>(_RestClient, req));
        }
        /// <summary>
        /// Updates the given <see cref="ShopifyFulfillment"/>. Id must not be null.
        /// </summary>
        /// <param name="orderId">The order id to which the fulfillments belong.</param>
        /// <param name="fulfillment">The <see cref="ShopifyFulfillment"/> to update.</param>
        /// <returns>The updated <see cref="ShopifyFulfillment"/>.</returns>
        public async Task <ShopifyFulfillment> UpdateAsync(long orderId, ShopifyFulfillment fulfillment)
        {
            var req = RequestEngine.CreateRequest($"orders/{orderId}/fulfillments/{fulfillment.Id.Value}.json", Method.PUT, "fulfillment");

            req.AddJsonBody(new { fulfillment });

            return(await RequestEngine.ExecuteRequestAsync <ShopifyFulfillment>(_RestClient, req));
        }
        /// <summary>
        /// Updates the given <see cref="ShopifyRedirect"/>. Id must not be null.
        /// </summary>
        /// <param name="redirect">The <see cref="ShopifyRedirect"/> to update.</param>
        /// <returns>The updated <see cref="ShopifyRedirect"/>.</returns>
        public async Task <ShopifyRedirect> UpdateAsync(ShopifyRedirect redirect)
        {
            IRestRequest req = RequestEngine.CreateRequest("redirects/{0}.json".FormatWith(redirect.Id.Value), Method.PUT, "redirect");

            req.AddJsonBody(new { redirect });

            return(await RequestEngine.ExecuteRequestAsync <ShopifyRedirect>(_RestClient, req));
        }
Beispiel #21
0
        /// <summary>
        /// Creates a new <see cref="ShopifyApplicationCredit"/>.
        /// </summary>
        /// <param name="credit">A new <see cref="ShopifyApplicationCredit"/>. Id should be set to null.</param>
        public virtual async Task <ShopifyApplicationCredit> CreateAsync(ShopifyApplicationCredit credit)
        {
            var req = RequestEngine.CreateRequest($"application_credits.json", Method.POST, "application_credit");

            req.AddJsonBody(new { application_credit = credit });

            return(await RequestEngine.ExecuteRequestAsync <ShopifyApplicationCredit>(_RestClient, req));
        }
        /// <summary>
        /// Creates or updates a <see cref="ShopifyAsset"/>. Both tasks use the same method due to the
        /// way Shopify API handles assets. If an asset has a unique <see cref="ShopifyAsset.Key"/> value,
        /// it will be created. If not, it will be updated. Copy an asset by setting the
        /// <see cref="ShopifyAsset.SourceKey"/> to the target's <see cref="ShopifyAsset.Key"/> value.
        /// Note: This will not return the asset's <see cref="ShopifyAsset.Value"/> property. You should
        /// use <see cref="GetAsync(long, string, string)"/> to refresh the value after creating or updating.
        /// </summary>
        /// <param name="themeId">The id of the theme that the asset belongs to.</param>
        /// <param name="asset">The asset.</param>
        /// <returns>The created or updated asset.</returns>
        public async Task <ShopifyAsset> CreateOrUpdateAsync(long themeId, ShopifyAsset asset)
        {
            IRestRequest req = RequestEngine.CreateRequest("themes/{0}/assets.json".FormatWith(themeId), Method.PUT, "asset");

            req.AddJsonBody(new { asset = asset });

            return(await RequestEngine.ExecuteRequestAsync <ShopifyAsset>(_RestClient, req));
        }
Beispiel #23
0
        /// <summary>
        /// Updates the given <see cref="ShopifyCustomer"/>. Id must not be null.
        /// </summary>
        /// <param name="customer">The <see cref="ShopifyCustomer"/> to update.</param>
        /// <returns>The updated <see cref="ShopifyCustomer"/>.</returns>
        public async Task <ShopifyCustomer> UpdateAsync(ShopifyCustomer customer)
        {
            IRestRequest req = RequestEngine.CreateRequest("customers/{0}.json".FormatWith(customer.Id.Value), Method.PUT, "customer");

            req.AddJsonBody(new { customer });

            return(await RequestEngine.ExecuteRequestAsync <ShopifyCustomer>(_RestClient, req));
        }
        /// <summary>
        /// Deletes a <see cref="ShopifyAsset"/> with the given key.
        /// </summary>
        /// <param name="themeId">The id of the theme that the asset belongs to.</param>
        /// <param name="key">The key value of the asset, e.g. 'templates/index.liquid' or 'assets/bg-body.gif'.</param>
        public async Task DeleteAsync(long themeId, string key)
        {
            IRestRequest req = RequestEngine.CreateRequest("themes/{0}/assets.json".FormatWith(themeId), Method.DELETE);

            req = SetAssetQuerystring(req, key, themeId);

            await RequestEngine.ExecuteRequestAsync(_RestClient, req);
        }
Beispiel #25
0
        /// <summary>
        /// Updates the given <see cref="ShopifyOrder"/>. Id must not be null.
        /// </summary>
        /// <param name="order">The <see cref="ShopifyOrder"/> to update.</param>
        /// <returns>The updated <see cref="ShopifyOrder"/>.</returns>
        public async Task <ShopifyOrder> UpdateAsync(ShopifyOrder order)
        {
            IRestRequest req = RequestEngine.CreateRequest($"orders/{order.Id.Value}.json", Method.PUT, "order");

            req.AddJsonBody(new { order });

            return(await RequestEngine.ExecuteRequestAsync <ShopifyOrder>(_RestClient, req));
        }
Beispiel #26
0
        /// <summary>
        /// Updates the given <see cref="ShopifyScriptTag"/>. Id must not be null.
        /// </summary>
        /// <param name="tag">The <see cref="ShopifyScriptTag"/> to update.</param>
        /// <returns>The updated <see cref="ShopifyScriptTag"/>.</returns>
        public async Task <ShopifyScriptTag> UpdateAsync(ShopifyScriptTag tag)
        {
            IRestRequest req = RequestEngine.CreateRequest("script_tags/{0}.json".FormatWith(tag.Id.Value), Method.PUT, "script_tag");

            req.AddJsonBody(new { script_tag = tag });

            return(await RequestEngine.ExecuteRequestAsync <ShopifyScriptTag>(_RestClient, req));
        }
        /// <summary>
        /// Updates the given <see cref="ShopifyTheme"/>. Id must not be null.
        /// </summary>
        /// <param name="theme">The <see cref="ShopifyTheme"/> to update.</param>
        /// <returns>The updated <see cref="ShopifyTheme"/>.</returns>
        public async Task <ShopifyTheme> UpdateAsync(ShopifyTheme theme)
        {
            IRestRequest req = RequestEngine.CreateRequest($"themes/{theme.Id.Value}.json", Method.PUT, "theme");

            req.AddJsonBody(new { theme });

            return(await RequestEngine.ExecuteRequestAsync <ShopifyTheme>(_RestClient, req));
        }
Beispiel #28
0
        /// <summary>
        /// Deletes a <see cref="ShopifyAsset"/> with the given key.
        /// </summary>
        /// <param name="themeId">The id of the theme that the asset belongs to.</param>
        /// <param name="key">The key value of the asset, e.g. 'templates/index.liquid' or 'assets/bg-body.gif'.</param>
        public virtual async Task DeleteAsync(long themeId, string key)
        {
            IRestRequest req = RequestEngine.CreateRequest($"themes/{themeId}/assets.json", Method.DELETE);

            req = SetAssetQuerystring(req, key, themeId);

            await RequestEngine.ExecuteRequestAsync(_RestClient, req);
        }
Beispiel #29
0
        /// <summary>
        /// Creates a new <see cref="ShopifyWebhook"/> on the store.
        /// </summary>
        /// <param name="webhook">A new <see cref="ShopifyWebhook"/>. Id should be set to null.</param>
        /// <returns>The new <see cref="ShopifyWebhook"/>.</returns>
        public virtual async Task <ShopifyWebhook> CreateAsync(ShopifyWebhook webhook)
        {
            IRestRequest req = RequestEngine.CreateRequest("webhooks.json", Method.POST, "webhook");

            //Build the request body
            req.AddJsonBody(new { webhook });

            return(await RequestEngine.ExecuteRequestAsync <ShopifyWebhook>(_RestClient, req));
        }
        /// <summary>
        /// Retrieves the <see cref="ShopifyTheme"/> with the given id.
        /// </summary>
        /// <param name="themeId">The id of the theme to retrieve.</param>
        /// <param name="fields">A comma-separated list of fields to return.</param>
        /// <returns>The <see cref="ShopifyTheme"/>.</returns>
        public async Task <ShopifyTheme> GetAsync(long themeId, string fields = null)
        {
            IRestRequest req = RequestEngine.CreateRequest($"themes/{themeId}.json", Method.GET, "theme");

            if (string.IsNullOrEmpty(fields) == false)
            {
                req.AddParameter("fields", fields);
            }

            return(await RequestEngine.ExecuteRequestAsync <ShopifyTheme>(_RestClient, req));
        }