rightsignature 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +31 -23
- data/lib/rightsignature/helpers/normalizing.rb +14 -5
- data/lib/rightsignature/template.rb +2 -1
- data/lib/rightsignature/version.rb +1 -1
- data/spec/normalizing_spec.rb +67 -0
- data/spec/template_spec.rb +32 -0
- metadata +2 -1
data/README.md
CHANGED
@@ -8,7 +8,7 @@ gem install rightsignature
|
|
8
8
|
```
|
9
9
|
or in your Gemfile
|
10
10
|
```
|
11
|
-
gem 'rightsignature', '~> 0.1.
|
11
|
+
gem 'rightsignature', '~> 0.1.5'
|
12
12
|
```
|
13
13
|
|
14
14
|
Setup
|
@@ -199,6 +199,7 @@ Optional options:
|
|
199
199
|
Ex. ['sent_from_api', {"user_id" => "32"}]
|
200
200
|
* callback_url: A URI encoded URL that specifies the location for API to POST a callback notification to when the document has been created and signed.
|
201
201
|
Ex. "http://yoursite/callback"
|
202
|
+
* use_merge_field_ids: Using merge field ids instead of merge field name for merge_fields. true or false.
|
202
203
|
|
203
204
|
#####Template Prepacking
|
204
205
|
For cloning a Template before sending it.
|
@@ -211,17 +212,20 @@ After prepacking, the new template can be updated with prefill data. This won't
|
|
211
212
|
```
|
212
213
|
RightSignature::Template.prefill(guid, subject, roles)
|
213
214
|
```
|
214
|
-
|
215
|
-
|
216
|
-
*
|
217
|
-
*
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
215
|
+
* guid: template guid to use. Should be a template that was prepackaged
|
216
|
+
* subject: document subject.
|
217
|
+
* roles: recipient names in array of {:name => "Person's Name", :email => "Email"} hashed by Role ID. Ex. {"signer_A" => {:name => "Your Name", :name => "a@example.com"}}
|
218
|
+
* Optional options:
|
219
|
+
* description: document description that'll appear in the email
|
220
|
+
* merge_fields: document merge fields, should be an array of merge_field_values in a hash with the merge_field_name.
|
221
|
+
Ex. [{"Salary" => "$1,000,000"}]
|
222
|
+
* expires_in: number of days before expiring the document. API only allows 2,5,15, or 30.
|
223
|
+
* tags: document tags, an array of string or hashes 'single_tag' (for simple tag) or {'tag_name' => 'tag_value'} (for tuples pairs)
|
224
|
+
Ex. ['sent_from_api', {"user_id" => "32"}]
|
225
|
+
* callback_url: A URI encoded URL that specifies the location for API to POST a callback notification to when the document has been created and signed.
|
226
|
+
Ex. "http://yoursite/callback"
|
227
|
+
* use_merge_field_ids: Using merge field ids instead of merge field name for merge_fields. true or false.
|
228
|
+
|
225
229
|
```
|
226
230
|
options = {
|
227
231
|
:description => "Please read over the handbook and sign it.",
|
@@ -245,16 +249,19 @@ Send template as a document for signing. Same options as prefill.
|
|
245
249
|
```
|
246
250
|
RightSignature::Template.send_template(guid, subject, roles)
|
247
251
|
```
|
248
|
-
|
249
|
-
|
250
|
-
*
|
251
|
-
*
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
252
|
+
* guid: template guid to use. Should be a template that was prepackaged
|
253
|
+
* subject: document subject.
|
254
|
+
* roles: recipient names in array of {:name => "Person's Name", :email => "Email"} hashed by Role ID. Ex. {"signer_A" => {:name => "Your Name", :name => "a@example.com"}}
|
255
|
+
* Optional options:
|
256
|
+
* description: document description that'll appear in the email
|
257
|
+
* merge_fields: document merge fields, should be an array of merge_field_values in a hash with the merge_field_name.
|
258
|
+
Ex. [{"Salary" => "$1,000,000"}]
|
259
|
+
* expires_in: number of days before expiring the document. API only allows 2,5,15, or 30.
|
260
|
+
* tags: document tags, an array of string or hashes 'single_tag' (for simple tag) or {'tag_name' => 'tag_value'} (for tuples pairs)
|
261
|
+
Ex. ['sent_from_api', {"user_id" => "32"}]
|
262
|
+
* callback_url: A URI encoded URL that specifies the location for API to POST a callback notification to when the document has been created and signed.
|
263
|
+
Ex. "http://yoursite/callback"
|
264
|
+
* use_merge_field_ids: Using merge field ids instead of merge field name for merge_fields. true or false.
|
258
265
|
|
259
266
|
```
|
260
267
|
options = {
|
@@ -280,7 +287,7 @@ Returns an array of {:name => "John Bellingham", "url" => "https://rightsignatur
|
|
280
287
|
RightSignature::Template.send_as_embedded_signers(guid, recipients, options={})
|
281
288
|
```
|
282
289
|
* guid: guid of template to create document with
|
283
|
-
* recipient: recipient names in array of {"
|
290
|
+
* recipient: recipient names in array of {:name => "Person's Name"} hashed by Role ID. Ex. {"signer_A" => {:name => "Your Name"}}
|
284
291
|
* options:
|
285
292
|
* subject: document subject that'll appear in the email
|
286
293
|
* description: document description that'll appear in the email
|
@@ -292,6 +299,7 @@ RightSignature::Template.send_as_embedded_signers(guid, recipients, options={})
|
|
292
299
|
* callback_url: A URI encoded URL that specifies the location for API to POST a callback notification to when the document has been created and signed.
|
293
300
|
Ex. "http://yoursite/callback"
|
294
301
|
* redirect_location: URL to redirect users after signing.
|
302
|
+
* use_merge_field_ids: Using merge field ids instead of merge field name for merge_fields. true or false.
|
295
303
|
|
296
304
|
#####Create New Template Link
|
297
305
|
Generate a url that let's someone upload and create a template under OAuth user's account.
|
@@ -34,14 +34,19 @@ module RightSignature::Helpers
|
|
34
34
|
|
35
35
|
module RolesHelper
|
36
36
|
class <<self
|
37
|
-
# Converts [{"
|
38
|
-
# [{:role => {:name => "John", :email => "email@example.com", "@
|
37
|
+
# Converts [{"Role_ID" => {:name => "John", :email => "email@example.com"}}] to
|
38
|
+
# [{:role => {:name => "John", :email => "email@example.com", "@role_id" => "Role_ID"} }]
|
39
|
+
# Tries to guess if it's using Role ID or Role Name
|
39
40
|
def array_to_xml_hash(roles_array)
|
40
41
|
roles_hash_array = []
|
41
42
|
roles_array.each do |role_hash|
|
42
43
|
name, value = role_hash.first
|
43
44
|
raise "Hash '#{role_hash.inspect}' is malformed, should be something like {ROLE_NAME => {:name => \"a\", :email => \"a@a.com\"}}" unless value.is_a? Hash and name.is_a? String
|
44
|
-
|
45
|
+
if name.match(/^signer_[A-Z]+$/) || name.match(/^cc_[A-Z]+$/)
|
46
|
+
roles_hash_array << {:role => value.merge({"@role_id" => name})}
|
47
|
+
else
|
48
|
+
roles_hash_array << {:role => value.merge({"@role_name" => name})}
|
49
|
+
end
|
45
50
|
end
|
46
51
|
|
47
52
|
roles_hash_array
|
@@ -55,11 +60,15 @@ module RightSignature::Helpers
|
|
55
60
|
class <<self
|
56
61
|
# Converts [{"Role Name" => {:name => "John", :email => "email@example.com"}}] to
|
57
62
|
# [{"role roles_name=\"Role Name\"" => {:role => {:name => "John", :email => "email@example.com"}} }]
|
58
|
-
def array_to_xml_hash(merge_fields_array)
|
63
|
+
def array_to_xml_hash(merge_fields_array, use_id=false)
|
59
64
|
merge_fields = []
|
60
65
|
merge_fields_array.each do |merge_field_hash|
|
61
66
|
name, value = merge_field_hash.first
|
62
|
-
|
67
|
+
if use_id
|
68
|
+
merge_fields << { :merge_field => {:value => value, "@merge_field_id" => name}}
|
69
|
+
else
|
70
|
+
merge_fields << { :merge_field => {:value => value, "@merge_field_name" => name}}
|
71
|
+
end
|
63
72
|
end
|
64
73
|
|
65
74
|
merge_fields
|
@@ -80,7 +80,8 @@ module RightSignature
|
|
80
80
|
xml_hash[:template][:roles] = RolesHelper.array_to_xml_hash(roles)
|
81
81
|
|
82
82
|
# Optional arguments
|
83
|
-
|
83
|
+
use_merge_field_ids = options.delete(:use_merge_field_ids)
|
84
|
+
xml_hash[:template][:merge_fields] = MergeFieldsHelper.array_to_xml_hash(options[:merge_fields], use_merge_field_ids) if options[:merge_fields]
|
84
85
|
xml_hash[:template][:tags] = TagsHelper.array_to_xml_hash(options[:tags]) if options[:tags]
|
85
86
|
[:expires_in, :description, :callback_url, :action].each do |other_option|
|
86
87
|
xml_hash[:template][other_option] = options[other_option] if options[other_option]
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe RightSignature::Helpers::TagsHelper do
|
4
|
+
describe "mixed_array_to_string_array" do
|
5
|
+
it "should convert array of strings and hashes to string" do
|
6
|
+
RightSignature::Helpers::TagsHelper.mixed_array_to_string_array(["a", {'good' => "yea"}, '123']).should == "a,good:yea,123"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should raise error if array contains something other than hash or string" do
|
10
|
+
lambda {RightSignature::Helpers::TagsHelper.mixed_array_to_string_array(["a", ['bad'], {'good' => "yea"}])}.should raise_error
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "array_to_xml_hash" do
|
15
|
+
it "should convert array of string and hash of {name => value} into array of :tag => {:name => name, :value => value}" do
|
16
|
+
RightSignature::Helpers::TagsHelper.array_to_xml_hash(['abc', {"taggy" => "tvalue"}]).should == [{:tag => {:name => 'abc'}}, {:tag => {:name => 'taggy', :value => 'tvalue'}}]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe RightSignature::Helpers::RolesHelper do
|
22
|
+
describe "array_to_xml_hash" do
|
23
|
+
it "should convert array of {\"Role name\" => {:name => name, :email => email}} to array of {:role => {:name => name, :email => email, \"@role_id\" => \"Role name\"}} " do
|
24
|
+
results = RightSignature::Helpers::RolesHelper.array_to_xml_hash([
|
25
|
+
{"Leaser" => {:name => "John Bellingham", :email => "j@example.com"}},
|
26
|
+
{"Leasee" => {:name => "Timmy S", :email => "t@example.com"}}
|
27
|
+
])
|
28
|
+
results.size.should == 2
|
29
|
+
results.include?({:role => {:name => "John Bellingham", :email => "j@example.com", "@role_name" => "Leaser"}})
|
30
|
+
results.include?({:role => {:name => "Timmy S", :email => "t@example.com", "@role_name" => "Leasee"}})
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should convert array of {\"signer_A\" => {:name => name, :email => email}} or {\"cc_A\" => {:name => name, :email => email}} to array of {:role => {:name => name, :email => email, \"@role_id\" => \"signer_a\"}} " do
|
34
|
+
results = RightSignature::Helpers::RolesHelper.array_to_xml_hash([
|
35
|
+
{"signer_A" => {:name => "John Bellingham", :email => "j@example.com"}},
|
36
|
+
{"cc_A" => {:name => "Timmy S", :email => "t@example.com"}}
|
37
|
+
])
|
38
|
+
results.size.should == 2
|
39
|
+
results.include?({:role => {:name => "John Bellingham", :email => "j@example.com", "@role_id" => "signer_A"}})
|
40
|
+
results.include?({:role => {:name => "Timmy S", :email => "t@example.com", "@role_id" => "cc_A"}})
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe RightSignature::Helpers::MergeFieldsHelper do
|
46
|
+
describe "array_to_xml_hash" do
|
47
|
+
it "should convert array of {\"Merge field name\" => \"Merge Field Value\"} to array of {:merge_field => {:value => \"Merge Field Value\", \"@merge_field_name\" => \"Merge Field Name\"}} " do
|
48
|
+
results = RightSignature::Helpers::MergeFieldsHelper.array_to_xml_hash([
|
49
|
+
{"City" => "Santa Barbara"},
|
50
|
+
{"Section" => "House"}
|
51
|
+
])
|
52
|
+
results.size.should == 2
|
53
|
+
results.include?({:merge_field => {:value => "Santa Barbara", "@merge_field_name" => "City"}})
|
54
|
+
results.include?({:merge_field => {:value => "House", "@merge_field_name" => "Section"}})
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should convert array of {\"Merge field name\" => \"Merge Field Value\"} to array of {:merge_field => {:value => \"Merge Field Value\", \"@merge_field_id\" => \"Merge Field Name\"}} " do
|
58
|
+
results = RightSignature::Helpers::MergeFieldsHelper.array_to_xml_hash([
|
59
|
+
{"1_abc_defg" => "Santa Barbara"},
|
60
|
+
{"2_345_789" => "House"}
|
61
|
+
], true)
|
62
|
+
results.size.should == 2
|
63
|
+
results.include?({:merge_field => {:value => "Santa Barbara", "@merge_field_id" => "1_abc_defg"}})
|
64
|
+
results.include?({:merge_field => {:value => "House", "@merge_field_id" => "2_345_789"}})
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/spec/template_spec.rb
CHANGED
@@ -80,6 +80,24 @@ describe RightSignature::Template do
|
|
80
80
|
})
|
81
81
|
RightSignature::Template.prefill("MYGUID", "sign me", [{"Employee" => {:name => "John Employee", :email => "john@employee.com"}}])
|
82
82
|
end
|
83
|
+
|
84
|
+
it "should add \"@role_id\"=>'signer_A' key to roles in xml hash" do
|
85
|
+
RightSignature::Connection.should_receive(:post).with('/api/templates.xml', {
|
86
|
+
:template => {
|
87
|
+
:guid => "MYGUID",
|
88
|
+
:action => "prefill",
|
89
|
+
:subject => "sign me",
|
90
|
+
:roles => [
|
91
|
+
{:role => {
|
92
|
+
:name => "John Employee",
|
93
|
+
:email => "john@employee.com",
|
94
|
+
"@role_id" => "signer_A"
|
95
|
+
}}
|
96
|
+
]
|
97
|
+
}
|
98
|
+
})
|
99
|
+
RightSignature::Template.prefill("MYGUID", "sign me", [{"signer_A" => {:name => "John Employee", :email => "john@employee.com"}}])
|
100
|
+
end
|
83
101
|
|
84
102
|
describe "optional options" do
|
85
103
|
it "should add \"@merge_field_name\"=>'Tax_id' key to merge_fields in xml hash" do
|
@@ -96,6 +114,20 @@ describe RightSignature::Template do
|
|
96
114
|
RightSignature::Template.prefill("MYGUID", "sign me", [], {:merge_fields => [{"Tax_id" => "123456"}]})
|
97
115
|
end
|
98
116
|
|
117
|
+
it "should add \"@merge_field_id\"=>'123_abc_78' key to merge_fields in xml hash" do
|
118
|
+
RightSignature::Connection.should_receive(:post).with('/api/templates.xml', {
|
119
|
+
:template => {
|
120
|
+
:guid => "MYGUID",
|
121
|
+
:action => "prefill",
|
122
|
+
:subject => "sign me",
|
123
|
+
:roles => [
|
124
|
+
],
|
125
|
+
:merge_fields => [{:merge_field => {:value => "123456", "@merge_field_id" => "123_abc_78"}}]
|
126
|
+
}
|
127
|
+
})
|
128
|
+
RightSignature::Template.prefill("MYGUID", "sign me", [], {:merge_fields => [{"123_abc_78" => "123456"}], :use_merge_field_ids => true})
|
129
|
+
end
|
130
|
+
|
99
131
|
it "should add \"tag\" key to tags in xml hash" do
|
100
132
|
RightSignature::Connection.should_receive(:post).with('/api/templates.xml', {
|
101
133
|
:template => {
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rightsignature
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -136,6 +136,7 @@ files:
|
|
136
136
|
- spec/connection_spec.rb
|
137
137
|
- spec/document_spec.rb
|
138
138
|
- spec/errors_spec.rb
|
139
|
+
- spec/normalizing_spec.rb
|
139
140
|
- spec/oauth_connnection_spec.rb
|
140
141
|
- spec/spec_helper.rb
|
141
142
|
- spec/template_spec.rb
|