Module: Fastly::Fetcher

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

Overview

:nodoc: all

Instance Method Summary collapse

Instance Method Details

#client(opts = {}) ⇒ Object

Get the current Fastly::Client



14
15
16
17
18
# File 'lib/fastly/fetcher.rb', line 14

def client(opts={})
  opts[:base_url]  ||= 'api.fastly.com'
  opts[:base_port] ||= 80
  @client ||= Fastly::Client.new(opts)
end

#create(klass, opts) ⇒ Object



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

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

#delete(klass, obj) ⇒ Object



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

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

#get(klass, *args) ⇒ Object



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

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
  return nil if hash.nil?
  return klass.new(hash, self)
end

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



20
21
22
23
24
# File 'lib/fastly/fetcher.rb', line 20

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



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

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