documenso_rails 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/documenso_rails/client.rb +19 -7
- data/lib/documenso_rails/model.rb +17 -15
- data/lib/documenso_rails/send_result.rb +15 -0
- data/lib/documenso_rails/version.rb +1 -1
- data/lib/documenso_rails.rb +1 -0
- data/lib/generators/documenso_rails/templates/migration.rb.tt +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3bbe705e6a7915e8f743db3a147e7236f784fa1e8a8d73e7ef9421ac25c5c7a5
|
|
4
|
+
data.tar.gz: 15c1f5092f81c0c72fdc0a9e06dd1d667c7545855fc26b70d22f1d1098008aaa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 187e22505ec52b254e8e6f217022bb17ad5833f811d17212a6ed3ccabd03076dc43636ba6aebf8332d1795c694b0838bb60fcaa23e5ed6f280712f8f6edc17cc
|
|
7
|
+
data.tar.gz: 43ee1d411050cb99c987d11ce48653a474438b727a249132b141f8c7121291b72584a21f3cfd71c612bb321077b1fe64cc80a98f9c1a35c869960b288d8b7f21
|
|
@@ -18,9 +18,8 @@ module DocumensoRails
|
|
|
18
18
|
redirect_url: redirect_url
|
|
19
19
|
)
|
|
20
20
|
envelope_id = envelope.fetch("id")
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
envelope_id
|
|
21
|
+
distribute_result = distribute_envelope(envelope_id)
|
|
22
|
+
build_send_result(envelope_id, distribute_result)
|
|
24
23
|
end
|
|
25
24
|
|
|
26
25
|
def create_and_send_from_template(template_id:, signers:, prefill_fields: {}, title: nil, redirect_url: nil)
|
|
@@ -32,9 +31,8 @@ module DocumensoRails
|
|
|
32
31
|
redirect_url: redirect_url
|
|
33
32
|
)
|
|
34
33
|
envelope_id = envelope.fetch("id")
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
envelope_id
|
|
34
|
+
distribute_result = distribute_envelope(envelope_id)
|
|
35
|
+
build_send_result(envelope_id, distribute_result)
|
|
38
36
|
end
|
|
39
37
|
|
|
40
38
|
def create_envelope(file_io:, filename:, title:, signers:, fields:, redirect_url: nil)
|
|
@@ -115,7 +113,8 @@ module DocumensoRails
|
|
|
115
113
|
request["Content-Type"] = "application/json"
|
|
116
114
|
request.body = { envelopeId: envelope_id }.to_json
|
|
117
115
|
|
|
118
|
-
execute(uri, request)
|
|
116
|
+
body = execute(uri, request).body
|
|
117
|
+
body.present? ? JSON.parse(body) : {}
|
|
119
118
|
end
|
|
120
119
|
|
|
121
120
|
def download_signed_pdf(envelope_id)
|
|
@@ -128,6 +127,19 @@ module DocumensoRails
|
|
|
128
127
|
|
|
129
128
|
private
|
|
130
129
|
|
|
130
|
+
def build_send_result(envelope_id, distribute_payload)
|
|
131
|
+
raw_recipients = Array(distribute_payload["recipients"] || distribute_payload[:recipients])
|
|
132
|
+
recipients = raw_recipients.map do |recipient|
|
|
133
|
+
{
|
|
134
|
+
email: recipient["email"] || recipient[:email],
|
|
135
|
+
name: recipient["name"] || recipient[:name],
|
|
136
|
+
signing_url: recipient["signingUrl"] || recipient[:signingUrl] || recipient["signing_url"]
|
|
137
|
+
}
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
SendResult.new(envelope_id: envelope_id, recipients: recipients, raw: distribute_payload)
|
|
141
|
+
end
|
|
142
|
+
|
|
131
143
|
def execute(uri, request)
|
|
132
144
|
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
|
|
133
145
|
http.open_timeout = 10
|
|
@@ -19,11 +19,11 @@ module DocumensoRails
|
|
|
19
19
|
unsigned_attachment = public_send(DocumensoRails.configuration.unsigned_attachment_name)
|
|
20
20
|
raise Error, "No unsigned PDF attached to #{self.class.name}##{id}" unless unsigned_attachment.attached?
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
result = nil
|
|
23
23
|
target_redirect = redirect_url || DocumensoRails.configuration.redirect_url
|
|
24
24
|
|
|
25
25
|
unsigned_attachment.open do |tempfile|
|
|
26
|
-
|
|
26
|
+
result = DocumensoRails.client.create_and_send(
|
|
27
27
|
file_io: tempfile,
|
|
28
28
|
filename: "#{id}.pdf",
|
|
29
29
|
title: try(:title) || "Document ##{id}",
|
|
@@ -33,19 +33,14 @@ module DocumensoRails
|
|
|
33
33
|
)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
signature_status: "sent",
|
|
39
|
-
signature_sent_at: Time.current
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
envelope_id
|
|
36
|
+
apply_send_result!(result)
|
|
37
|
+
result
|
|
43
38
|
end
|
|
44
39
|
|
|
45
40
|
def send_from_template!(template_id:, signers:, prefill_fields: {}, title: nil, redirect_url: nil)
|
|
46
41
|
target_redirect = redirect_url || DocumensoRails.configuration.redirect_url
|
|
47
42
|
|
|
48
|
-
|
|
43
|
+
result = DocumensoRails.client.create_and_send_from_template(
|
|
49
44
|
template_id: template_id,
|
|
50
45
|
signers: signers,
|
|
51
46
|
prefill_fields: prefill_fields,
|
|
@@ -53,13 +48,20 @@ module DocumensoRails
|
|
|
53
48
|
redirect_url: target_redirect
|
|
54
49
|
)
|
|
55
50
|
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
apply_send_result!(result)
|
|
52
|
+
result
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
private
|
|
56
|
+
|
|
57
|
+
def apply_send_result!(result)
|
|
58
|
+
attrs = {
|
|
59
|
+
documenso_envelope_id: result.envelope_id,
|
|
58
60
|
signature_status: "sent",
|
|
59
61
|
signature_sent_at: Time.current
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
}
|
|
63
|
+
attrs[:signing_url] = result.signing_url if has_attribute?(:signing_url)
|
|
64
|
+
update!(attrs)
|
|
63
65
|
end
|
|
64
66
|
end
|
|
65
67
|
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module DocumensoRails
|
|
2
|
+
class SendResult
|
|
3
|
+
attr_reader :envelope_id, :recipients, :raw
|
|
4
|
+
|
|
5
|
+
def initialize(envelope_id:, recipients: [], raw: {})
|
|
6
|
+
@envelope_id = envelope_id
|
|
7
|
+
@recipients = recipients
|
|
8
|
+
@raw = raw
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def signing_url
|
|
12
|
+
recipients.find { |r| r[:signing_url].present? }&.dig(:signing_url)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
data/lib/documenso_rails.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
class AddDocumensoFieldsTo<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
|
|
2
2
|
def change
|
|
3
3
|
add_column :<%= table_name %>, :documenso_envelope_id, :string
|
|
4
|
+
add_column :<%= table_name %>, :signing_url, :string
|
|
4
5
|
add_column :<%= table_name %>, :signature_status, :string, default: "draft", null: false
|
|
5
6
|
add_column :<%= table_name %>, :signature_sent_at, :datetime
|
|
6
7
|
add_column :<%= table_name %>, :signature_completed_at, :datetime
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: documenso_rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jeremy Weiland
|
|
@@ -79,6 +79,7 @@ files:
|
|
|
79
79
|
- lib/documenso_rails/configuration.rb
|
|
80
80
|
- lib/documenso_rails/engine.rb
|
|
81
81
|
- lib/documenso_rails/model.rb
|
|
82
|
+
- lib/documenso_rails/send_result.rb
|
|
82
83
|
- lib/documenso_rails/version.rb
|
|
83
84
|
- lib/generators/documenso_rails/install_generator.rb
|
|
84
85
|
- lib/generators/documenso_rails/templates/initializer.rb.tt
|