class BunnyCdn::Storage

Public Class Methods

apiKey() click to toggle source

Sets the apiKey to that in configuration

# File lib/bunny_cdn/storage.rb, line 26
def self.apiKey
  BunnyCdn.configuration.accessKey
end
deleteFile(path= '', file) click to toggle source

Deletes a file from the storage zone Params:

path

path to delete file from

file

specific file to delete from storage zone

# File lib/bunny_cdn/storage.rb, line 102
def self.deleteFile(path= '', file)
  begin
    response = RestClient.delete("#{set_region_url}/#{storageZone}/#{path}/#{file}", headers)
  rescue RestClient::ExceptionWithResponse => exception
    return exception
  end
  return response.body
end
getFile(path= '', file) click to toggle source

Gets a single file from the storage zone Params:

path

desired path to get file

file

specific file to get from storage zone

# File lib/bunny_cdn/storage.rb, line 53
def self.getFile(path= '', file)
  begin
    response = RestClient.get("#{set_region_url}/#{storageZone}/#{path}/#{file}", headers)
  rescue RestClient::ExceptionWithResponse => exception
    return exception
  end
  return response.body
end
getZoneFiles(path= '') click to toggle source

Gets all the files from the storage zone Params:

path

desired path to get files

# File lib/bunny_cdn/storage.rb, line 40
def self.getZoneFiles(path= '')
  begin
    response = RestClient.get("#{set_region_url}/#{storageZone}/#{path}", headers)
  rescue RestClient::ExceptionWithResponse => exception
    return exception
  end
  return response.body
end
headers() click to toggle source

Sets the necessary headers to make requests to the BunnyCDN API

# File lib/bunny_cdn/storage.rb, line 31
def self.headers
  {
    :accesskey => apiKey
  }
end
set_region_url() click to toggle source

Sets the proper URL based on the region set in configuration

# File lib/bunny_cdn/storage.rb, line 12
def self.set_region_url
  case BunnyCdn.configuration.region
  when nil || 'eu'
    'https://storage.bunnycdn.com'
  when 'ny'
    'https://ny.storage.bunnycdn.com'
  when 'la'
    'https://la.storage.bunnycdn.com'
  when 'sg'
    'https://sg.storage.bunnycdn.com'
  end
end
storageZone() click to toggle source

Sets the storage zone as set in configuration

# File lib/bunny_cdn/storage.rb, line 7
def self.storageZone
  BunnyCdn.configuration.storageZone
end
uploadFile(path= '', file) click to toggle source

Uploads a file on the system to the storage zone Params:

path

desired path to upload file

file

specific file to upload to storage zone

# File lib/bunny_cdn/storage.rb, line 66
def self.uploadFile(path= '', file)
  fileName = File.basename(file)
  headers = {
    :accessKey => apiKey,
    :checksum => ''
  }
  begin
    response = RestClient.put("#{set_region_url}/#{storageZone}/#{path}/#{fileName}", File.read(file), headers)
  rescue RestClient::ExceptionWithResponse => exception
    return exception
  end
  return response.body
end
uploadFormFile(path= '', file) click to toggle source

Uploads a file from a file input to the storage zone Params:

path

desired path to upload file

file

specific file to upload to storage zone

# File lib/bunny_cdn/storage.rb, line 84
def self.uploadFormFile(path= '', file)
  fileName = file.original_filename
  headers = {
    :accessKey => apiKey,
    :checksum => ''
  }
  begin
    response = RestClient.put("#{set_region_url}/#{storageZone}/#{path}/#{fileName}", File.read(file.tempfile), headers)
  rescue RestClient::ExceptionWithResponse => exception
    return exception
  end
  return response.body
end