rightsignature 0.1.8 → 1.0.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.
@@ -1,240 +1,236 @@
1
1
  module RightSignature
2
- class Template
3
- extend RightSignature::Helpers
4
-
5
- class << self
6
-
7
- # List Templates and passes in optional options.
8
- # Options:
9
- # * page: page number
10
- # * per_page: number of templates to return per page.
11
- # API only supports 10, 20, 30, 40, or 50. Default is 10.
12
- # * tags: filter templates by given tags. Array of strings, for name/value tags colon (:) should separate name and value.
13
- # Ex. "single_tag,tag_key:tag_value" would find templates with 'single_tag' and the name/value of 'tag_key' with value 'tag_value'.
14
- # * search: term to search for in templates.
15
- def list(options={})
16
- options[:tags] = TagsHelper.mixed_array_to_string_array(options[:tags]) if options[:tags]
17
- RightSignature::Connection.get "/api/templates.xml", options
18
- end
2
+ module Template
3
+ include RightSignature::Helpers
4
+ # List Templates and passes in optional options.
5
+ # Options:
6
+ # * page: page number
7
+ # * per_page: number of templates to return per page.
8
+ # API only supports 10, 20, 30, 40, or 50. Default is 10.
9
+ # * tags: filter templates by given tags. Array of strings, for name/value tags colon (:) should separate name and value.
10
+ # Ex. "single_tag,tag_key:tag_value" would find templates with 'single_tag' and the name/value of 'tag_key' with value 'tag_value'.
11
+ # * search: term to search for in templates.
12
+ def templates_list(options={})
13
+ options[:tags] = TagsHelper.mixed_array_to_string_array(options[:tags]) if options[:tags]
14
+ get "/api/templates.xml", options
15
+ end
16
+
17
+ def template_details(guid)
18
+ get "/api/templates/#{guid}.xml", {}
19
+ end
20
+
21
+ # Clones a template so it can be used for sending. Always first step in sending a template.
22
+ def prepackage(guid)
23
+ post "/api/templates/#{guid}/prepackage.xml", {}
24
+ end
25
+
26
+ # Prefills template.
27
+ # * guid: templates guid. Ex. a_1_zcfdidf8fi23
28
+ # * subject: subject of the document that'll appear in email
29
+ # * roles: Recipients of the document, should be an array of role names and emails in a hash with keys as role_names.
30
+ # Ex. [{"Employee" => {:name => "John Employee", :email => "john@employee.com"}}]
31
+ # is equivalent to
32
+ # <role role_name="Employee">
33
+ # <name>John Employee</name>
34
+ # <email>john@employee.com</email>
35
+ # </role>
36
+ # * options: other optional values
37
+ # - description: document description that'll appear in the email
38
+ # - merge_fields: document merge fields, should be an array of merge_field_values in a hash with the merge_field_name.
39
+ # Ex. [{"Salary" => "$1,000,000"}]
40
+ # is equivalent to
41
+ # <merge_field merge_field_name="Salary">
42
+ # <value>$1,000,000</value>
43
+ # </merge_field>
44
+ # - expires_in: number of days before expiring the document. API only allows 2,5,15, or 30.
45
+ # - tags: document tags, an array of string or hashes 'single_tag' (for simple tag) or {'tag_name' => 'tag_value'} (for tuples pairs)
46
+ # Ex. ['sent_from_api', {"user_id" => "32"}]
47
+ # - 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.
48
+ # Ex. "http://yoursite/callback"
49
+ #
50
+ # Ex. call with all options used
51
+ # RightSignature::Template.prefill(
52
+ # "a_1_zcfdidf8fi23",
53
+ # "Your Employee Handbook",
54
+ # [{"employee" => {:name => "John Employee", :email => "john@employee.com"}}],
55
+ # {
56
+ # :description => "Please read over the handbook and sign it.",
57
+ # :merge_fields => [
58
+ # { "Department" => "Fun and games" },
59
+ # { "Salary" => "$1,000,000" }
60
+ # ],
61
+ # :expires_in => 5,
62
+ # :tags => [
63
+ # {:name => 'sent_from_api'},
64
+ # {:name => 'user_id', :value => '32'}
65
+ # ],
66
+ # :callback_url => "http://yoursite/callback"
67
+ # })
68
+ def prefill(guid, subject, roles, options={})
69
+ xml_hash = {
70
+ :template => {
71
+ :guid => guid,
72
+ :action => "prefill",
73
+ :subject => subject
74
+ }
75
+ }
19
76
 
