Skip to content

Instantly share code, notes, and snippets.

@mscoutermarsh
Created November 15, 2016 18:25
Show Gist options
  • Save mscoutermarsh/b79068669a1910d96f62fe446ad23f75 to your computer and use it in GitHub Desktop.
Save mscoutermarsh/b79068669a1910d96f62fe446ad23f75 to your computer and use it in GitHub Desktop.
Example Ruby for purging imgix cache
# usage: Set env variable IMGIX_API_KEY to your api key
# Need to add httparty to your gemfile
#
# Cdn::Purge.cache.call('urlhere')
class Cdn::PurgeCache
include HTTParty
API_KEY = ENV.fetch('IMGIX_API_KEY'.freeze)
base_uri 'https://api.imgix.com/v2'.freeze
class << self
def call(url)
new(url).call
end
end
def initialize(url)
@options = { body: { url: url }, basic_auth: { username: API_KEY, password: '' } }
end
def call
purge = self.class.post('/image/purger'.freeze, @options)
purge.success?
rescue Errno::ECONNRESET, SocketError
{ 'status' => 'failed' }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment