class Fastly::Version

An iteration of your configuration

def self.create_new(fetcher, opts)

Create an entirely new version, not cloned from the previous one.
def self.create_new(fetcher, opts)
  hash = fetcher.client.post(Version.post_path(opts))
  return nil if hash.nil?
  Version.new(hash, fetcher)
end

def self.delete_path(obj)

def self.delete_path(obj)
  put_path(obj)
end

def self.get_path(service, number)

def self.get_path(service, number)
  "/service/#{service}/version/#{number}"
end

def self.post_path(opts = {})

def self.post_path(opts = {})
  "/service/#{opts[:service_id]}/version"
end

def self.put_path(obj)

def self.put_path(obj)
  get_path(obj.service_id, obj.number)
end

def activate!

Activate this version
def activate!
  hash = fetcher.client.put("#{Version.put_path(self)}/activate")
  !hash.nil?
end

def active?

Is version active?
def active?
  true == @active
end

def clone

Clone this Version
def clone
  hash = fetcher.client.put("#{Version.put_path(self)}/clone")
  return nil if hash.nil?
  Version.new(hash, fetcher)
end

def deactivate!

Deactivate this version
def deactivate!
  hash = fetcher.client.put("#{Version.put_path(self)}/deactivate")
  !hash.nil?
end

def delete_vcl(name)

Delete a VCL file for this Version
def delete_vcl(name)
  hash = fetcher.client.delete("#{Version.put_path(self)}/vcl/#{name}")
  hash.nil? ? nil : hash
end

def dictionaries

def dictionaries
  fetcher.list_dictionaries(:service_id => service_id, :version => number)
end

def generated_vcl(opts = {})

in the opts
:include_content => true
Won't return the content of the VCL unless you pass in

Get the generated VCL object for this Version (which must have been activated first)
def generated_vcl(opts = {})
  hash = fetcher.client.get("#{Version.put_path(self)}/generated_vcl", opts)
  opts = {
    'content'    => hash['vcl'] || hash['content'],
    'name'       => hash['md5'],
    'version'    => hash['version'],
    'service_id' => hash['service']
  }
  VCL.new(opts, fetcher)
end

def locked?

Is this Version locked
def locked?
  true == @locked
end

def service

Get the Service object this Version belongs to
def service
  fetcher.get(Service, service_id)
end

def settings

Get the Settings object for this Version
def settings
  fetcher.get_settings(service_id, number)
end

def upload_main_vcl(name, contents)

Upload a VCL file for this Version and set as the main VCL
def upload_main_vcl(name, contents)
  upload_vcl(name, contents).set_main!
end

def upload_vcl(name, content)

Upload a VCL file for this Version
def upload_vcl(name, content)
  hash = fetcher.client.post("#{Version.put_path(self)}/vcl", name: name, content: content)
  return nil if hash.nil?
  VCL.new(hash, fetcher)
end

def validate

Validate this Version
def validate
  hash = fetcher.client.get("#{Version.put_path(self)}/validate")
  valid = ("ok" == hash["status"])
  message = hash['msg']
  [valid, message]
end

def vcl(name, opts = {})

in the opts
:include_content => true
Won't return the content of the VCL unless you pass in

Get the named VCL for this version
def vcl(name, opts = {})
  fetcher.get_vcl(service_id, number, name, opts)
end