Module: Invoiced::Operations::Update

Included in:
Customer, Invoice, LineItem, Subscription, Transaction
Defined in:
lib/invoiced/operations/update.rb

Instance Method Summary collapse

Instance Method Details

#save(params = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/invoiced/operations/update.rb', line 4

def save(params = {})
    update = {}

    @unsaved.each do |k|
    	update[k] = @values[k]
    end

    update.merge(params)

				# perform the update if there are any changes
    if update.length > 0
		response = @client.request(:patch, self.endpoint(), update)

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

		return response[:code] == 200
    end

    false
end