20
- def details(guid)
21
- RightSignature::Connection.get "/api/templates/#{guid}.xml", {}
22
- end
77
+ xml_hash[:template][:roles] = RolesHelper.array_to_xml_hash(roles)
23
78
 
24
- # Clones a template so it can be used for sending. Always first step in sending a template.
25
- def prepackage(guid)
26
- RightSignature::Connection.post "/api/templates/#{guid}/prepackage.xml", {}
79
+ # Optional arguments
80
+ use_merge_field_ids = options.delete(:use_merge_field_ids)
81
+ xml_hash[:template][:merge_fields] = MergeFieldsHelper.array_to_xml_hash(options[:merge_fields], use_merge_field_ids) if options[:merge_fields]
82
+ xml_hash[:template][:tags] = TagsHelper.array_to_xml_hash(options[:tags]) if options[:tags]
83
+ [:expires_in, :description, :callback_url, :action].each do |other_option|
84
+ xml_hash[:template][other_option] = options[other_option] if options[other_option]
27
85
  end
28
-
29
- # Prefills template.
30
- # * guid: templates guid. Ex. a_1_zcfdidf8fi23
31
- # * subject: subject of the document that'll appear in email
32
- # * roles: Recipients of the document, should be an array of role names and emails in a hash with keys as role_names.
33
- # Ex. [{"Employee" => {:name => "John Employee", :email => "john@employee.com"}}]
34
- # is equivalent to
35
- # <role role_name="Employee">
36
- # <name>John Employee</name>
37
- # <email>john@employee.com</email>
38
- # </role>
39
- # * options: other optional values
40
- # - description: document description that'll appear in the email
41
- # - merge_fields: document merge fields, should be an array of merge_field_values in a hash with the merge_field_name.
42
- # Ex. [{"Salary" => "$1,000,000"}]
43
- # is equivalent to
44
- # <merge_field merge_field_name="Salary">
45
- # <value>$1,000,000</value>
46
- # </merge_field>
47
- # - expires_in: number of days before expiring the document. API only allows 2,5,15, or 30.
48
- # - tags: document tags, an array of string or hashes 'single_tag' (for simple tag) or {'tag_name' => 'tag_value'} (for tuples pairs)
49
- # Ex. ['sent_from_api', {"user_id" => "32"}]
50
- # - 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.
51
- # Ex. "http://yoursite/callback"
52
- #
53
- # Ex. call with all options used
54
- # RightSignature::Template.prefill(
55
- # "a_1_zcfdidf8fi23",
56
- # "Your Employee Handbook",
57
- # [{"employee" => {:name => "John Employee", :email => "john@employee.com"}}],
58
- # {
59
- # :description => "Please read over the handbook and sign it.",
60
- # :merge_fields => [
61
- # { "Department" => "Fun and games" },
62
- # { "Salary" => "$1,000,000" }
63
- # ],
64
- # :expires_in => 5,
65
- # :tags => [
66
- # {:name => 'sent_from_api'},
67
- # {:name => 'user_id', :value => '32'}
68
- # ],
69
- # :callback_url => "http://yoursite/callback"
70
- # })
71
- def prefill(guid, subject, roles, options={})
72
- xml_hash = {
73
- :template => {
74
- :guid => guid,
75
- :action => "prefill",
76
- :subject => subject
77
- }
78
- }
79
-
80
- xml_hash[:template][:roles] = RolesHelper.array_to_xml_hash(roles)
81
-
82
- # Optional arguments
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]
85
- xml_hash[:template][:tags] = TagsHelper.array_to_xml_hash(options[:tags]) if options[:tags]
86
- [:expires_in, :description, :callback_url, :action].each do |other_option|
87
- xml_hash[:template][other_option] = options[other_option] if options[other_option]
88
- end
89
86
 
