Module: Fastly::Fetcher
- Included in:
- Fastly
- Defined in:
- lib/fastly/fetcher.rb
Overview
Encapsulates HTTP client interactions
Instance Method Summary collapse
-
#client(opts = {}) ⇒ Object
Get the current Fastly::Client.
- #create(klass, opts) ⇒ Object
- #delete(klass, obj) ⇒ Object
- #get(klass, *args) ⇒ Object
- #list(klass, opts = {}) ⇒ Object
- #update(klass, obj) ⇒ Object
Instance Method Details
#client(opts = {}) ⇒ Object
Get the current Fastly::Client
16 17 18 |
# File 'lib/fastly/fetcher.rb', line 16 def client(opts = {}) @client ||= Client.new(opts) end |
#create(klass, opts) ⇒ Object
35 36 37 38 |
# File 'lib/fastly/fetcher.rb', line 35 def create(klass, opts) hash = client.post(klass.post_path(opts), opts) klass.new(hash, self) end |
#delete(klass, obj) ⇒ Object
45 46 47 |
# File 'lib/fastly/fetcher.rb', line 45 def delete(klass, obj) client.delete(klass.delete_path(obj)) end |
#get(klass, *args) ⇒ Object
26 27 28 29 30 31 32 33 |
# 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 hash.nil? ? nil : 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
40 41 42 43 |
# File 'lib/fastly/fetcher.rb', line 40 def update(klass, obj) hash = client.put(klass.put_path(obj), obj.as_hash) klass.new(hash, self) end |