Class: TortoiseLabs::Invoice

Inherits:
Object
  • Object
show all
Defined in:
lib/tortoiselabs/billing.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ihash) ⇒ Invoice

Returns a new instance of Invoice.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/tortoiselabs/billing.rb', line 5

def initialize(ihash)
  @creation_ts, @total = ihash["creation_ts"], ihash["total"]
  @payment_ts, @user = ihash["payment_ts"], ihash["user"]
  @id = ihash["invoice"]
  @items = Array.new
  
  ihash["items"].each do |itemhash|
    obj = Item.new(itemhash)
    @items << obj
  end
end

Instance Attribute Details

#creation_tsObject (readonly)

Returns the value of attribute creation_ts.



3
4
5
# File 'lib/tortoiselabs/billing.rb', line 3

def creation_ts
  @creation_ts
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/tortoiselabs/billing.rb', line 3

def id
  @id
end

#itemsObject (readonly)

Returns the value of attribute items.



3
4
5
# File 'lib/tortoiselabs/billing.rb', line 3

def items
  @items
end

#payment_tsObject (readonly)

Returns the value of attribute payment_ts.



3
4
5
# File 'lib/tortoiselabs/billing.rb', line 3

def payment_ts
  @payment_ts
end

#totalObject (readonly)

Returns the value of attribute total.



3
4
5
# File 'lib/tortoiselabs/billing.rb', line 3

def total
  @total
end

#userObject (readonly)

Returns the value of attribute user.



3
4
5
# File 'lib/tortoiselabs/billing.rb', line 3

def user
  @user
end

Class Method Details

.add_credit(amount) ⇒ Object



35
36
37
38
39
# File 'lib/tortoiselabs/billing.rb', line 35

def self.add_credit(amount)
  response = TortoiseLabs::Client.post("/invoice/svccredit",
                                      {:creditamt => amount})
  return response.request.last_uri.to_s
end

.get(id) ⇒ Object



41
42
43
44
# File 'lib/tortoiselabs/billing.rb', line 41

def self.get(id)
  result = TortoiseLabs::Client.get("/invoice/#{id}")
  self.new(JSON.parse(result)["invoice"])
end

.listObject

Class Methods



25
26
27
28
29
30
31
32
33
# File 'lib/tortoiselabs/billing.rb', line 25

def self.list
  result = TortoiseLabs::Client.get("/invoice/list")
  invoices = Array.new
  JSON.parse(result)["invoices"].each do |invoice|
    obj = self.new(invoice)
    invoices << obj
  end
  invoices
end

Instance Method Details

#to_sObject

Instance methods



19
20
21
# File 'lib/tortoiselabs/billing.rb', line 19

def to_s
  "Invoice ##{@id}"
end