90
- RightSignature::Connection.post "/api/templates.xml", xml_hash
91
- end
87
+ post "/api/templates.xml", xml_hash
88
+ end
89
+
90
+ def prepackage_and_send(guid, roles, options={})
91
+ response = prepackage(guid)
92
+ new_guid = response["template"]["guid"]
93
+ send_template(new_guid, options.delete(:subject) || response["template"]["subject"], roles, options)
94
+ end
95
+
96
+ # Sends template.
97
+ # * guid: templates guid. Ex. a_1_zcfdidf8fi23
98
+ # * subject: subject of the document that'll appear in email
99
+ # * roles: Recipients of the document, should be an array of role names and emails in a hash with keys as role_names.
100
+ # Ex. [{"Employee" => {:name => "John Employee", :email => "john@employee.com"}}]
101
+ # is equivalent to
102
+ # <role role_name="Employee">
103
+ # <name>John Employee</name>
104
+ # <email>john@employee.com</email>
105
+ # </role>
106
+ # * options: other optional values
107
+ # - description: document description that'll appear in the email
108
+ # - merge_fields: document merge fields, should be an array of merge_field_values in a hash with the merge_field_name.
109
+ # Ex. [{"Salary" => "$1,000,000"}]
110
+ # is equivalent to
111
+ # <merge_field merge_field_name="Salary">
112
+ # <value>$1,000,000</value>
113
+ # </merge_field>
114
+ # - expires_in: number of days before expiring the document. API only allows 2,5,15, or 30.
115
+ # - tags: document tags, an array of {:name => 'tag_name'} (for simple tag) or {:name => 'tag_name', :value => 'value'} (for tuples pairs)
116
+ # Ex. [{:name => 'sent_from_api'}, {:name => "user_id", :value => "32"}]
117
+ # - 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.
118
+ # Ex. "http://yoursite/callback"
119
+ #
120
+ # Ex. call with all options used
121
+ # RightSignature::Template.prefill(
122
+ # "a_1_zcfdidf8fi23",
123
+ # "Your Employee Handbook",
124
+ # [{"employee" => {:name => "John Employee", :email => "john@employee.com"}}],
125
+ # {
126
+ # :description => "Please read over the handbook and sign it.",
127
+ # :merge_fields => [
128
+ # { "Department" => "Fun and games" },
129
+ # { "Salary" => "$1,000,000" }
130
+ # ],
131
+ # :expires_in => 5,
132
+ # :tags => [
133
+ # {:name => 'sent_from_api'},
134
+ # {:name => 'user_id', :value => '32'}
135
+ # ],
136
+ # :callback_url => "http://yoursite/callback"
137
+ # })
138
+ def send_template(guid, subject, roles, options={})
139
+ prefill(guid, subject, roles, options.merge({:action => 'send'}))
140
+ end
141
+
142
+ # Creates a URL that give person ability to create a template in your account.
143
+ # * options: optional options for redirected person
144
+ # - callback_location: URI encoded URL that specifies the location we will POST a callback notification to when the template has been created.
145
+ # - redirect_location: A URI encoded URL that specifies the location we will redirect the user to, after they have created a template.
146
+ # - tags: tags to add to the template. an array of 'tag_name' (for simple tag) or {'tag_name' => 'value'} (for tuples pairs)
147
+ # Ex. ['created_from_api', {"user_id" => "123"}]
148
+ # - acceptable_role_names: The user creating the Template will be forced to select one of the values provided.
149
+ # There will be no free-form name entry when adding roles to the Template. An array of strings.
150
+ # Ex. ["Employee", "Employeer"]
151
+ # - acceptable_merge_field_names: The user creating the Template will be forced to select one of the values provided.
152
+ # There will be no free-form name entry when adding merge fields to the Template.
153
+ # Ex. ["Location", "Tax ID", "Company Name"]
154
+ def generate_build_url(options={})
155
+ xml_hash = {:template => {}}
156
+ xml_hash[:template][:tags] = TagsHelper.array_to_xml_hash(options[:tags]) if options[:tags]
92
157
 
