class Fastly::Service

Represents something you want to serve - this can be, for example, a whole web site, a Wordpress site, or just your image servers

Attributes

comment[RW]

a free form comment field

customer_id[RW]

The id of the customer this belongs to

id[RW]

The id of the service

name[RW]

The name of this service

versions[W]

Public Instance Methods

customer() click to toggle source

Get the Customer object for this Service

# File lib/fastly/service.rb, line 89
def customer
  fetcher.get(Customer, customer_id)
end
details(opts = {}) click to toggle source

A deep hash of nested details

# File lib/fastly/service.rb, line 84
def details(opts = {})
  fetcher.client.get("#{Service.get_path(id)}/details", opts)
end
invoice(year = nil, month = nil) click to toggle source

Return a Invoice object representing the invoice for this service

If a year and month are passed in returns the invoice for that whole month.

Otherwise it returns the invoice for the current month so far.

# File lib/fastly/service.rb, line 47
def invoice(year = nil, month = nil)
  opts = { service_id: id }

  unless year.nil? || month.nil?
    opts[:year]  = year
    opts[:month] = month
  end

  fetcher.get(Invoice, opts)
end
purge_all() click to toggle source

Purge all assets from this service.

See README.md for examples of purging

# File lib/fastly/service.rb, line 61
def purge_all
  fetcher.client.post("#{Service.get_path(id)}/purge_all")
end
purge_by_key(key, soft=false) click to toggle source

Purge anything with the specific key from the given service.

See README.md for examples of purging

# File lib/fastly/service.rb, line 68
def purge_by_key(key, soft=false)
  require_api_key!
  fetcher.client.post("#{Service.get_path(id)}/purge/#{key}", soft ? { headers: { 'Fastly-Soft-Purge' => "1"} } : {})
end
stats(_type = :all, opts = {}) click to toggle source

Get a hash of stats from different data centers.

Type is always :all (argument is ignored)

# File lib/fastly/service.rb, line 38
def stats(_type = :all, opts = {})
  fetcher.client.get("#{Service.get_path(id)}/stats/summary", opts)
end
version(number = -1) click to toggle source

Get an individual Version object. By default returns the latest version

# File lib/fastly/service.rb, line 79
def version(number = -1)
  versions[number]
end
versions() click to toggle source

Get a sorted array of all the versions that this service has had.

# File lib/fastly/service.rb, line 74
def versions
  @versions.map { |v| Version.new(v, fetcher) }.sort { |a, b| a.number.to_i <=> b.number.to_i }
end