/// <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/{themeId}/assets.json", Method.PUT, "asset"); req.AddJsonBody(new { asset = asset }); return await RequestEngine.ExecuteRequestAsync<ShopifyAsset>(_RestClient, req); }
public ShopifyAsset DownloadShopifyAsset(long themeId, ShopifyAsset asset) { ShopifyAsset downloadedAsset = null; var cridentials = _shopifyAuthenticationService.GetCridentials(); using (var webClient = new WebClient()) { webClient.Credentials = cridentials; var url = GetRequestUrl(string.Format("themes/{0}/assets.json?asset[key]={1}&theme_id={0}", themeId, asset.Key)); var json = webClient.DownloadString(url); var downloadedAssetContainer = JsonConvert.DeserializeObject <ShopifyAssetContainer>(json); downloadedAsset = downloadedAssetContainer.Asset; } return(downloadedAsset); }
public ShopifyAsset Update(ShopifyAsset asss) { return(base.Update(asss, asss.ThemeId, $"/admin/themes/{asss.ThemeId}/assets.json")); }