Module: Cloudflare::Purge::PurgeAllFile

Included in:
Client
Defined in:
lib/cloudflare/purge/purge_all_file.rb

Instance Method Summary collapse

Instance Method Details

#purge_all_fileObject

Remove ALL files from Cloudflare’s cache api.cloudflare.com/#zone-purge-all-files



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cloudflare/purge/purge_all_file.rb', line 6

def purge_all_file
  uri = URI.parse("https://api.cloudflare.com/client/#{Cloudflare::Purge::ApiVersion::VERSION}/zones/#{config.zone_id}/purge_cache")
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  
  body = { purge_everything: true }
  
  headers = {
    'X-Auth-Email': config.email,
    'X-Auth-Key': config.auth_key,
    'Content-Type': "application/json",
  }
  
  response = http.post(uri.path, body.to_json, headers)
  
  parse_response = JSON.parse(response.body)
  
  raise StandardError.new "Failed purge all file: #{parse_response}" unless response.code == "200"
  raise StandardError.new "Failed purge all file: #{parse_response}" unless parse_response["success"]  
end