Module: Fastly::Fetcher

Included in:
Fastly
Defined in:
lib/fastly/fetcher.rb

Overview

Encapsulates HTTP client interactions

Instance Method Summary collapse

Instance Method Details

#client(opts = {}) ⇒ Object

Get the current Fastly::Client



18
19
20
# File 'lib/fastly/fetcher.rb', line 18

def client(opts = {})
  @client ||= Client.new(opts)
end

#create(klass, opts) ⇒ Object



37
38
39
40
# File 'lib/fastly/fetcher.rb', line 37

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

#delete(klass, obj) ⇒ Object



47
48
49
# File 'lib/fastly/fetcher.rb', line 47

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

#get(klass, *args) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/fastly/fetcher.rb', line 28

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

#list(klass, opts = {}) ⇒ Object



22
23
24
25
26
# File 'lib/fastly/fetcher.rb', line 22

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

#update(klass, obj) ⇒ Object



42
43
44
45
# File 'lib/fastly/fetcher.rb', line 42

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