Add feature to resend an existing envelope
This commit is contained in:
parent
f2175f3184
commit
4a0035e43b
@ -35,8 +35,10 @@ module Docurest
|
||||
|
||||
private
|
||||
|
||||
def multipart_query(klass, url, use_base_url: true, parse_json: true, files: {}, **body)
|
||||
def multipart_query(klass, url, use_base_url: true, parse_json: true, request_query: {}, files: {}, **body)
|
||||
uri = build_uri(url, use_base_url)
|
||||
uri.query = URI.encode_www_form(request_query)
|
||||
|
||||
if files.empty?
|
||||
request = klass.new uri, {'Content-Type' => 'application/json'}
|
||||
request.body = JSON.generate(body)
|
||||
|
@ -35,8 +35,8 @@ module Docurest
|
||||
field :email_settings, :emailSettings, ->(value) { Docurest::Envelope::EmailSettings.new value }
|
||||
|
||||
association(:recipients, :envelope_id) { Docurest::Envelope::Recipient.list(guid) }
|
||||
def save_recipients
|
||||
Docurest::Envelope::Recipient.save recipients
|
||||
def save_recipients(resend: false)
|
||||
Docurest::Envelope::Recipient.save recipients, resend: resend
|
||||
end
|
||||
|
||||
association(:documents, :envelope_id) { Docurest::Envelope::Document.list(guid) }
|
||||
@ -58,13 +58,28 @@ module Docurest
|
||||
Docurest::Envelope::Document.new(id: document_id, envelope_id: guid).download(file)
|
||||
end
|
||||
|
||||
def resend
|
||||
return unless persisted? && %w{sent delivered}.include?(status)
|
||||
Docurest.client.put "/envelopes/#{guid}", {request_query: {resend_envelope: true}}
|
||||
end
|
||||
|
||||
def fire
|
||||
return unless status == 'created'
|
||||
|
||||
if persisted?
|
||||
Docurest.client.put "/envelopes/#{guid}", {status: :sent}
|
||||
else
|
||||
self.status = :sent
|
||||
end
|
||||
end
|
||||
|
||||
def void(reason = 'No reason provided.')
|
||||
Docurest.client.put "/envelopes/#{guid}", {status: :voided, voidedReason: reason}
|
||||
end
|
||||
|
||||
def save
|
||||
def save(resend: false)
|
||||
result = if persisted?
|
||||
Docurest.client.put "/envelopes/#{guid}", to_h
|
||||
Docurest.client.put "/envelopes/#{guid}", to_h.merge(request_query: {resend_envelope: resend})
|
||||
else
|
||||
Docurest.client.post "/envelopes", to_h
|
||||
end
|
||||
|
@ -12,10 +12,11 @@ module Docurest
|
||||
end
|
||||
end
|
||||
|
||||
def self.save(recipients)
|
||||
def self.save(recipients, resend: false)
|
||||
Array(recipients).group_by(&:envelope_id).each do |envelope_id, array|
|
||||
next unless envelope_id
|
||||
Docurest.client.put "/envelopes/#{envelope_id}/recipients", Docurest::Base.hash_by_type(array)
|
||||
Docurest.client.put "/envelopes/#{envelope_id}/recipients",
|
||||
Docurest::Base.hash_by_type(array).merge(request_query: {resend_envelope: resend})
|
||||
end
|
||||
end
|
||||
|
||||
@ -46,11 +47,12 @@ module Docurest
|
||||
name: name,
|
||||
email: email,
|
||||
customFields: customFields,
|
||||
emailNotification: email_notification.to_h,
|
||||
routingOrder: routingOrder,
|
||||
note: note,
|
||||
tabs: Docurest::Base.hash_by_type(tabs),
|
||||
}
|
||||
}.tap do |hash|
|
||||
hash[:emailNotification] = email_notification.to_h if email_notification
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user