lib/bunny_cdn/storage.rb in bunny_cdn-1.0.1 vs lib/bunny_cdn/storage.rb in bunny_cdn-1.0.2
- old
+ new
@@ -1,7 +1,9 @@
module BunnyCdn
class Storage
+
+ RestClient.log = STDOUT # enables RestClient logging
BASE_URL = 'https://storage.bunnycdn.com'
def self.storageZone
BunnyCdn.configuration.storageZone
@@ -16,30 +18,46 @@
:accesskey => apiKey
}
end
def self.getZoneFiles(path= '')
- response = RestClient.get("#{BASE_URL}/#{storageZone}/#{path}", headers)
+ begin
+ response = RestClient.get("#{BASE_URL}/#{storageZone}/#{path}", headers)
+ rescue RestClient::ExceptionWithResponse => exception
+ return exception
+ end
return response.body
end
def self.getFile(path= '', file)
- response = RestClient.get("#{BASE_URL}/#{storageZone}/#{path}/#{file}", headers)
+ begin
+ response = RestClient.get("#{BASE_URL}/#{storageZone}/#{path}/#{file}", headers)
+ rescue RestClient::ExceptionWithResponse => exception
+ return exception
+ end
return response.body
end
def self.uploadFile(path= '', file)
fileName = File.basename(file)
headers = {
:accessKey => apiKey,
:checksum => ''
}
- response = RestClient.put("#{BASE_URL}/#{storageZone}/#{path}/#{fileName}", File.read(file), headers)
+ begin
+ response = RestClient.put("#{BASE_URL}/#{storageZone}/#{path}/#{fileName}", File.read(file), headers)
+ rescue RestClient::ExceptionWithResponse => exception
+ return exception
+ end
return response.body
end
def self.deleteFile(path= '', file)
- response = RestClient.delete("#{BASE_URL}/#{storageZone}/#{path}/#{file}", headers)
+ begin
+ response = RestClient.delete("#{BASE_URL}/#{storageZone}/#{path}/#{file}", headers)
+ rescue RestClient::ExceptionWithResponse => exception
+ return exception
+ end
return response.body
end
end
end
\ No newline at end of file