Class: Cloudability::Billing

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/cloudability/billing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Billing

Returns a new instance of Billing.

Raises:

  • (ArgumentError)


9
10
11
12
13
14
# File 'lib/cloudability/billing.rb', line 9

def initialize(options={})
  raise ArgumentError, "You must provide an auth token" if options[:auth_token].nil?

  @auth_token = options[:auth_token]
  @params=[]
end

Instance Attribute Details

#auth_tokenObject

Returns the value of attribute auth_token.



7
8
9
# File 'lib/cloudability/billing.rb', line 7

def auth_token
  @auth_token
end

Instance Method Details

#filter_by_period(period) ⇒ Object

Find a particular period, based on its month. Period must be in YY-MM-01 format with the date always 01.



42
43
44
45
46
47
48
49
50
51
# File 'lib/cloudability/billing.rb', line 42

def filter_by_period(period)
  unless period =~ /^[0-9]{2}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/
    raise ArgumentError, "You must provide a valid date in the form of 'YY-MM-DD'."
  end

  @params << "&period=#{period}"
  single_billing = get_url(@params).first

  Hashie::Mash.new(single_billing)
end

#report_by(dimension) ⇒ Array

Define which dimension the billing report will return.

Parameters:

  • dimension (Symbol)

    to report on.

Returns:

  • (Array)

    array of Hashie::Mashes



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cloudability/billing.rb', line 20

def report_by(dimension)
  case dimension
  when :account
    @params << "&by=account"
  when :credential
    @params << "&by=credential"
  when :period
    @params << "&by=period"
  when :service
    @params << "&by=service"
  when :vendor
    @params << "&by=vendor"
  else
    raise ArgumentError, "You must provide a valid dimension to report on."
  end

  billings = get_url(@params)
  billings.map { |b| Hashie::Mash.new(b) }
end