42 lines
1.1 KiB
Ruby
42 lines
1.1 KiB
Ruby
|
class Documenso
|
||
|
include HTTParty
|
||
|
# debug_output $stdout
|
||
|
# http_proxy 'localhost', 8080
|
||
|
|
||
|
def initialize(url, token)
|
||
|
self.class.base_uri URI.join(url, 'api/v1/').to_s
|
||
|
self.class.headers 'Authorization' => token,
|
||
|
'Content-Type' => 'application/json'
|
||
|
end
|
||
|
|
||
|
def self.perform_request(method, path, json, &block)
|
||
|
response = super method, path, body: json.to_json, &block
|
||
|
return response.parsed_response if response.success?
|
||
|
raise Exception, response
|
||
|
end
|
||
|
|
||
|
def template(id)
|
||
|
self.class.get "/templates/#{id}"
|
||
|
end
|
||
|
|
||
|
def generate(id, recipient, **kwargs)
|
||
|
template = self.template id
|
||
|
recipients = template.fetch 'Recipient'
|
||
|
recipient[:id] = recipients.first['id']
|
||
|
self.class.post "/templates/#{id}/generate-document",
|
||
|
recipients: [recipient], **kwargs
|
||
|
end
|
||
|
|
||
|
def document(id)
|
||
|
self.class.get "/documents/#{id}"
|
||
|
end
|
||
|
|
||
|
def send(id, **kwargs)
|
||
|
self.class.post "/documents/#{id}/send", **kwargs
|
||
|
end
|
||
|
|
||
|
def resend(id, recipients, **kwargs)
|
||
|
self.class.post "/documents/#{id}/resend", recipients: recipients, **kwargs
|
||
|
end
|
||
|
end
|