Skip to content

Instantly share code, notes, and snippets.

@ismasan
Created April 30, 2016 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ismasan/3e3b33ef51f52446196966e1b8d31f6c to your computer and use it in GitHub Desktop.
Save ismasan/3e3b33ef51f52446196966e1b8d31f6c to your computer and use it in GitHub Desktop.
Delete product images using the Ruby bootic API client.
require 'bootic_client'
# Configure the client with your credentials
BooticClient.configure do |c|
c.client_id = 'MY_CLIENT_ID'
c.client_secret = 'MY_CLIENT_SECRET'
c.logger = Logger.new(STDOUT) # optional
c.logging = true # optional
c.cache_store = Rails.cache # optional
end
# Instantiate a client
client = BooticClient.client(:client_credentials, scope: 'admin')
# Fetch the root resource and your default shop
root = client.root
shop = root.shops.first
# Iterate products and delete all images.
#
shop.products(status: 'all').full_set.each do |product|
# Fetch each product's detail resource
# so we can get ALL of its images
product = product.self
if product.has?(:images)
product.images.each do |a|
if a.has?(:delete_product_asset)
a.delete_product_asset
puts "Deleted #{product.slug}: #{a.file_name}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment