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