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
|
||||
|
||||
require "faraday/multipart"
|
||||
|
||||
module Fiken
|
||||
module Resources
|
||||
module Concerns
|
||||
# /<parent>/attachments — list (where supported) and multipart upload.
|
||||
class Attachments < Resource::Base
|
||||
def initialize(client, company_slug, parent_path, listable: true)
|
||||
super(client, company_slug)
|
||||
@parent_path = parent_path
|
||||
@listable = listable
|
||||
end
|
||||
|
||||
def base_path
|
||||
"#{@parent_path}/attachments"
|
||||
end
|
||||
|
||||
def list
|
||||
raise Error, "this resource does not support listing attachments" unless @listable
|
||||
|
||||
get_collection(base_path, {})
|
||||
end
|
||||
|
||||
# Upload a file. Provide either path: (a filename on disk) or io: + filename:.
|
||||
# Extra Fiken fields (e.g. comment:, attachToPayment:) are passed as form fields.
|
||||
def add(path: nil, io: nil, filename: nil, content_type: "application/octet-stream", **fields)
|
||||
parts = { "file" => build_file_part(path, io, filename, content_type) }
|
||||
fields.each { |key, value| parts[key.to_s] = value.to_s unless value.nil? }
|
||||
build_created(connection.post_multipart(base_path, parts))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user