Class: CFO::Account

Inherits:
Object
  • Object
show all
Defined in:
lib/cfo/resources/account.rb

Overview

Represents an account for a specific service with a cloud provider.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Account

Creates a object representing a REST Resource for an account.

Parameters:

  • attributes (Hash) (defaults to: {})
    • :name, :provider, :service, or :billing_codes



19
20
21
# File 'lib/cfo/resources/account.rb', line 19

def initialize(attributes = {})
  attributes.each {|k,v| self.send("#{k}=",v) if self.respond_to?("#{k}=")}
end

Instance Attribute Details

#billing_codesObject

An Array of String pairs representing all the BillingCodes associated with all this Acccount’s BillingRecords.



15
16
17
# File 'lib/cfo/resources/account.rb', line 15

def billing_codes
  @billing_codes
end

#nameObject

A human-readable ID for the account - best to make this URL-safe.



5
6
7
# File 'lib/cfo/resources/account.rb', line 5

def name
  @name
end

#providerObject

The (Fog) name of the cloud computing service provider.



8
9
10
# File 'lib/cfo/resources/account.rb', line 8

def provider
  @provider
end

#serviceObject

The (Fog) name of the cloud computing service.



11
12
13
# File 'lib/cfo/resources/account.rb', line 11

def service
  @service
end

Instance Method Details

#report_uriString

Returns a URI path to this object’s cost report.

Returns:

  • (String)

    a URI path to this object’s cost report.



45
46
47
# File 'lib/cfo/resources/account.rb', line 45

def report_uri
  "#{CFO.root}/report/for_account/#{URI.escape(@name)}"
end

#to_hash(verbose = true) ⇒ Hash

Returns a RESTful Hash representation of this object.

Parameters:

  • verbose (Booolean) (defaults to: true)

    whether to include biling codes and resources.

Returns:

  • (Hash)

    a RESTful Hash representation of this object.



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cfo/resources/account.rb', line 25

def to_hash(verbose = true)
  extra_info = {
    'resources' => CloudResource.hash_list(:account => @name),
    'billing_codes' => @billing_codes,
  }
  {
    'id'            => @name,
    'service'       => @service,
    'provider'      => @provider,
    'url'           => uri,
    'report_url'    => report_uri,
  }.merge(verbose ? extra_info : {})
end

#to_jsonString

Returns a RESTful JSON representation of this object.

Returns:

  • (String)

    a RESTful JSON representation of this object.



50
# File 'lib/cfo/resources/account.rb', line 50

def to_json ; to_hash.to_json end

#uriString

Returns a URI path to this object’s JSON representation.

Returns:

  • (String)

    a URI path to this object’s JSON representation



40
41
42
# File 'lib/cfo/resources/account.rb', line 40

def uri
  "#{CFO.root}/accounts/#{URI.escape(@name)}"
end