* Add :fastly_http_purge feature flag * Add fastly.purge to EdgeCache::Bust::Fasty * Update app/services/edge_cache/bust/fastly.rb Co-authored-by: Michael Kohl <citizen428@dev.to> * Update app/services/edge_cache/bust/fastly.rb Co-authored-by: Michael Kohl <citizen428@dev.to> * Update spec/lib/data_update_scripts/add_fastly_http_purge_feature_flag_spec.rb Co-authored-by: Michael Kohl <citizen428@dev.to> * Improve specs applying the feedback * Deploy to BHC * Undo Travis changes Co-authored-by: Michael Kohl <citizen428@dev.to> Co-authored-by: Mac Siri <krairit.siri@gmail.com>
37 lines
967 B
Ruby
37 lines
967 B
Ruby
module EdgeCache
|
|
class Bust
|
|
class Fastly
|
|
# [@forem/systems] Fastly-enabled Forems don't need "flexible" domains.
|
|
def self.call(path)
|
|
api_key = ApplicationConfig["FASTLY_API_KEY"]
|
|
return fastly_purge(api_key, path) if FeatureFlag.enabled?(:fastly_http_purge)
|
|
|
|
fastly_post(api_key, path)
|
|
end
|
|
|
|
def self.fastly_post(api_key, path)
|
|
urls(path).map do |url|
|
|
HTTParty.post("https://api.fastly.com/purge/#{url}", headers: { "Fastly-Key" => api_key })
|
|
end
|
|
end
|
|
private_class_method :fastly_post
|
|
|
|
def self.fastly_purge(api_key, path)
|
|
fastly = ::Fastly.new(api_key: api_key)
|
|
|
|
urls(path).map do |url|
|
|
fastly.purge(url)
|
|
end
|
|
end
|
|
private_class_method :fastly_purge
|
|
|
|
def self.urls(path)
|
|
[
|
|
URL.url(path),
|
|
URL.url("#{path}?i=i"),
|
|
]
|
|
end
|
|
private_class_method :fastly_purge
|
|
end
|
|
end
|
|
end
|