class Fastly
Top-level Fastly
class
The current version of the library
Invoice
object
Service
object
Settings
Object
Token
object
Constants
- VERSION
Attributes
Time between checks in milliseconds
The HTTP status to indicate a successful healthcheck (e.g. 200)
How many have to be ok for it work the first time
The HTTP method to use: GET, PUT, POST etc.
Public Class Methods
Tries to load options from the file passed in using, C<load_options>, stopping when it finds the first one.
Then it overrides those options with command line options of the form
--<key>=<value>
# File lib/fastly.rb, line 744 def self.get_options(*files) options = {} files.each do |file| next unless File.exist?(file) options = load_config(file) break end while ARGV.size > 0 && ARGV[0] =~ /^-+(\w+)\=(\w+)$/ options[$1.to_sym] = $2 ARGV.shift end fail "Couldn't find options from command line arguments or #{files.join(', ')}" unless options.size > 0 options end
Attempts to load various config options in the form
<key> = <value>
From a file.
Skips whitespace and lines starting with C<#>.
# File lib/fastly.rb, line 716 def self.load_config(file) options = {} return options unless File.exist?(file) File.open(file, 'r') do |infile| while line = infile.gets line.chomp! next if line =~ /^#/ next if line =~ /^\s*$/ next unless line =~ /=/ line.strip! key, val = line.split(/\s*=\s*/, 2) options[key.to_sym] = val end end options end
Create a new Fastly
client. Options are
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.
# File lib/fastly.rb, line 57 def initialize(opts) if opts[:api_key].nil? raise ArgumentError, "Required option missing. Please pass ':api_key'." end client(opts) self end
Public Instance Methods
Whether or not we're authed at all by either username & password or API key
# File lib/fastly.rb, line 67 def authed? client.authed? end
opts must contain service_id, version and name params
# File lib/fastly.rb, line 225
opts must contain service_id, version and name params
# File lib/fastly.rb, line 273
opts must contain service_id, version and name params
# File lib/fastly.rb, line 269
opts must contain service_id, version and name params
# File lib/fastly.rb, line 229
opts must contain service_id, dictionary_id, item_key and item_value params
# File lib/fastly.rb, line 233
opts must contain service_id, version and name params
# File lib/fastly.rb, line 237
opts must contain service_id, version and name params
# File lib/fastly.rb, line 241
opts must contain service_id, version and name params
# File lib/fastly.rb, line 281
opts must contain service_id, version and name params
# File lib/fastly.rb, line 277
opts must contain service_id, version and name params
# File lib/fastly.rb, line 249
opts must contain service_id, version and name params
# File lib/fastly.rb, line 245
opts must contain service_id, version and name params
# File lib/fastly.rb, line 257
opts must contain service_id, version and name params
# File lib/fastly.rb, line 285
opts must contain service_id, version and name params
# File lib/fastly.rb, line 289
opts must contain service_id, version and name params
# File lib/fastly.rb, line 253
opts must contain service_id, version and name params
# File lib/fastly.rb, line 261
opts must contain service_id, version and name params
# File lib/fastly.rb, line 265
opts must contain a service_id param
# File lib/fastly.rb, line 221
Return a Customer
object representing the customer of the current logged in user.
# File lib/fastly.rb, line 78 def current_customer fail AuthRequired unless authed? @current_customer ||= get(Customer) end
Return a User
object representing the current logged in user.
# File lib/fastly.rb, line 84 def current_user @current_user ||= get(User) end
# File lib/fastly/token.rb, line 36 def customer_tokens(opts) hash = client.get("/customer/#{opts[:customer_id]}/tokens") hash.map { |token_hash| Token.new(token_hash, Fastly::Fetcher) } end
You can also call
backend.delete!
# File lib/fastly.rb, line 529
You can also call
cache_setting.delete!
# File lib/fastly.rb, line 589
You can also call
condition.delete!
# File lib/fastly.rb, line 614
You can also call
customer.delete!
# File lib/fastly.rb, line 514
You can also call
dictionary.delete!
# File lib/fastly.rb, line 534
You can also call
dictionary_item.delete!
# File lib/fastly.rb, line 539
You can also call
backend.delete!
# File lib/fastly.rb, line 544
You can also call
domain.delete!
# File lib/fastly.rb, line 549
You can also call
gzip.delete!
# File lib/fastly.rb, line 599
You can also call
header.delete!
# File lib/fastly.rb, line 594
You can also call
healthcheck.delete!
# File lib/fastly.rb, line 554
You can also call
match.delete!(match)
# File lib/fastly.rb, line 559
You can also call
papertrail_logging.delete!
# File lib/fastly.rb, line 569
You can also call
request_setting.delete!
# File lib/fastly.rb, line 604
You can also call
response_object.delete!
# File lib/fastly.rb, line 609
You can also call
s3_logging.delete!
# File lib/fastly.rb, line 564
You can also call
service.delete!
# File lib/fastly.rb, line 519
You can also call
snippet.delete!
# File lib/fastly.rb, line 584
You can also call
syslog.delete!
# File lib/fastly.rb, line 574
You can also call
user.delete!
# File lib/fastly.rb, line 509
You can also call
vcl.delete!
# File lib/fastly.rb, line 579
You can also call
version.delete!
# File lib/fastly.rb, line 524
Whether or not we're fully (username and password) authed Some methods require full username and password rather than just auth token
# File lib/fastly.rb, line 73 def fully_authed? client.fully_authed? end
Get a backend
# File lib/fastly.rb, line 309
Get a Cache Setting
# File lib/fastly.rb, line 369
Get a Condition
# File lib/fastly.rb, line 365
Get a customer
# File lib/fastly.rb, line 297
Get a single dictionary
# File lib/fastly.rb, line 313
Get a single dictionary item
# File lib/fastly.rb, line 317
Get a Director
# File lib/fastly.rb, line 321
Get a Domain
# File lib/fastly.rb, line 325
Get a Gzip
# File lib/fastly.rb, line 373
Get a Header
# File lib/fastly.rb, line 377
Get a Healthcheck
# File lib/fastly.rb, line 329
Return an Invoice
object
If a year and month are passed in returns the invoices for that whole month.
Otherwise it returns the invoices for the current month so far.
# File lib/fastly/invoice.rb, line 92 def get_invoice(year = nil, month = nil) opts = { customer_id: current_customer.id } if year.nil? || month.nil? opts[:mtd] = true else opts[:year] = year opts[:month] = month end get(Invoice, opts) end
Return an Invoice
object for the passed invoice ID
# File lib/fastly/invoice.rb, line 105 def get_invoice_by_id(id) opts = { id: id, customer_id: current_customer.id } get(Invoice, opts) end
Get a Match
# File lib/fastly.rb, line 333
Get a Papertrail logging stream config
# File lib/fastly.rb, line 341
Get a Request Setting
# File lib/fastly.rb, line 381
Get a Response Object
# File lib/fastly.rb, line 385
Get a S3 logging
# File lib/fastly.rb, line 337
Get a Service
# File lib/fastly.rb, line 301
Get the Settings
object for the specified Version
# File lib/fastly/settings.rb, line 61 def get_settings(service, number) hash = client.get(Settings.get_path(service, number)) return nil if hash.nil? hash['settings'] = Hash[['general.default_host', 'general.default_ttl'].collect { |var| [var, hash.delete(var)] }] Settings.new(hash, self) end
Get a Settings
# File lib/fastly.rb, line 361
Get a VCL
snippet
# File lib/fastly.rb, line 353
Get a Syslog
# File lib/fastly.rb, line 345
Get a User
# File lib/fastly.rb, line 293
Get a VCL
# File lib/fastly.rb, line 349
Get a Version
# File lib/fastly.rb, line 305
Get a list of all backends
# File lib/fastly.rb, line 639
Get a list of all cache settings
# File lib/fastly.rb, line 683
Get a list of all conditions
# File lib/fastly.rb, line 679
Get a list of all customers
# File lib/fastly.rb, line 627
Get a list of all dictionaries
# File lib/fastly.rb, line 647
Get a list of all items belonging to a dictionary
# File lib/fastly.rb, line 651
Get a list of all directors
# File lib/fastly.rb, line 643
Get a list of all domains
# File lib/fastly.rb, line 655
Get a list of all gzips
# File lib/fastly.rb, line 691
Get a list of all headers
# File lib/fastly.rb, line 687
Get a list of all healthchecks
# File lib/fastly.rb, line 659
Retun an array of Invoice
objects.
# File lib/fastly/invoice.rb, line 115 def list_invoices opts = { customer_id: current_customer.id } list(Invoice, opts) end
Get a list of all matches
# File lib/fastly.rb, line 663
Get a list of all request_settings
# File lib/fastly.rb, line 695
Get a list of all response_objects
# File lib/fastly.rb, line 699
Get a list of all services
# File lib/fastly.rb, line 635
Get a list of all vcl snippets
# File lib/fastly.rb, line 675
Get a list of all syslogs
# File lib/fastly.rb, line 667
Get a list of all users
# File lib/fastly.rb, line 623
Get a list of all vcls
# File lib/fastly.rb, line 671
Get a list of all versions
# File lib/fastly.rb, line 631
# File lib/fastly/token.rb, line 23 def new_token(opts) if client.fully_authed? opts[:username] = client.user opts[:password] = client.password opts[:include_auth] = false token = create(Token, opts) token.nil? ? nil : token else raise ArgumentError, "Required options missing. Please pass :api_key, :user and :password." end end
Purge the specified path from your cache.
# File lib/fastly.rb, line 89 def purge(url, soft=false) client.purge(url, soft ? { headers: { 'Fastly-Soft-Purge' => "1"} } : {}) end
Fetches the list of codes for regions that are covered by the Fastly
CDN service.
# File lib/fastly.rb, line 151 def regions client.get_stats('/stats/regions') end
Search all the services that the current customer has.
In general you'll want to do
services = fastly.search_services(:name => name)
or
service = fastly.search_services(:name => name, :version => number)
# File lib/fastly/service.rb, line 103 def search_services(opts) hash = client.get("#{Service.post_path}/search", opts) hash.nil? ? nil : Service.new(hash, self) 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 docs.fastly.com/docs/stats for details.
# File lib/fastly.rb, line 109 def stats(opts) if opts[:aggregate] && (opts[:field] || opts[:service]) fail Error, "You can't specify a field or a service for an aggregate request" end url = '/stats' url += '/aggregate' if opts.delete(:aggregate) if service = opts.delete(:service) url += "/service/#{service}" end if field = opts.delete(:field) url += "/field/#{field}" end client.get_stats(url, opts) end
You can also call
backend.save!
# File lib/fastly.rb, line 409
You can also call
cache_setting.save!
# File lib/fastly.rb, line 474
You can also call
condition.save!
# File lib/fastly.rb, line 499
You can also call
customer.save!
# File lib/fastly.rb, line 394
You can also call
dictionary.save!
# File lib/fastly.rb, line 414
You can also call
dictionary_item.save!
# File lib/fastly.rb, line 419
You can also call
director.save!
# File lib/fastly.rb, line 424
You can also call
domain.save!
# File lib/fastly.rb, line 429
You can also call
gzip.save!
# File lib/fastly.rb, line 484
You can also call
header.save!
# File lib/fastly.rb, line 479
You can also call
healthcheck.save!
# File lib/fastly.rb, line 434
You can also call
match.save!
# File lib/fastly.rb, line 439
You can also call
papertrail_logging.save!
# File lib/fastly.rb, line 454
You can also call
request_setting.save!
# File lib/fastly.rb, line 489
You can also call
response_object.save!
# File lib/fastly.rb, line 494
You can also call
s3_logging.save!
# File lib/fastly.rb, line 449
You can also call
service.save!
# File lib/fastly.rb, line 399
You can also call
settings.save!
# File lib/fastly.rb, line 444
You can also call
snippet.save!
# File lib/fastly.rb, line 469
You can also call
syslog.save!
# File lib/fastly.rb, line 459
You can also call
user.save!
# File lib/fastly.rb, line 389
You can also call
vcl.save!
# File lib/fastly.rb, line 464
You can also call
version.save!
# File lib/fastly.rb, line 404
Returns usage information aggregated across all Fastly
services and grouped by region.
If the :by_month flag is passed then returns total usage information aggregated by month as well as grouped by service & region.
If the :by_service flag is passed then returns 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 docs.fastly.com/docs/stats for details.
# File lib/fastly.rb, line 143 def usage(opts) url = '/stats/usage' url += '_by_month' if opts.delete(:by_month) url += '_by_service' if opts.delete(:by_service) client.get_stats(url, opts) end