Sha256: 397accb653ddc9a19b6943692104e630dec986f4d1c13506843b7d1c4ad53fb1
Contents?: true
Size: 1.57 KB
Versions: 6
Compression:
Stored size: 1.57 KB
Contents
# frozen_string_literal: true require 'forwardable' module ChartMogul class CustomerInvoices < APIResource extend Forwardable include Enumerable set_resource_name 'Invoices' set_resource_path '/v1/import/customers/:customer_uuid/invoices' writeable_attr :invoices, default: [] writeable_attr :customer_uuid include API::Actions::All include API::Actions::Create include Concerns::Pageable2 include Concerns::PageableWithCursor def serialize_invoices map(&:serialize_for_write) end def self.all(customer_uuid, options = {}) super(options.merge(customer_uuid: customer_uuid)) end def next(options = {}) CustomerInvoices.all(customer_uuid, options.merge(cursor: cursor)) end def self.destroy_all!(data_source_uuid, customer_uuid) path = ChartMogul::ResourcePath.new('v1/data_sources/:data_source_uuid/customers/:customer_uuid/invoices') handling_errors do connection.delete(path.apply(data_source_uuid: data_source_uuid, customer_uuid: customer_uuid)) end true end def_delegators :invoices, :each, :[], :<<, :size, :length, :empty?, :first private # TODO: replace with Entries concern? def set_invoices(invoices_attributes) @invoices = invoices_attributes.map.with_index do |invoice_attributes, index| existing_invoice = invoices[index] if existing_invoice existing_invoice.assign_all_attributes(invoice_attributes) else Invoice.new_from_json(invoice_attributes) end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems