Add resource framework: Base, CRUD mixins, and shared drafts/attachments/payments concerns
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Fiken
|
||||
module Resources
|
||||
module Concerns
|
||||
# /<parent>/drafts — the draft lifecycle shared by invoices, credit notes,
|
||||
# offers, order confirmations, sales and purchases.
|
||||
class Drafts < Resource::Base
|
||||
include Resource::Listable
|
||||
include Resource::Findable
|
||||
include Resource::Creatable
|
||||
include Resource::Updatable # drafts update via PUT
|
||||
include Resource::Deletable
|
||||
|
||||
def initialize(client, company_slug, parent_path, create_action)
|
||||
super(client, company_slug)
|
||||
@parent_path = parent_path
|
||||
@create_action = create_action
|
||||
end
|
||||
|
||||
def base_path
|
||||
"#{@parent_path}/drafts"
|
||||
end
|
||||
|
||||
def attachments(draft_id)
|
||||
Attachments.new(client, company_slug, "#{base_path}/#{draft_id}")
|
||||
end
|
||||
|
||||
# Finalize a draft into its document (e.g. createInvoice, createSale).
|
||||
def create_document(draft_id, attributes = nil)
|
||||
post_create("#{base_path}/#{draft_id}/#{@create_action}", attributes)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user