Sha256: 543831ac96885e15f78ed3bb1cfca1a0ba437dc97013879f66a22acfc772578e

Contents?: true

Size: 1.6 KB

Versions: 2

Compression:

Stored size: 1.6 KB

Contents

module BunnyCdn
  class Pullzone

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

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

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

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

    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

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

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

    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bunny_cdn-1.0.1 lib/bunny_cdn/pullzone.rb
bunny_cdn-1.0.0 lib/bunny_cdn/pullzone.rb