Class: Invoiced::Invoice

Inherits:
Object
  • Object
show all
Includes:
Operations::Create, Operations::Delete, Operations::List, Operations::Update
Defined in:
lib/invoiced/invoice.rb

Constant Summary collapse

OBJECT_NAME =
'invoice'

Instance Attribute Summary

Attributes inherited from Object

#client

Instance Method Summary collapse

Methods included from Operations::Delete

#delete

Methods included from Operations::Update

#save

Methods included from Operations::Create

#create

Methods included from Operations::List

#list

Methods inherited from Object

#[], #[]=, #add_accessors, #build_endpoint, #each, #endpoint, #endpoint_base, #initialize, #inspect, #keys, #metaclass, #method_missing, #refresh_from, #remove_accessors, #retrieve, #set_endpoint_base, #to_hash, #to_json, #to_s, #values

Constructor Details

This class inherits a constructor from Invoiced::Object

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Invoiced::Object

Instance Method Details

#attachments(params = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/invoiced/invoice.rb', line 44

def attachments(params={})
    response = @client.request(:get, "#{self.endpoint()}/attachments", params)

    # ensure each attachment has an ID
    body = response[:body]
    body.each do |attachment|
        if !attachment.has_key?(:id)
            attachment[:id] = attachment[:file][:id]
        end
end

    # build objects
    attachment = Attachment.new(@client)
    attachments = Util.build_objects(attachment, body)

    # store the metadata from the list operation
     = Invoiced::List.new(response[:headers][:link], response[:headers][:x_total_count])

    return attachments, 
end

#notesObject



70
71
72
73
# File 'lib/invoiced/invoice.rb', line 70

def notes()
    note = Note.new(@client)
    note.set_endpoint_base(self.endpoint())
end

#pay(opts = {}) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/invoiced/invoice.rb', line 35

def pay(opts={})
    response = @client.request(:post, "#{self.endpoint()}/pay", {}, opts)

    # update the local values with the response
    refresh_from(response[:body].dup.merge({:id => self.id}))

    return response[:code] == 200
end

#payment_planObject



65
66
67
68
# File 'lib/invoiced/invoice.rb', line 65

def payment_plan()
    paymentPlan = PaymentPlan.new(@client)
    paymentPlan.set_endpoint_base(self.endpoint())
end

#send(params = {}, opts = {}) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/invoiced/invoice.rb', line 10

def send(params={}, opts={})
    response = @client.request(:post, "#{self.endpoint()}/emails", params, opts)

    # build email objects
    email = Email.new(@client)
    Util.build_objects(email, response[:body])
end

#send_letter(params = {}, opts = {}) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/invoiced/invoice.rb', line 26

def send_letter(params={}, opts={})
    response = @client.request(:post, "#{self.endpoint()}/letters", params, opts)

    # build letter objects

    letter = Letter.new(@client)
    Util.build_objects(letter, response[:body])
end

#send_sms(params = {}, opts = {}) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/invoiced/invoice.rb', line 18

def send_sms(params={}, opts={})
    response = @client.request(:post, "#{self.endpoint()}/text_messages", params, opts)

    # build text message objects
    text_message = TextMessage.new(@client)
    Util.build_objects(text_message, response[:body])
end

#voidObject



75
76
77
78
79
80
81
# File 'lib/invoiced/invoice.rb', line 75

def void()
    response = @client.request(:post, "#{self.endpoint()}/void", {})

    refresh_from(response[:body].dup.merge({:id => self.id}))

    return response[:code] == 200
end