Class: Invoiced::CreditNote

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

Constant Summary collapse

OBJECT_NAME =
'credit_note'

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



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/invoiced/credit_note.rb', line 18

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

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



10
11
12
13
14
15
16
# File 'lib/invoiced/credit_note.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

#voidObject



39
40
41
42
43
44
45
# File 'lib/invoiced/credit_note.rb', line 39

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

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

    return response[:code] == 200
end