Sha256: 090af65b4c87f7388cf53ae9aee03a911c21f55fbb7335d5bc096a043fb79e87

Contents?: true

Size: 1.24 KB

Versions: 36

Compression:

Stored size: 1.24 KB

Contents

class Fastly
  # :nodoc:
  class AuthRequired < RuntimeError; end
  # :nodoc:
  class KeyAuthRequired < AuthRequired; end
  # :nodoc:
  class FullAuthRequired <  AuthRequired; end
  # :nodoc:
  class Error < RuntimeError; end
  # :nodoc:
  class Unauthorized < AuthRequired; end
  # :nodoc:
  class AdminRequired < AuthRequired; end

  # Encapsulates HTTP client interactions
  module Fetcher # :nodoc: all
    # Get the current Fastly::Client
    def client(opts = {})
      @client ||= Client.new(opts)
    end

    def list(klass, opts = {})
      list = client.get(klass.list_path(opts))
      return [] if list.nil?
      list.map { |hash| klass.new(hash, self) }
    end

    def get(klass, *args)
      if [User, Customer].include?(klass) && args.empty?
        hash = client.get("/current_#{klass.path}")
      else
        hash = client.get(klass.get_path(*args))
      end
      hash.nil? ? nil : klass.new(hash, self)
    end

    def create(klass, opts)
      hash = client.post(klass.post_path(opts), opts)
      klass.new(hash, self)
    end

    def update(klass, obj)
      hash = client.put(klass.put_path(obj), obj.as_hash)
      klass.new(hash, self)
    end

    def delete(klass, obj)
      client.delete(klass.delete_path(obj))
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
fastly-3.0.2 lib/fastly/fetcher.rb
fastly-3.0.1 lib/fastly/fetcher.rb
fastly-3.0.0 lib/fastly/fetcher.rb
fastly-2.5.3 lib/fastly/fetcher.rb
fastly-2.5.2 lib/fastly/fetcher.rb
fastly-2.5.1 lib/fastly/fetcher.rb
fastly-2.5.0 lib/fastly/fetcher.rb
fastly-2.4.0 lib/fastly/fetcher.rb
fastly-2.3.1 lib/fastly/fetcher.rb
fastly-2.3.0 lib/fastly/fetcher.rb
fastly-2.2.0 lib/fastly/fetcher.rb
fastly-2.1.0 lib/fastly/fetcher.rb
fastly-2.0.0 lib/fastly/fetcher.rb
fastly-1.15.0 lib/fastly/fetcher.rb
fastly-1.14.0 lib/fastly/fetcher.rb
fastly-1.13.2 lib/fastly/fetcher.rb
fastly-1.13.1 lib/fastly/fetcher.rb
fastly-1.13.0 lib/fastly/fetcher.rb
fastly-1.12.0 lib/fastly/fetcher.rb
fastly-1.11.0 lib/fastly/fetcher.rb