93
- def prepackage_and_send(guid, roles, options={})
94
- response = prepackage(guid)
95
- new_guid = response["template"]["guid"]
96
- send_template(new_guid, options.delete(:subject) || response["template"]["subject"], roles, options)
158
+ [:acceptable_merge_field_names, :acceptable_role_names].each do |option|
159
+ xml_hash[:template][option] = array_to_acceptable_names_hash(options[option]) if options[option]
97
160
  end
98
161
 
99
- # Sends template.
100
- # * guid: templates guid. Ex. a_1_zcfdidf8fi23
101
- # * subject: subject of the document that'll appear in email
102
- # * roles: Recipients of the document, should be an array of role names and emails in a hash with keys as role_names.
103
- # Ex. [{"Employee" => {:name => "John Employee", :email => "john@employee.com"}}]
104
- # is equivalent to
105
- # <role role_name="Employee">
106
- # <name>John Employee</name>
107
- # <email>john@employee.com</email>
108
- # </role>
109
- # * options: other optional values
110
- # - description: document description that'll appear in the email
111
- # - merge_fields: document merge fields, should be an array of merge_field_values in a hash with the merge_field_name.
112
- # Ex. [{"Salary" => "$1,000,000"}]
113
- # is equivalent to
114
- # <merge_field merge_field_name="Salary">
115
- # <value>$1,000,000</value>
116
- # </merge_field>
117
- # - expires_in: number of days before expiring the document. API only allows 2,5,15, or 30.
118
- # - tags: document tags, an array of {:name => 'tag_name'} (for simple tag) or {:name => 'tag_name', :value => 'value'} (for tuples pairs)
119
- # Ex. [{:name => 'sent_from_api'}, {:name => "user_id", :value => "32"}]
120
- # - 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.
121
- # Ex. "http://yoursite/callback"
122
- #
123
- # Ex. call with all options used
124
- # RightSignature::Template.prefill(
125
- # "a_1_zcfdidf8fi23",
126
- # "Your Employee Handbook",
127
- # [{"employee" => {:name => "John Employee", :email => "john@employee.com"}}],
128
- # {
129
- # :description => "Please read over the handbook and sign it.",
130
- # :merge_fields => [
131
- # { "Department" => "Fun and games" },
132
- # { "Salary" => "$1,000,000" }
133
- # ],
134
- # :expires_in => 5,
135
- # :tags => [
136
- # {:name => 'sent_from_api'},
137
- # {:name => 'user_id', :value => '32'}
138
- # ],
139
- # :callback_url => "http://yoursite/callback"
140
- # })
141
- def send_template(guid, subject, roles, options={})
142
- prefill(guid, subject, roles, options.merge({:action => 'send'}))
162
+ [:callback_location, :redirect_location].each do |other_option|
163
+ xml_hash[:template][other_option] = options[other_option] if options[other_option]
143
164
  end
