Class: Fastly::Service

Inherits:
Base
  • Object
show all
Defined in:
lib/fastly/service.rb

Overview

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

Instance Attribute Summary collapse

Attributes inherited from Base

#fetcher

Instance Method Summary collapse

Methods inherited from Base

#as_hash, #delete!, delete_path, get_path, #initialize, list_path, path, post_path, put_path, #require_api_key!, #save!

Constructor Details

This class inherits a constructor from Fastly::Base

Instance Attribute Details

#commentObject

Returns the value of attribute comment


5
6
7
# File 'lib/fastly/service.rb', line 5

def comment
  @comment
end

#customer_idObject

Returns the value of attribute customer_id


5
6
7
# File 'lib/fastly/service.rb', line 5

def customer_id
  @customer_id
end

#idObject

Returns the value of attribute id


5
6
7
# File 'lib/fastly/service.rb', line 5

def id
  @id
end

#nameObject

Returns the value of attribute name


5
6
7
# File 'lib/fastly/service.rb', line 5

def name
  @name
end

#versionsObject

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


74
75
76
# 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

Instance Method Details

#customerObject

Get the Customer object for this Service


89
90
91
# File 'lib/fastly/service.rb', line 89

def customer
  fetcher.get(Customer, customer_id)
end

#details(opts = {}) ⇒ Object

A deep hash of nested details


84
85
86
# 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) ⇒ Object

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.


47
48
49
50
51
52
53
54
55
56
# 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_allObject

Purge all assets from this service.

See README.md for examples of purging


61
62
63
# 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) ⇒ Object

Purge anything with the specific key from the given service.

See README.md for examples of purging


68
69
70
71
# 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 = {}) ⇒ Object

Get a hash of stats from different data centers.

Type is always :all (argument is ignored)


38
39
40
# 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)) ⇒ Object

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


79
80
81
# File 'lib/fastly/service.rb', line 79

def version(number = -1)
  versions[number]
end