Example #1
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));
        }
Example #2
0
        /// <summary>
        /// Updates the given <see cref="ShopifyPage"/>. Id must not be null.
        /// </summary>
        /// <param name="pageId">The <see cref="ShopifyPage"/> pageId to update.</param>
        /// <param name="metafield">The <see cref="ShopifyMetaField"/> to update.</param>
        /// <returns>The updated <see cref="ShopifyMetaField"/>.</returns>
        public async Task <ShopifyMetaField> UpdateMetafieldAsync(long pageId, ShopifyMetaField metafield)
        {
            var requestPath = $"pages/{pageId}/metafields.json";
            var method      = Method.POST;

            if (metafield.Id.HasValue)
            {
                requestPath = $"pages/{pageId}/metafields/{metafield.Id.Value}.json";
                method      = Method.PUT;
            }

            IRestRequest req = RequestEngine.CreateRequest(requestPath, method, "metafield");

            req.AddJsonBody(new { metafield });

            return(await RequestEngine.ExecuteRequestAsync <ShopifyMetaField>(_RestClient, req));
        }
Example #3
0
        /// <summary>
        /// Creates a new <see cref="ShopifyMetaField"/> associated with the provided resource and resource id. Leave both resourceType and resourceId null for shop metafields.
        /// </summary>
        /// <param name="metafield">A new <see cref="ShopifyMetaField"/>. Id should be set to null.</param>
        /// <param name="resourceId">The Id of the resource the metafield will be associated with. This can be variants, products, orders, customers, custom_collections, etc.</param>
        /// <param name="resourceType">The resource type the metaifeld will be associated with. This can be variants, products, orders, customers, custom_collections, etc.</param>
        /// <returns>The new <see cref="ShopifyMetaField"/>.</returns>
        public async Task <ShopifyMetaField> CreateAsync(ShopifyMetaField metafield, long?resourceId, string resourceType = null)
        {
            string reqPath = "metafields.json";

            if (resourceType != null && resourceId != null)
            {
                reqPath = $"{resourceType}/{resourceId}/metafields.json";
            }
            IRestRequest req = RequestEngine.CreateRequest(reqPath, Method.POST, "metafield");

            //Build the request body
            Dictionary <string, object> body = new Dictionary <string, object>()
            {
                { "metafield", metafield }
            };

            req.AddJsonBody(body);

            return(await RequestEngine.ExecuteRequestAsync <ShopifyMetaField>(_RestClient, req));
        }
        /// <summary>
        /// Updates the given <see cref="ShopifyPage"/>. Id must not be null.
        /// </summary>
        /// <param name="pageId">The <see cref="ShopifyPage"/> pageId to update.</param>
        /// <param name="metafield">The <see cref="ShopifyMetaField"/> to update.</param>
        /// <returns>The updated <see cref="ShopifyMetaField"/>.</returns>
        public async Task<ShopifyMetaField> UpdateMetafieldAsync(long pageId, ShopifyMetaField metafield)
        {
            var requestPath = $"pages/{pageId}/metafields.json";
            var method = Method.POST;

            if (metafield.Id.HasValue)
            {
                requestPath = $"pages/{pageId}/metafields/{metafield.Id.Value}.json";
                method = Method.PUT;
            }

            IRestRequest req = RequestEngine.CreateRequest(requestPath, method, "metafield");

            req.AddJsonBody(new {metafield});
            
            return await RequestEngine.ExecuteRequestAsync<ShopifyMetaField>(_RestClient, req);
        }
        /// <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);
        }
        /// <summary>
        /// Creates a new <see cref="ShopifyMetaField"/> associated with the provided resource and resource id. Leave both resourceType and resourceId null for shop metafields.
        /// </summary>
        /// <param name="metafield">A new <see cref="ShopifyMetaField"/>. Id should be set to null.</param>
        /// <param name="resourceId">The Id of the resource the metafield will be associated with. This can be variants, products, orders, customers, custom_collections, etc.</param>
        /// <param name="resourceType">The resource type the metaifeld will be associated with. This can be variants, products, orders, customers, custom_collections, etc.</param>
        /// <returns>The new <see cref="ShopifyMetaField"/>.</returns>
        public async Task<ShopifyMetaField> CreateAsync(ShopifyMetaField metafield, long? resourceId, string resourceType = null)
        {
            string reqPath = "metafields.json";
            if (resourceType != null && resourceId != null)
            {
                reqPath = $"{resourceType}/{resourceId}/metafields.json";
            }
            IRestRequest req = RequestEngine.CreateRequest(reqPath, Method.POST, "metafield");

            //Build the request body
            Dictionary<string, object> body = new Dictionary<string, object>()
            {
                { "metafield", metafield }
            };

            req.AddJsonBody(body);

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