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, #save!

Constructor Details

This class inherits a constructor from Fastly::Base

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



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

def comment
  @comment
end

#customer_idObject

Returns the value of attribute customer_id.



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

def customer_id
  @customer_id
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#customerObject

Get the Customer object for this Service



92
93
94
# File 'lib/fastly/service.rb', line 92

def customer
  fetcher.get(Fastly::Customer, customer_id)
end

#details(opts = {}) ⇒ Object

A deep hash of nested details



87
88
89
# File 'lib/fastly/service.rb', line 87

def details(opts={})
  client.get(get_path(self.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.



51
52
53
54
55
56
57
58
# File 'lib/fastly/service.rb', line 51

def invoice(year=nil, month=nil)
  opts = { :service_id => self.id }
  unless year.nil? || month.nil?
    opts[:year]  = year
    opts[:month] = month
  end
  fetcher.get(Fastly::Invoice, opts)
end

#purge_allObject

Purge all assets from this service.



61
62
63
# File 'lib/fastly/service.rb', line 61

def purge_all
  res = client.put(get_path(self.id)+"/purge_all")
end

#purge_by_key(key) ⇒ Object

Purge anything with the specific key from the given service.



67
68
69
# File 'lib/fastly/service.rb', line 67

def purge_by_key(key)
   res = client.put(get_path(self.id)+"/purge/#{key}")
end

#stats(type = :all, opts = {}) ⇒ Object

Get a hash of stats from different data centers.

Type can be one of

  • minutely

  • hourly

  • daily

  • all



40
41
42
43
44
# File 'lib/fastly/service.rb', line 40

def stats(type=:all, opts={})
  raise Fastly::Error "Unknown stats type #{type}" unless [:minutely,:hourly,:daily,:all].include?(type.to_sym)
  hash = fetcher.client.get(Fastly::Service.get_path(self.id)+"/stats/#{type}", opts)
  return hash
end

#version(number = -1)) ⇒ Object

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



82
83
84
# File 'lib/fastly/service.rb', line 82

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

#versionsObject

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



77
78
79
# File 'lib/fastly/service.rb', line 77

def versions
  @versions.map { |v| Fastly::Version.new(v, fetcher) }.sort { |a,b| a.number.to_i <=> b.number.to_i }
end

#versions=(versions) ⇒ Object

Set all the versions that this service has had.



72
73
74
# File 'lib/fastly/service.rb', line 72

def versions=(versions)
  @versions = versions
end