144
-
145
- # Creates a URL that give person ability to create a template in your account.
146
- # * options: optional options for redirected person
147
- # - callback_location: URI encoded URL that specifies the location we will POST a callback notification to when the template has been created.
148
- # - redirect_location: A URI encoded URL that specifies the location we will redirect the user to, after they have created a template.
149
- # - tags: tags to add to the template. an array of 'tag_name' (for simple tag) or {'tag_name' => 'value'} (for tuples pairs)
150
- # Ex. ['created_from_api', {"user_id" => "123"}]
151
- # - acceptable_role_names: The user creating the Template will be forced to select one of the values provided.
152
- # There will be no free-form name entry when adding roles to the Template. An array of strings.
153
- # Ex. ["Employee", "Employeer"]
154
- # - acceptable_merge_field_names: The user creating the Template will be forced to select one of the values provided.
155
- # There will be no free-form name entry when adding merge fields to the Template.
156
- # Ex. ["Location", "Tax ID", "Company Name"]
157
- def generate_build_url(options={})
158
- xml_hash = {:template => {}}
159
- xml_hash[:template][:tags] = TagsHelper.array_to_xml_hash(options[:tags]) if options[:tags]
160
-
161
- [:acceptable_merge_field_names, :acceptable_role_names].each do |option|
162
- xml_hash[:template][option] = array_to_acceptable_names_hash(options[option]) if options[option]
163
- end
164
-
165
- [:callback_location, :redirect_location].each do |other_option|
166
- xml_hash[:template][other_option] = options[other_option] if options[other_option]
167
- end
168
165
 
169
- response = RightSignature::Connection.post "/api/templates/generate_build_token.xml", xml_hash
170
-
171
- redirect_token = response["token"]["redirect_token"]
172
-
173
- "#{RightSignature::Connection.site}/builder/new?rt=#{redirect_token}"
174
- end
166
+ response = post "/api/templates/generate_build_token.xml", xml_hash
175
167
 
