lib/fastly.rb in fastly-1.1.2 vs lib/fastly.rb in fastly-1.1.3
- old
+ new
@@ -13,11 +13,11 @@
require 'fastly/belongs_to_service_and_version'
require 'fastly/backend'
require 'fastly/cache_setting'
require 'fastly/condition'
require 'fastly/customer'
- require 'fastly/director'
+ require 'fastly/director'
require 'fastly/domain'
require 'fastly/header'
require 'fastly/healthcheck'
require 'fastly/gzip'
require 'fastly/invoice'
@@ -34,17 +34,17 @@
require 'fastly/version'
include Fastly::Fetcher
# Create a new Fastly client. Options are
- #
+ #
# user:: your Fastly login
# password:: your Fastly password
# api_key:: your Fastly api key
- #
- # You only need to pass in C<api_key> OR C<user> and C<password>.
- #
+ #
+ # You only need to pass in C<api_key> OR C<user> and C<password>.
+ #
# Some methods require full username and password rather than just auth token.
def initialize(opts)
self.client(opts)
self
end
@@ -76,18 +76,18 @@
# Set the current customer to act as.
# NOTE: this will only work if you're an admin
def set_customer(id)
raise Fastly::FullAuthRequired "You must be fully authed to set the customer" unless self.fully_authed?;
raise Fastly::AdminRequired "You must be an admin to set the customer" unless self.current_user.can_do?(:admin);
- @current_customer = nil
+ @current_customer = nil
client.set_customer(id);
end
# Return a hash representing all commands available.
#
# Useful for information.
- def commands
+ def commands
client.get('/commands')
end
# Purge the specified path from your cache.
def purge(path)
@@ -111,25 +111,25 @@
# 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.
#
@@ -152,19 +152,19 @@
# 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, CacheSetting, Condition, Director, Domain, Header, Healthcheck, Gzip, Match, Origin, RequestSetting, ResponseObject, Service, S3Logging, Syslog, VCL, Version].each do |klass|
+ [User, Customer, Backend, CacheSetting, Condition, Director, Domain, Header, Healthcheck, Gzip, Match, Origin, RequestSetting, ResponseObject, Service, S3Logging, Syslog, VCL, Version].each do |klass|
type = Util.class_to_path(klass)
# 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|
list(klass, *args)
end
end
-
+
self.send :define_method, "get_#{type}".to_sym do |*args|
get(klass, *args)
end
self.send :define_method, "create_#{type}".to_sym do |obj|
@@ -182,15 +182,15 @@
# :method: create_version(opts)
# opts must contain a service_id param
- ##
+ ##
# :method: create_backend(opts)
# opts must contain service_id, version and name params
- ##
+ ##
# :method: create_director(opts)
# opts must contain service_id, version and name params
##
# :method: reate_domain(opts)
@@ -201,15 +201,15 @@
# opts must contain service_id, version and name params
##
# :method: create_origin(opts)
# opts must contain service_id, version and name params
-
+
##
# :method: create_healthcheck(opts)
# opts must contain service_id, version and name params
-
+
##
# :method: create_s3_logging(opts)
# opts must contain service_id, version and name params
##
@@ -217,11 +217,11 @@
# 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
##
@@ -246,15 +246,15 @@
##
# :method: get_user(id)
# Get a User
- ##
+ ##
# :method: get_customer(id)
# Get a customer
- ##
+ ##
# :method: get_service(id)
# Get a Service
##
# :method: get_version(service_id, number)
@@ -262,371 +262,371 @@
##
# :method: get_backend(service_id, number, name)
# Get a backend
- ##
+ ##
# :method: get_director(service_id, number, name)
# Get a Director
- ##
+ ##
# :method: get_domain(service_id, number, name)
# Get a Domain
-
- ##
+
+ ##
# :method: get_healthcheck(service_id, number, name)
# Get a Healthcheck
- ##
+ ##
# :method: get_match(service_id, number, name)
# Get a Match
- ##
+ ##
# :method: get_origin(service_id, number, name)
# Get an Origin
##
# :method: get_s3_logging(service_id, number, name)
# Get a S3 logging
-
- ##
+
+ ##
# :method: get_syslog(service_id, number, name)
# Get a Syslog
- ##
+ ##
# :method: get_vcl(service_id, number, name)
# Get a VCL
- ##
+ ##
# :method: get_version(service_id, number, name)
# Get a Version
- ##
+ ##
# :method: get_settings(service_id, number, name)
# Get a Settings
- ##
+ ##
# :method: get_condition(service_id, number, name)
# Get a Condition
- ##
+ ##
# :method: get_cache_setting(service_id, number, name)
# Get a Cache Setting
- ##
+ ##
# :method: get_gzip(service_id, number, name)
# Get a Gzip
- ##
+ ##
# :method: get_header(service_id, number, name)
# Get a Header
- ##
+ ##
# :method: get_request_setting(service_id, number, name)
# Get a Request Setting
- ##
+ ##
# :method: get_response_object(service_id, number, name)
# Get a Response Object
##
# :method: update_user(user)
# You can also call
# user.save!
- ##
+ ##
# :method: update_customer(customer)
# You can also call
# customer.save!
- ##
+ ##
# :method: update_service(service)
# You can also call
# service.save!
- ##
+ ##
# :method: update_version(version)
# You can also call
# version.save!
- ##
+ ##
# :method: update_backend(backend)
# You can also call
# backend.save!
- ##
+ ##
# :method: update_director(director)
# You can also call
# director.save!
- ##
+ ##
# :method: update_domain(domain)
# You can also call
# domain.save!
-
- ##
+
+ ##
# :method: update_healthcheck(healthcheck)
# You can also call
# healthcheck.save!
- ##
+ ##
# :method: update_match(match)
# You can also call
# match.save!
- ##
+ ##
# :method: update_origin(origin)
# You can also call
# origin.save!
-
- ##
+
+ ##
# :method: update_settings(settings)
# You can also call
# settings.save!
- ##
+ ##
# :method: update_s3_logging(s3_logging)
# You can also call
# s3_logging.save!
- ##
+ ##
# :method: update_syslog(syslog)
# You can also call
# syslog.save!
- ##
+ ##
# :method: update_vcl(vcl)
# You can also call
# vcl.save!
- ##
+ ##
# :method: update_cache_setting(cache_setting)
# You can also call
# cache_setting.save!
- ##
+ ##
# :method: update_header(header)
# You can also call
# header.save!
- ##
+ ##
# :method: update_gzip(gzip)
# You can also call
# gzip.save!
- ##
+ ##
# :method: update_request_setting(request_setting)
# You can also call
# request_setting.save!
- ##
+ ##
# :method: update_response_object(response_object)
# You can also call
# response_object.save!
- ##
+ ##
# :method: update_condition(condition)
# You can also call
# condition.save!
- ##
+ ##
# :method: update_version(version)
# You can also call
# version.save!
- ##
- # :method: delete_user(user)
+ ##
+ # :method: delete_user(user)
# You can also call
# user.delete!
- ##
+ ##
# :method: delete_customer(customer)
# You can also call
# customer.delete!
- ##
+ ##
# :method: delete_service(service)
# You can also call
# service.delete!
- ##
+ ##
# :method: delete_version(version)
# You can also call
# version.delete!
- ##
+ ##
# :method:delete_backend(backend)
# You can also call
# backend.delete!
- ##
+ ##
# :method: delete_director(backend)
# You can also call
# backend.delete!
- ##
+ ##
# :method: delete_domain(domain
# You can also call
# domain.delete!
- ##
+ ##
# :method: delete_healthcheck(healthcheck)
# You can also call
# healthcheck.delete!
- ##
+ ##
# :method: delete_match(match)
# You can also call
# match.delete!(match)
- ##
+ ##
# :method: delete_origin(origin)
# You can also call
# origin.delete!
- ##
+ ##
# :method: delete_s3_logging(s3_logging)
# You can also call
# s3_logging.delete!
- ##
+ ##
# :method: delete_syslog(syslog)
# You can also call
# syslog.delete!
- ##
+ ##
# :method: delete_vcl(vcl)
# You can also call
# vcl.delete!
- ##
+ ##
# :method: delete_cache_setting(cache_setting)
# You can also call
# cache_setting.delete!
- ##
+ ##
# :method: delete_header(header)
# You can also call
# header.delete!
- ##
+ ##
# :method: delete_gzip(gzip)
# You can also call
# gzip.delete!
- ##
+ ##
# :method: delete_request_setting(request_setting)
# You can also call
# request_setting.delete!
- ##
+ ##
# :method: delete_response_object(response_object)
# You can also call
# response_object.delete!
- ##
+ ##
# :method: delete_condition(condition)
# You can also call
# condition.delete!
- ##
+ ##
# :method: delete_version(version)
# You can also call
# version.delete!
# :method: list_users(:service_id => service.id, :version => version.number)
- #
+ #
# Get a list of all users
# :method: list_customers(:service_id => service.id, :version => version.number)
- #
+ #
# Get a list of all customers
# :method: list_versions(:service_id => service.id, :version => version.number)
- #
+ #
# Get a list of all versions
# :method: list_services(:service_id => service.id, :version => version.number)
- #
+ #
# Get a list of all services
- # :method: list_backends(:service_id => service.id, :version => version.number)
- #
+ # :method: list_backends(:service_id => service.id, :version => version.number)
+ #
# Get a list of all backends
- # :method: list_directors(:service_id => service.id, :version => version.number)
- #
+ # :method: list_directors(:service_id => service.id, :version => version.number)
+ #
# Get a list of all directors
- # :method: list_domains(:service_id => service.id, :version => version.number)
- #
+ # :method: list_domains(:service_id => service.id, :version => version.number)
+ #
# Get a list of all domains
# :method: list_healthchecks(:service_id => service.id, :version => version.number)
- #
+ #
# Get a list of all healthchecks
# :method: list_matchs(:service_id => service.id, :version => version.number)
- #
+ #
# Get a list of all matches
- # :method: list_origins(:service_id => service.id, :version => version.number)
- #
+ # :method: list_origins(:service_id => service.id, :version => version.number)
+ #
# Get a list of all origins
# :method: list_syslogs(:service_id => service.id, :version => version.number)
- #
+ #
# Get a list of all syslogs
- # :method: list_vcls(:service_id => service.id, :version => version.number)
- #
+ # :method: list_vcls(:service_id => service.id, :version => version.number)
+ #
# Get a list of all vcls
-
- # :method: list_conditions(:service_id => service.id, :version => version.number)
- #
+
+ # :method: list_conditions(:service_id => service.id, :version => version.number)
+ #
# Get a list of all conditions
# :method: list_cache_settings(:service_id => service.id, :version => version.number)
- #
+ #
# Get a list of all cache settings
# :method: list_headers(:service_id => service.id, :version => version.number)
- #
+ #
# Get a list of all headers
# :method: list_gzips(:service_id => service.id, :version => version.number)
- #
+ #
# Get a list of all gzips
# :method: list_request_settings(:service_id => service.id, :version => version.number)
- #
+ #
# Get a list of all request_settings
# :method: list_response_objects(:service_id => service.id, :version => version.number)
- #
+ #
# Get a list of all response_objects
# :method: list_versions(:service_id => service.id, :version => version.number)
- #
+ #
# Get a list of all versions
##
# Attempts to load various config options in the form
- #
+ #
# <key> = <value>
- #
+ #
# From a file.
- #
+ #
# Skips whitespace and lines starting with C<#>.
#
def self.load_config(file)
options = {}
return options unless File.exist?(file)
@@ -644,16 +644,16 @@
end
options;
end
##
- # Tries to load options from the file[s] passed in using,
+ # Tries to load options from the file[s] passed in using,
# C<load_options>, stopping when it finds the first one.
- #
- # Then it overrides those options with command line options
+ #
+ # Then it overrides those options with command line options
# of the form
- #
+ #
# --<key>=<value>
#
def self.get_options(*files)
options = {}
files.each do |file|
@@ -662,10 +662,10 @@
break
end
while (ARGV.size>0 && ARGV[0] =~ /^-+(\w+)\=(\w+)$/) do
options[$1.to_sym] = $2;
- @ARGV.shift;
+ ARGV.shift;
end
raise"Couldn't find options from command line arguments or #{files.join(', ')}" unless options.size>0
options;
end
end