Class: Cloudability::Billing
- Inherits:
-
Object
- Object
- Cloudability::Billing
- Includes:
- HTTParty
- Defined in:
- lib/cloudability/billing.rb
Instance Attribute Summary collapse
-
#auth_token ⇒ Object
Returns the value of attribute auth_token.
Instance Method Summary collapse
-
#filter_by_period(period) ⇒ Object
Find a particular period, based on its month.
-
#initialize(options = {}) ⇒ Billing
constructor
A new instance of Billing.
-
#report_by(dimension) ⇒ Array
Define which dimension the billing report will return.
Constructor Details
#initialize(options = {}) ⇒ Billing
Returns a new instance of Billing.
9 10 11 12 13 14 |
# File 'lib/cloudability/billing.rb', line 9 def initialize(={}) raise ArgumentError, "You must provide an auth token" if [:auth_token].nil? @auth_token = [:auth_token] @params=[] end |
Instance Attribute Details
#auth_token ⇒ Object
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.
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 |