Class: BunnyCdn::Resources::PullZones

Inherits:
Base
  • Object
show all
Defined in:
lib/bunny_cdn/resources/pull_zones.rb

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from BunnyCdn::Resources::Base

Instance Method Details

#add_hostname(id, hostname) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bunny_cdn/resources/pull_zones.rb', line 32

def add_hostname(id, hostname)
  post("pullzone/#{id.to_i}/addHostname", {
    "Hostname" => hostname
  })
rescue ApiError => e
  if hostname_already_registered?(e)
    { "success" => true, "skipped" => true }
  else
    raise
  end
end

#create(name:, type:, origin_url:) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/bunny_cdn/resources/pull_zones.rb', line 14

def create(name:, type:, origin_url:)
  post("pullzone", {
    name: name,
    type: type,
    originUrl: origin_url
  })
end

#delete(id) ⇒ Object



22
23
24
25
26
# File 'lib/bunny_cdn/resources/pull_zones.rb', line 22

def delete(id)
  path = "pullzone/#{id.to_i}"
  response = connection.delete(path)
  handle_response(response, path)
end

#find(id) ⇒ Object



10
11
12
# File 'lib/bunny_cdn/resources/pull_zones.rb', line 10

def find(id)
  get("pullzone/#{id.to_i}")
end

#health_checkObject



52
53
54
55
56
57
# File 'lib/bunny_cdn/resources/pull_zones.rb', line 52

def health_check
  get("pullzone", { page: 1, perPage: 1 })
  true
rescue ApiError
  false
end

#list(page: 1, per_page: 1000) ⇒ Object



6
7
8
# File 'lib/bunny_cdn/resources/pull_zones.rb', line 6

def list(page: 1, per_page: 1000)
  get("pullzone?page=#{page}&perPage=#{per_page}")
end

#load_free_ssl(hostname:) ⇒ Object



44
45
46
# File 'lib/bunny_cdn/resources/pull_zones.rb', line 44

def load_free_ssl(hostname:)
  get("pullzone/loadFreeCertificate", { hostname: hostname })
end

#purge(id) ⇒ Object



28
29
30
# File 'lib/bunny_cdn/resources/pull_zones.rb', line 28

def purge(id)
  post("pullzone/#{id.to_i}/purgeCache")
end

#purge_by_tag(id, tag) ⇒ Object



48
49
50
# File 'lib/bunny_cdn/resources/pull_zones.rb', line 48

def purge_by_tag(id, tag)
  post("pullzone/#{id.to_i}/purgeCache?cacheTag=#{CGI.escape(tag)}", {})
end