Class: Cloudability::Budgets

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Budgets

Returns a new instance of Budgets.

Raises:

  • (ArgumentError)


9
10
11
12
# File 'lib/cloudability/budgets.rb', line 9

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

Instance Attribute Details

#auth_tokenObject

Returns the value of attribute auth_token.



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

def auth_token
  @auth_token
end

Instance Method Details

#find_allObject

Return all the budgets for the current account, and return as mash’s.



15
16
17
# File 'lib/cloudability/budgets.rb', line 15

def find_all
  convert_to_mashes(get_budgets)
end

#find_by_id(id) ⇒ Object

Find a particular budget, based on its id, and return a mash.



20
21
22
# File 'lib/cloudability/budgets.rb', line 20

def find_by_id(id)
  find_all.select {|b| b.id == id}.first
end

#find_by_key(options = {}) ⇒ Object

Find a particular budget, based on a key, and return a mash.



34
35
36
37
38
39
40
41
42
43
# File 'lib/cloudability/budgets.rb', line 34

def find_by_key(options={})
  case options[:key]
  when :id
    budget = find_by_id(options[:value])
  when :subject
    budget = find_by_subject(options[:value])
  else
    raise ArgumentError, "You must provide a valid key."
  end
end

#find_by_subject(subject) ⇒ Object

Find a particular budget, based on its subject, and return a mash.



25
26
27
28
29
30
31
# File 'lib/cloudability/budgets.rb', line 25

def find_by_subject(subject)
  unless subject.length == 14
    raise ArgumentError, "You must provide a valid subject such as 1234-5678-9101."
  end
  
  find_all.select {|b| b.subject == subject}.first
end