lib/fastly.rb in fastly-1.00 vs lib/fastly.rb in fastly-1.01
- old
+ new
@@ -2,13 +2,11 @@
# Copyright:: Copyright (c) 2011 Fastly Inc
# License:: Distributes under the same terms as Ruby
# A client library for interacting with the Fastly web acceleration service
class Fastly
- # The current version of the library
- VERSION = "1.00"
-
+ require 'fastly/gem_version'
require 'fastly/fetcher'
require 'fastly/client'
require 'fastly/base'
require 'fastly/belongs_to_service_and_version'
@@ -87,11 +85,69 @@
def purge(path)
res = client.post("/purge/#{path}")
#res = client.post("/purge/", :path => path)
end
+ # Fetches historical stats for each of your fastly services and groups the results by service id.
+ #
+ # If you pass in a :field opt then fetches only the specified field.
+ # If you pass in a :service opt then fetches only the specified service.
+ # The :field and :service opts can be combined.
+ #
+ # If you pass in an :aggregate flag then fetches historical stats information aggregated across all of your Fastly services. This cannot be combined with :field and :service.
+ #
+ # Other options available are:
+ #
+ # from:: earliest time from which to fetch historical statistics
+ # to:: latest time from which to fetch historical statistics
+ # by:: the sampling rate used to produce the result set (minute, hour, day)
+ # region:: restrict query to a particular region
+ #
+ # See http://docs.fastly.com/docs/stats for details.
+ def stats(opts)
+ raise Fastly::Error.new("You can't specify a field or a service for an aggregate request") if opts[:aggregate] && (opts[:field] || opts[:service])
+
+ url = "/stats"
+ if opts.delete(:aggregate)
+ url += "/aggregate"
+ end
+
+ if service = opts.delete(:service)
+ url += "/service/#{service}"
+ end
+
+ if field = opts.delete(:field)
+ url += "/field/#{field}"
+ end
+
+ client.get_stats(url, opts);
+ end
+
+ # Returns usage information aggregated across all Fastly services and grouped by region.
+ #
+ # If the :by_service flag is passed then teturns usage information aggregated by service and grouped by service & region.
+ #
+ # Other options available are:
+ #
+ # from:: earliest time from which to fetch historical statistics
+ # to:: latest time from which to fetch historical statistics
+ # by:: the sampling rate used to produce the result set (minute, hour, day)
+ # region:: restrict query to a particular region
+ #
+ # See http://docs.fastly.com/docs/stats for details.
+ def usage(opts)
+ url = "/stats/usage";
+ url += "_by_service" if opts.delete(:by_service)
+ client.get_stats(url, opts)
+ end
+
+ # Fetches the list of codes for regions that are covered by the Fastly CDN service.
+ def regions
+ client.get_stats("/stats/regions")
+ end
+
[User, Customer, Backend, Director, Domain, Healthcheck, Match, Origin, Service, Syslog, VCL, Version].each do |klass|
type = klass.to_s.downcase.split("::")[-1]
# unless the class doesn't have a list path or it already exists
unless klass.list_path.nil? || klass.respond_to?("list_#{type}s".to_sym)
self.send :define_method, "list_#{type}s".to_sym do |*args|
@@ -149,10 +205,14 @@
# opts must contain service_id, version and name params
##
# :method: create_vcl(opts)
# opts must contain service_id, version and name params
+
+ ##
+ # :method: create_condition(opts)
+ # opts must contain service_id, version and name params
##
# :method: get_user(id)
# Get a User
@@ -272,10 +332,15 @@
# :method: update_vcl(vcl)
# You can also call
# vcl.save!
##
+ # :method: update_condition(condition)
+ # You can also call
+ # condition.save!
+
+ ##
# :method: update_version(version)
# You can also call
# version.save!
@@ -344,10 +409,15 @@
# :method: delete_vcl(vcl)
# You can also call
# vcl.delete!
##
+ # :method: delete_condition(condition)
+ # You can also call
+ # condition.delete!
+
+ ##
# :method: delete_version(version)
# You can also call
# version.delete!
# :method: list_users
@@ -395,9 +465,13 @@
# Get a list of all syslogs
# :method: list_vcls
#
# Get a list of all vcls
+
+ # :method: list_conditions
+ #
+ # Get a list of all conditions
# :method: list_versions
#
# Get a list of all versions