176
- # Sends template with all roles as embedded signers and returns an array of hashes with :name and :url for each signer link.
177
- # * guid: templates guid. Ex. a_1_zcfdidf8fi23
178
- # * roles: Recipients of the document, should be an array of role names in a hash with keys as role_names.
179
- # Ex. [{"Employee" => {:name => "John Employee"}]
180
- # is equivalent to
181
- # <role role_name="Employee">
182
- # <name>John Employee</name>
183
- # <email>noemail@rightsignature.com</email>
184
- # </role>
185
- # * options: other optional values
186
- # - subject: subject of the document that'll appear in email. Defaults to Template's subject
187
- # - description: document description that'll appear in the email
188
- # - merge_fields: document merge fields, should be an array of merge_field_values in a hash with the merge_field_name.
189
- # Ex. [{"Salary" => "$1,000,000"}]
190
- # is equivalent to
191
- # <merge_field merge_field_name="Salary">
192
- # <value>$1,000,000</value>
193
- # </merge_field>
194
- # - expires_in: number of days before expiring the document. API only allows 2,5,15, or 30.
195
- # - tags: document tags, an array of {:name => 'tag_name'} (for simple tag) or {:name => 'tag_name', :value => 'value'} (for tuples pairs)
196
- # Ex. [{:name => 'sent_from_api'}, {:name => "user_id", :value => "32"}]
197
- # - 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.
198
- # Ex. "http://yoursite/callback"
199
- # - redirect_location: A URI encoded URL that specifies the location for the signing widget to redirect the user to after it is signed.
200
- # Ex. "http://yoursite/thanks_for_signing"
201
- #
202
- # Ex. call with all options used
203
- # RightSignature::Template.prefill(
204
- # "a_1_zcfdidf8fi23",
205
- # "Your Employee Handbook",
206
- # [{"employee" => {:name => "John Employee", :email => "john@employee.com"}}],
207
- # {
208
- # :description => "Please read over the handbook and sign it.",
209
- # :merge_fields => [
210
- # { "Department" => "Fun and games" },
211
- # { "Salary" => "$1,000,000" }
212
- # ],
213
- # :expires_in => 5,
214
- # :tags => [
215
- # {:name => 'sent_from_api'},
216
- # {:name => 'user_id', :value => '32'}
217
- # ],
218
- # :callback_url => "http://yoursite/callback"
219
- # })
220
- def send_as_embedded_signers(guid, recipients, options={})
221
- redirect_location = options.delete(:redirect_location)
168
+ redirect_token = response["token"]["redirect_token"]
169
+
170
+ "#{site}/builder/new?rt=#{redirect_token}"
171
+ end
172
+
173
+ # Sends template with all roles as embedded signers and returns an array of hashes with :name and :url for each signer link.
174
+ # * guid: templates guid. Ex. a_1_zcfdidf8fi23
175
+ # * roles: Recipients of the document, should be an array of role names in a hash with keys as role_names.
176
+ # Ex. [{"Employee" => {:name => "John Employee"}]
177
+ # is equivalent to
178
+ # <role role_name="Employee">
179
+ # <name>John Employee</name>
180
+ # <email>noemail@rightsignature.com</email>
181
+ # </role>
182
+ # * options: other optional values
183
+ # - subject: subject of the document that'll appear in email. Defaults to Template's subject
184
+ # - description: document description that'll appear in the email
185
+ # - merge_fields: document merge fields, should be an array of merge_field_values in a hash with the merge_field_name.
186
+ # Ex. [{"Salary" => "$1,000,000"}]
187
+ # is equivalent to
188
+ # <merge_field merge_field_name="Salary">
189
+ # <value>$1,000,000</value>
190
+ # </merge_field>
191
+ # - expires_in: number of days before expiring the document. API only allows 2,5,15, or 30.
192
+ # - tags: document tags, an array of {:name => 'tag_name'} (for simple tag) or {:name => 'tag_name', :value => 'value'} (for tuples pairs)
193
+ # Ex. [{:name => 'sent_from_api'}, {:name => "user_id", :value => "32"}]
194
+ # - 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.
195
+ # Ex. "http://yoursite/callback"
196
+ # - redirect_location: A URI encoded URL that specifies the location for the signing widget to redirect the user to after it is signed.
197
+ # Ex. "http://yoursite/thanks_for_signing"
198
+ #
199
+ # Ex. call with all options used
200
+ # RightSignature::Template.prefill(
201
+ # "a_1_zcfdidf8fi23",
202
+ # "Your Employee Handbook",
203
+ # [{"employee" => {:name => "John Employee", :email => "john@employee.com"}}],
204
+ # {
205
+ # :description => "Please read over the handbook and sign it.",
206
+ # :merge_fields => [
207
+ # { "Department" => "Fun and games" },
208
+ # { "Salary" => "$1,000,000" }
209
+ # ],
210
+ # :expires_in => 5,
211
+ # :tags => [
212
+ # {:name => 'sent_from_api'},
213
+ # {:name => 'user_id', :value => '32'}
214
+ # ],
215
+ # :callback_url => "http://yoursite/callback"
216
+ # })
217
+ def send_as_embedded_signers(guid, recipients, options={})
218
+ redirect_location = options.delete(:redirect_location)
222
219
 
223
- response = prepackage(guid)
224
- template = response["template"]
220
+ response = prepackage(guid)
221
+ template = response["template"]
225
222
 
226
- recipients.each do |role_hash|
227
- key, value = role_hash.first
228
- role_hash[key][:email] = "noemail@rightsignature.com" unless role_hash[key]["email"] || role_hash[key][:email]
229
- end
230
-
231
- response = send_template(template["guid"], options[:subject] || template["subject"], recipients, options)
232
- document_guid = response["document"]["guid"]
233
-
234
- RightSignature::Document.get_signer_links_for(document_guid, redirect_location)
223
+ recipients.each do |role_hash|
224
+ key, value = role_hash.first
225
+ role_hash[key][:email] = "noemail@rightsignature.com" unless role_hash[key]["email"] || role_hash[key][:email]
235
226
  end
236
227
 
228
+ response = send_template(template["guid"], options[:subject] || template["subject"], recipients, options)
229
+ document_guid = response["document"]["guid"]
237
230
 
231
+ get_document_signer_links_for(document_guid, redirect_location)
238
232
  end
233
+
234
+
239
235
  end
240
236
  end