Class: BunnyCdn::Pullzone

Inherits:
Object
  • Object
show all
Defined in:
lib/bunny_cdn/pullzone.rb

Constant Summary collapse

BASE_URL =

URL to for BunnyCDN’s Pullzone API

'https://bunnycdn.com/api/pullzone'

Class Method Summary collapse

Class Method Details

.apiKeyObject

Sets the apiKey to that in configuration



9
10
11
# File 'lib/bunny_cdn/pullzone.rb', line 9

def self.apiKey
  @apiKey = BunnyCdn.configuration.apiKey
end

.createPullzone(name, type = 0, originUrl) ⇒ Object

Creates a new pullzone Params:

name

the name of the new Pull Zone

type

the pricing type of the pull zone you wish to add. 0 = Standard, 1 = High Volume

originURL+

the origin URL where the pull zone files are pulled from.



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/bunny_cdn/pullzone.rb', line 37

def self.createPullzone(name, type = 0, originUrl)
  values = {
    :name => name,
    :type => type,
    :originUrl => originUrl
  }
  begin
    response = RestClient.post(BASE_URL, values.to_json, headers)
  rescue RestClient::ExceptionWithResponse => exception
    return exception
  end
  return response
end

.deletePullzone(id) ⇒ Object

Deletes the pull zone using the given ID Params:

id

the ID of the Pull Zone to delete



66
67
68
69
70
71
72
73
# File 'lib/bunny_cdn/pullzone.rb', line 66

def self.deletePullzone(id)
  begin
    response = RestClient.delete("#{BASE_URL}/#{id}", headers)
  rescue RestClient::ExceptionWithResponse => exception
    return exception
  end
  return response
end

.getAllPullzonesObject

Gets all Pull Zones from BunnyCDN



23
24
25
26
27
28
29
30
# File 'lib/bunny_cdn/pullzone.rb', line 23

def self.getAllPullzones
  begin
    response = RestClient.get(BASE_URL, headers)
  rescue RestClient::ExceptionWithResponse => exception
    return exception
  end
  return response
end

.getSinglePullzone(id) ⇒ Object

Gets the details of the pull zone using the given ID Params:

id

the ID of the Pull Zone to return



54
55
56
57
58
59
60
61
# File 'lib/bunny_cdn/pullzone.rb', line 54

def self.getSinglePullzone(id)
  begin
    response = RestClient.get("#{BASE_URL}/#{id}", headers)
  rescue RestClient::ExceptionWithResponse => exception
    return exception
  end
  return response
end

.headersObject

Sets the necessary headers to make requests to the BunnyCDN API



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

def self.headers
  {
    :accesskey => apiKey,
    :accept => 'application/json',
    :content_type => 'application/json'
  }
end

.purgeCache(id) ⇒ Object

Purges the cache for the Pull Zone using the given ID Params:

id

the ID of the zone which should have the cache purged



78
79
80
81
82
83
84
85
# File 'lib/bunny_cdn/pullzone.rb', line 78

def self.purgeCache(id)
  begin
    response = RestClient.post("#{BASE_URL}/#{id}/purgeCache", {}.to_json, headers)
  rescue RestClient::ExceptionWithResponse => exception
    return exception
  end
  return response
end