lib/bunny_cdn/storage.rb in bunny_cdn-1.0.2 vs lib/bunny_cdn/storage.rb in bunny_cdn-1.1.0
- old
+ new
@@ -1,16 +1,25 @@
module BunnyCdn
class Storage
RestClient.log = STDOUT # enables RestClient logging
- BASE_URL = 'https://storage.bunnycdn.com'
-
def self.storageZone
BunnyCdn.configuration.storageZone
end
-
+ # Sets the proper URL based on the region set in configuration
+ def self.set_region_url
+ case BunnyCdn.configuration.region
+ when nil || 'eu'
+ 'https://storage.bunnycdn.com'
+ when 'ny'
+ 'https://ny.storage.bunnycdn.com'
+ when 'sg'
+ 'https://sg.storage.bunnycdn.com'
+ end
+ end
+
def self.apiKey
BunnyCdn.configuration.accessKey
end
def self.headers
@@ -19,20 +28,20 @@
}
end
def self.getZoneFiles(path= '')
begin
- response = RestClient.get("#{BASE_URL}/#{storageZone}/#{path}", headers)
+ response = RestClient.get("#{set_region_url}/#{storageZone}/#{path}", headers)
rescue RestClient::ExceptionWithResponse => exception
return exception
end
return response.body
end
def self.getFile(path= '', file)
begin
- response = RestClient.get("#{BASE_URL}/#{storageZone}/#{path}/#{file}", headers)
+ response = RestClient.get("#{set_region_url}/#{storageZone}/#{path}/#{file}", headers)
rescue RestClient::ExceptionWithResponse => exception
return exception
end
return response.body
end
@@ -42,19 +51,19 @@
headers = {
:accessKey => apiKey,
:checksum => ''
}
begin
- response = RestClient.put("#{BASE_URL}/#{storageZone}/#{path}/#{fileName}", File.read(file), headers)
+ response = RestClient.put("#{set_region_url}/#{storageZone}/#{path}/#{fileName}", File.read(file), headers)
rescue RestClient::ExceptionWithResponse => exception
return exception
end
return response.body
end
def self.deleteFile(path= '', file)
begin
- response = RestClient.delete("#{BASE_URL}/#{storageZone}/#{path}/#{file}", headers)
+ response = RestClient.delete("#{set_region_url}/#{storageZone}/#{path}/#{file}", headers)
rescue RestClient::ExceptionWithResponse => exception
return exception
end
return response.body
end
\ No newline at end of file