rightsignature 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +38 -0
- data/README.md +317 -0
- data/lib/rightsignature.rb +62 -0
- data/lib/rightsignature/connection.rb +58 -0
- data/lib/rightsignature/connection/oauth_connection.rb +34 -0
- data/lib/rightsignature/connection/token_connection.rb +19 -0
- data/lib/rightsignature/document.rb +216 -0
- data/lib/rightsignature/errors.rb +28 -0
- data/lib/rightsignature/helpers/normalizing.rb +79 -0
- data/lib/rightsignature/template.rb +177 -0
- data/lib/rightsignature/version.rb +3 -0
- data/rightsignature-api.gemspec +26 -0
- data/spec/api_token_connection_spec.rb +19 -0
- data/spec/configuration_spec.rb +98 -0
- data/spec/connection_spec.rb +95 -0
- data/spec/document_spec.rb +256 -0
- data/spec/errors_spec.rb +119 -0
- data/spec/oauth_connnection_spec.rb +42 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/template_spec.rb +189 -0
- metadata +136 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
module RightSignature
|
2
|
+
class OauthConnection
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def oauth_consumer
|
6
|
+
@oauth_consumer ||= OAuth::Consumer.new(
|
7
|
+
RightSignature::configuration[:consumer_key],
|
8
|
+
RightSignature::configuration[:consumer_secret],
|
9
|
+
{
|
10
|
+
:site => "https://rightsignature.com",
|
11
|
+
:scheme => :header,
|
12
|
+
:http_method => :post,
|
13
|
+
:authorize_path =>'/oauth/authorize',
|
14
|
+
:access_token_path =>'/oauth/access_token',
|
15
|
+
:request_token_path=>'/oauth/request_token'
|
16
|
+
}
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def access_token
|
21
|
+
@access_token ||= OAuth::AccessToken.new(oauth_consumer, RightSignature::configuration[:access_token], RightSignature::configuration[:access_secret])
|
22
|
+
end
|
23
|
+
|
24
|
+
def request(method, *options)
|
25
|
+
options.last ||= {}
|
26
|
+
options.last["Accept"] ||= "*/*"
|
27
|
+
options.last["content-type"] ||= "application/xml"
|
28
|
+
|
29
|
+
self.access_token.__send__(method, *options)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module RightSignature
|
2
|
+
class TokenConnection
|
3
|
+
include HTTParty
|
4
|
+
base_uri 'https://rightsignature.com'
|
5
|
+
format :xml
|
6
|
+
|
7
|
+
class <<self
|
8
|
+
def request(method, url, options)
|
9
|
+
options[:headers] ||= {}
|
10
|
+
options[:headers]['api-token'] = RightSignature::configuration[:api_token]
|
11
|
+
options[:headers]["Accept"] ||= "*/*"
|
12
|
+
options[:headers]["content-type"] ||= "application/xml"
|
13
|
+
__send__(method, url, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,216 @@
|
|
1
|
+
module RightSignature
|
2
|
+
class Document
|
3
|
+
extend RightSignature::Helpers
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def list(options={})
|
8
|
+
options[:tags] = TagsHelper.mixed_array_to_string_array(options[:tags]) if options[:tags]
|
9
|
+
options[:state] = options[:state].join(',') if options[:state] && options[:state].is_a?(Array)
|
10
|
+
RightSignature::Connection.get "/api/documents.xml", options
|
11
|
+
end
|
12
|
+
|
13
|
+
def details(guid)
|
14
|
+
RightSignature::Connection.get "/api/documents/#{guid}.xml"
|
15
|
+
end
|
16
|
+
|
17
|
+
def batch_details(guids)
|
18
|
+
RightSignature::Connection.get "/api/documents/#{guids.join(',')}/batch_details.xml"
|
19
|
+
end
|
20
|
+
|
21
|
+
def send_reminder(guid)
|
22
|
+
RightSignature::Connection.post "/api/documents/#{guid}/send_reminders.xml", {}
|
23
|
+
end
|
24
|
+
|
25
|
+
def trash(guid)
|
26
|
+
RightSignature::Connection.post "/api/documents/#{guid}/trash.xml", {}
|
27
|
+
end
|
28
|
+
|
29
|
+
def extend_expiration(guid)
|
30
|
+
RightSignature::Connection.post "/api/documents/#{guid}/extend_expiration.xml", {}
|
31
|
+
end
|
32
|
+
|
33
|
+
# This will REPLACE the tags on a document
|
34
|
+
# tags are an array of 'tag_name' or {'tag_name' => 'value'}
|
35
|
+
# Hash style:
|
36
|
+
# {:name => value}
|
37
|
+
def update_tags(guid, tags)
|
38
|
+
RightSignature::Connection.post "/api/documents/#{guid}/update_tags.xml", { :tags => TagsHelper.array_to_xml_hash(tags) }
|
39
|
+
end
|
40
|
+
|
41
|
+
# Creates a document from a raw data
|
42
|
+
# * file: file binary. Ex. File.read('myfile.pdf')
|
43
|
+
# * filename: original filename
|
44
|
+
# * subject: subject of the document that'll appear in email
|
45
|
+
# * recipients: Recipients of the document, should be an array of hashes with :name, :email, and :role ('cc' or 'signer').
|
46
|
+
# An optional :is_sender (true/false) is used to referrence the API User and won't need to supply :name and :email
|
47
|
+
# Ex. CC to support@rightsignature.com, with sender and john@rightsignature.com as a signer
|
48
|
+
# [
|
49
|
+
# {:name => "RightSignature", :email => "support@rightsignature.com", :role => 'cc'},
|
50
|
+
# {:name => "John Bellingham", :email => "john@rightsignature.com", :role => 'signer'},
|
51
|
+
# {'is_sender' => true, :role => 'signer'},
|
52
|
+
# ]
|
53
|
+
# * options: other optional values
|
54
|
+
# - description: document description that'll appear in the email
|
55
|
+
# - action: 'send' or 'redirect'. Redirect will return a token that will allow another person to send the document under API user's account
|
56
|
+
# - expires_in: number of days before expiring the document. API only allows 2,5,15, or 30.
|
57
|
+
# - tags: document tags, an array of string or hashes 'single_tag' (for simple tag) or {'tag_name' => 'tag_value'} (for tuples pairs)
|
58
|
+
# Ex. ['sent_from_api', {"user_id" => "32"}]
|
59
|
+
# - 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.
|
60
|
+
# Ex. "http://yoursite/callback"
|
61
|
+
# - use_text_tags: Document has special Text Tags that RightSignature parse. true or false.
|
62
|
+
# More info: https://rightsignature.com/apidocs/text_tags
|
63
|
+
def send_document_from_data(file_data, filename, subject, recipients, options={})
|
64
|
+
send_document(subject, recipients, {:type => "base64", :filename => filename, :value => Base64::encode64(file_data)}, options)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Creates a document from a File or path to file
|
68
|
+
# * file: Path to file or File object
|
69
|
+
# * subject: subject of the document that'll appear in email
|
70
|
+
# * recipients: Recipients of the document, should be an array of hashes with :name, :email, and :role ('cc' or 'signer').
|
71
|
+
# An optional :is_sender (true/false) is used to referrence the API User and won't need to supply :name and :email
|
72
|
+
# Ex. CC to support@rightsignature.com, with sender and john@rightsignature.com as a signer
|
73
|
+
# [
|
74
|
+
# {:name => "RightSignature", :email => "support@rightsignature.com", :role => 'cc'},
|
75
|
+
# {:name => "John Bellingham", :email => "john@rightsignature.com", :role => 'signer'},
|
76
|
+
# {'is_sender' => true, :role => 'signer'},
|
77
|
+
# ]
|
78
|
+
# * options: other optional values
|
79
|
+
# - description: document description that'll appear in the email
|
80
|
+
# - action: 'send' or 'redirect'. Redirect will return a token that will allow another person to send the document under API user's account
|
81
|
+
# - expires_in: number of days before expiring the document. API only allows 2,5,15, or 30.
|
82
|
+
# - tags: document tags, an array of string or hashes 'single_tag' (for simple tag) or {'tag_name' => 'tag_value'} (for tuples pairs)
|
83
|
+
# Ex. ['sent_from_api', {"user_id" => "32"}]
|
84
|
+
# - 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.
|
85
|
+
# Ex. "http://yoursite/callback"
|
86
|
+
# - use_text_tags: Document has special Text Tags that RightSignature parse. true or false.
|
87
|
+
# More info: https://rightsignature.com/apidocs/text_tags
|
88
|
+
def send_document_from_file(file, subject, recipients, options={})
|
89
|
+
send_document(subject, recipients, {:type => "base64", :filename => File.basename(file), :value => Base64::encode64(File.read(file)) }, options)
|
90
|
+
end
|
91
|
+
|
92
|
+
# Creates a document from URL
|
93
|
+
# * url: URL to file
|
94
|
+
# * subject: subject of the document that'll appear in email
|
95
|
+
# * recipients: Recipients of the document, should be an array of hashes with :name, :email, and :role ('cc' or 'signer').
|
96
|
+
# An optional :is_sender (true/false) is used to referrence the API User and won't need to supply :name and :email
|
97
|
+
# Ex. CC to support@rightsignature.com, with sender and john@rightsignature.com as a signer
|
98
|
+
# [
|
99
|
+
# {:name => "RightSignature", :email => "support@rightsignature.com", :role => 'cc'},
|
100
|
+
# {:name => "John Bellingham", :email => "john@rightsignature.com", :role => 'signer'},
|
101
|
+
# {'is_sender' => true, :role => 'signer'},
|
102
|
+
# ]
|
103
|
+
# * options: other optional values
|
104
|
+
# - description: document description that'll appear in the email
|
105
|
+
# - action: 'send' or 'redirect'. Redirect will return a token that will allow another person to send the document under API user's account
|
106
|
+
# - expires_in: number of days before expiring the document. API only allows 2,5,15, or 30.
|
107
|
+
# - tags: document tags, an array of string or hashes 'single_tag' (for simple tag) or {'tag_name' => 'tag_value'} (for tuples pairs)
|
108
|
+
# Ex. ['sent_from_api', {"user_id" => "32"}]
|
109
|
+
# - 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.
|
110
|
+
# Ex. "http://yoursite/callback"
|
111
|
+
# - use_text_tags: Document has special Text Tags that RightSignature parse. true or false.
|
112
|
+
# More info: https://rightsignature.com/apidocs/text_tags
|
113
|
+
def send_document_from_url(url, subject, recipients, options={})
|
114
|
+
send_document(subject, recipients, {:type => "url", :filename => File.basename(url), :value => url }, options)
|
115
|
+
end
|
116
|
+
|
117
|
+
# Creates a document from a base64 encoded file or publicly available URL
|
118
|
+
# * document_data: hash of document source :type ('base64' or 'url'), :filename to be used, :value of source (url or base64 encoded binary)
|
119
|
+
# * subject: subject of the document that'll appear in email
|
120
|
+
# * recipients: Recipients of the document, should be an array of hashes with :name, :email, and :role ('cc' or 'signer').
|
121
|
+
# An optional :is_sender (true/false) is used to referrence the API User and won't need to supply :name and :email
|
122
|
+
# Ex. CC to support@rightsignature.com, with sender and john@rightsignature.com as a signer
|
123
|
+
# [
|
124
|
+
# {:name => "RightSignature", :email => "support@rightsignature.com", :role => 'cc'},
|
125
|
+
# {:name => "John Bellingham", :email => "john@rightsignature.com", :role => 'signer'},
|
126
|
+
# {'is_sender' => true, :role => 'signer'},
|
127
|
+
# ]
|
128
|
+
# * options: other optional values
|
129
|
+
# - description: document description that'll appear in the email
|
130
|
+
# - action: 'send' or 'redirect'. Redirect will return a token that will allow another person to send the document under API user's account
|
131
|
+
# - expires_in: number of days before expiring the document. API only allows 2,5,15, or 30.
|
132
|
+
# - tags: document tags, an array of string or hashes 'single_tag' (for simple tag) or {'tag_name' => 'tag_value'} (for tuples pairs)
|
133
|
+
# Ex. ['sent_from_api', {"user_id" => "32"}]
|
134
|
+
# - 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.
|
135
|
+
# Ex. "http://yoursite/callback"
|
136
|
+
# - use_text_tags: Document has special Text Tags that RightSignature parse. true or false.
|
137
|
+
# More info: https://rightsignature.com/apidocs/text_tags
|
138
|
+
# Ex.
|
139
|
+
# recipients = [
|
140
|
+
# {:name => "RightSignature", :email => "support@rightsignature.com", :role => 'cc'},
|
141
|
+
# {:name => "John Bellingham", :email => "john@rightsignature.com", :role => 'signer'},
|
142
|
+
# {'is_sender' => true, :role => 'signer'},
|
143
|
+
# ]
|
144
|
+
# document_data = {:type => 'base64', :filename => "originalfile.pdf", :value => Base64.encode64(File.read('myfile.pdf','r'))}
|
145
|
+
# options = {
|
146
|
+
# :tags => ['sent_from_api', 'user_id' => '12345'],
|
147
|
+
# :expires_in => '5 days',
|
148
|
+
# :action => "redirect",
|
149
|
+
# 'callback_location' => "http://example.com/doc_callback",
|
150
|
+
# 'use_text_tags' => false
|
151
|
+
# }
|
152
|
+
# RightSignature::send_document( "My Subject", recipients, document_data, options)
|
153
|
+
#
|
154
|
+
def send_document(subject, recipients, document_data, options={})
|
155
|
+
document_hash = {:document => {
|
156
|
+
:subject => subject,
|
157
|
+
:action => "send",
|
158
|
+
:document_data => document_data
|
159
|
+
}}
|
160
|
+
|
161
|
+
document_hash[:document][:recipients] = []
|
162
|
+
recipients.each do |recipient_hash|
|
163
|
+
document_hash[:document][:recipients] << { :recipient => recipient_hash}
|
164
|
+
end
|
165
|
+
|
166
|
+
document_hash[:document].merge!(options)
|
167
|
+
RightSignature::Connection.post "/api/documents.xml", document_hash
|
168
|
+
end
|
169
|
+
|
170
|
+
# Prefills a document from a base64 encoded file or publicly available URL and returns a url that allows someone to send as the API User
|
171
|
+
# * document_data: hash of document source :type ('base64' or 'url'), :filename to be used, :value of source (url or base64 encoded binary)
|
172
|
+
# * subject: subject of the document that'll appear in email
|
173
|
+
# * recipients: Recipients of the document, should be an array of hashes with :name, :email, and :role ('cc' or 'signer').
|
174
|
+
# An optional :is_sender (true/false) is used to referrence the API User and won't need to supply :name and :email
|
175
|
+
# Ex. CC to support@rightsignature.com, with sender and john@rightsignature.com as a signer
|
176
|
+
# [
|
177
|
+
# {:name => "RightSignature", :email => "support@rightsignature.com", :role => 'cc'},
|
178
|
+
# {:name => "John Bellingham", :email => "john@rightsignature.com", :role => 'signer'},
|
179
|
+
# {'is_sender' => true, :role => 'signer'},
|
180
|
+
# ]
|
181
|
+
# * options: other optional values
|
182
|
+
# - description: document description that'll appear in the email
|
183
|
+
# - action: 'send' or 'redirect'. Redirect will return a token that will allow another person to send the document under API user's account
|
184
|
+
# - expires_in: number of days before expiring the document. API only allows 2,5,15, or 30.
|
185
|
+
# - tags: document tags, an array of string or hashes 'single_tag' (for simple tag) or {'tag_name' => 'tag_value'} (for tuples pairs)
|
186
|
+
# Ex. ['sent_from_api', {"user_id" => "32"}]
|
187
|
+
# - 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.
|
188
|
+
# Ex. "http://yoursite/callback"
|
189
|
+
# - use_text_tags: Document has special Text Tags that RightSignature parse. true or false.
|
190
|
+
# More info: https://rightsignature.com/apidocs/text_tags
|
191
|
+
# Ex.
|
192
|
+
# recipients = [
|
193
|
+
# {:name => "RightSignature", :email => "support@rightsignature.com", :role => 'cc'},
|
194
|
+
# {:name => "John Bellingham", :email => "john@rightsignature.com", :role => 'signer'},
|
195
|
+
# {'is_sender' => true, :role => 'signer'},
|
196
|
+
# ]
|
197
|
+
# document_data = {:type => 'base64', :filename => "originalfile.pdf", :value => Base64.encode64(File.read('myfile.pdf','r'))}
|
198
|
+
# options = {
|
199
|
+
# :tags => ['sent_from_api', 'user_id' => '12345'],
|
200
|
+
# :expires_in => '5 days',
|
201
|
+
# :action => "redirect",
|
202
|
+
# 'callback_location' => "http://example.com/doc_callback",
|
203
|
+
# 'use_text_tags' => false
|
204
|
+
# }
|
205
|
+
# RightSignature::generate_document_redirect_url( "My Subject", recipients, document_data, options)
|
206
|
+
#
|
207
|
+
def generate_document_redirect_url(subject, recipients, document_data, options={})
|
208
|
+
options[:action] = "redirect"
|
209
|
+
response = send_document(subject, recipients, document_data, options)
|
210
|
+
|
211
|
+
"#{RightSignature::Connection.site}/builder/new?rt=#{response['document']['redirect_token']}"
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module RightSignature
|
2
|
+
class ResponseError < Exception
|
3
|
+
attr_reader :response
|
4
|
+
|
5
|
+
def initialize(response, message=nil)
|
6
|
+
self.set_backtrace(caller[1..-1]) if self.backtrace.nil?
|
7
|
+
@response = response
|
8
|
+
super((message || @response.message))
|
9
|
+
end
|
10
|
+
|
11
|
+
def code
|
12
|
+
@response.code
|
13
|
+
end
|
14
|
+
|
15
|
+
def common_solutions
|
16
|
+
if @response.code.to_i == 406
|
17
|
+
"Check the Content-Type and makes sure it's the correct type (usually application/json or application/xml), ensure url has .xml or .json at the end, check 'Accept' header to allow xml or json ('*/*' for anything)"
|
18
|
+
elsif @response.code.to_i == 401
|
19
|
+
"Check your credentials and make sure they are correct and not expired"
|
20
|
+
elsif @response.code.to_i >= 500 && @response.code.to_i < 600
|
21
|
+
"Check the format of your xml or json"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class TokenResponseError < Exception; end
|
27
|
+
class OAuthResponseError < Exception; end
|
28
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module RightSignature::Helpers
|
2
|
+
module TagsHelper
|
3
|
+
class <<self
|
4
|
+
def mixed_array_to_string_array(array_of_tags)
|
5
|
+
return array_of_tags unless array_of_tags.is_a?(Array)
|
6
|
+
|
7
|
+
tags = []
|
8
|
+
array_of_tags.each_with_index do |tag, idx|
|
9
|
+
if tag.is_a? Hash
|
10
|
+
tags << tag.first.join(':')
|
11
|
+
elsif tag.is_a? String
|
12
|
+
tags << tag
|
13
|
+
else
|
14
|
+
raise "Tags should be an array of Strings ('tag_name') or Hashes ({'tag_name' => 'value'})"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
tags.join(',')
|
19
|
+
end
|
20
|
+
|
21
|
+
def array_to_xml_hash(tags_array)
|
22
|
+
tags_array.map do |t|
|
23
|
+
if t.is_a? Hash
|
24
|
+
name, value = t.first
|
25
|
+
{:tag => {:name => name, :value => value}}
|
26
|
+
else
|
27
|
+
{:tag => {:name => t}}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
module RolesHelper
|
36
|
+
class <<self
|
37
|
+
# Converts [{"Role Name" => {:name => "John", :email => "email@example.com"}}] to
|
38
|
+
# [{:role => {:name => "John", :email => "email@example.com", "@role_name" => "Role Name"} }]
|
39
|
+
def array_to_xml_hash(roles_array)
|
40
|
+
roles_hash_array = []
|
41
|
+
roles_array.each do |role_hash|
|
42
|
+
name, value = role_hash.first
|
43
|
+
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
|
+
roles_hash_array << {:role => value.merge({"@role_name" => name})}
|
45
|
+
end
|
46
|
+
|
47
|
+
roles_hash_array
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
module MergeFieldsHelper
|
55
|
+
class <<self
|
56
|
+
# Converts [{"Role Name" => {:name => "John", :email => "email@example.com"}}] to
|
57
|
+
# [{"role roles_name=\"Role Name\"" => {:role => {:name => "John", :email => "email@example.com"}} }]
|
58
|
+
def array_to_xml_hash(merge_fields_array)
|
59
|
+
merge_fields = []
|
60
|
+
merge_fields_array.each do |merge_field_hash|
|
61
|
+
name, value = merge_field_hash.first
|
62
|
+
merge_fields << { :merge_field => {:value => value, "@merge_field_name" => name}}
|
63
|
+
end
|
64
|
+
|
65
|
+
merge_fields
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def array_to_acceptable_names_hash(acceptable_names)
|
72
|
+
converted_fields = []
|
73
|
+
acceptable_names.each do |name|
|
74
|
+
converted_fields << {:name => name}
|
75
|
+
end
|
76
|
+
|
77
|
+
converted_fields
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,177 @@
|
|
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
|
19
|
+
|
20
|
+
def details(guid)
|
21
|
+
RightSignature::Connection.get "/api/templates/#{guid}.xml", {}
|
22
|
+
end
|
23
|
+
|
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", {}
|
27
|
+
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
|
+
xml_hash[:template][:merge_fields] = MergeFieldsHelper.array_to_xml_hash(options[:merge_fields]) if options[:merge_fields]
|
84
|
+
xml_hash[:template][:tags] = TagsHelper.array_to_xml_hash(options[:tags]) if options[:tags]
|
85
|
+
[:expires_in, :description, :callback_url, :action].each do |other_option|
|
86
|
+
xml_hash[:template][other_option] = options[other_option] if options[other_option]
|
87
|
+
end
|
88
|
+
|
89
|
+
RightSignature::Connection.post "/api/templates.xml", xml_hash
|
90
|
+
end
|
91
|
+
|
92
|
+
def prepackage_and_send(guid, subject, roles, options={})
|
93
|
+
response = prepackage(guid)
|
94
|
+
new_guid = response["template"]["guid"]
|
95
|
+
send_template(new_guid, subject, roles, options)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Sends template.
|
99
|
+
# * guid: templates guid. Ex. a_1_zcfdidf8fi23
|
100
|
+
# * subject: subject of the document that'll appear in email
|
101
|
+
# * roles: Recipients of the document, should be an array of role names and emails in a hash with keys as role_names.
|
102
|
+
# Ex. [{"Employee" => {:name => "John Employee", :email => "john@employee.com"}}]
|
103
|
+
# is equivalent to
|
104
|
+
# <role role_name="Employee">
|
105
|
+
# <name>John Employee</name>
|
106
|
+
# <email>john@employee.com</email>
|
107
|
+
# </role>
|
108
|
+
# * options: other optional values
|
109
|
+
# - description: document description that'll appear in the email
|
110
|
+
# - merge_fields: document merge fields, should be an array of merge_field_values in a hash with the merge_field_name.
|
111
|
+
# Ex. [{"Salary" => "$1,000,000"}]
|
112
|
+
# is equivalent to
|
113
|
+
# <merge_field merge_field_name="Salary">
|
114
|
+
# <value>$1,000,000</value>
|
115
|
+
# </merge_field>
|
116
|
+
# - expires_in: number of days before expiring the document. API only allows 2,5,15, or 30.
|
117
|
+
# - tags: document tags, an array of {:name => 'tag_name'} (for simple tag) or {:name => 'tag_name', :value => 'value'} (for tuples pairs)
|
118
|
+
# Ex. [{:name => 'sent_from_api'}, {:name => "user_id", :value => "32"}]
|
119
|
+
# - 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.
|
120
|
+
# Ex. "http://yoursite/callback"
|
121
|
+
#
|
122
|
+
# Ex. call with all options used
|
123
|
+
# RightSignature::Template.prefill(
|
124
|
+
# "a_1_zcfdidf8fi23",
|
125
|
+
# "Your Employee Handbook",
|
126
|
+
# [{"employee" => {:name => "John Employee", :email => "john@employee.com"}}],
|
127
|
+
# {
|
128
|
+
# :description => "Please read over the handbook and sign it.",
|
129
|
+
# :merge_fields => [
|
130
|
+
# { "Department" => "Fun and games" },
|
131
|
+
# { "Salary" => "$1,000,000" }
|
132
|
+
# ],
|
133
|
+
# :expires_in => 5,
|
134
|
+
# :tags => [
|
135
|
+
# {:name => 'sent_from_api'},
|
136
|
+
# {:name => 'user_id', :value => '32'}
|
137
|
+
# ],
|
138
|
+
# :callback_url => "http://yoursite/callback"
|
139
|
+
# })
|
140
|
+
def send_template(guid, subject, roles, options={})
|
141
|
+
prefill(guid, subject, roles, options.merge({:action => 'send'}))
|
142
|
+
end
|
143
|
+
|
144
|
+
# Creates a URL that give person ability to create a template in your account.
|
145
|
+
# * options: optional options for redirected person
|
146
|
+
# - callback_location: URI encoded URL that specifies the location we will POST a callback notification to when the template has been created.
|
147
|
+
# - redirect_location: A URI encoded URL that specifies the location we will redirect the user to, after they have created a template.
|
148
|
+
# - tags: tags to add to the template. an array of 'tag_name' (for simple tag) or {'tag_name' => 'value'} (for tuples pairs)
|
149
|
+
# Ex. ['created_from_api', {"user_id" => "123"}]
|
150
|
+
# - acceptabled_role_names: The user creating the Template will be forced to select one of the values provided.
|
151
|
+
# There will be no free-form name entry when adding roles to the Template. An array of strings.
|
152
|
+
# Ex. ["Employee", "Employeer"]
|
153
|
+
# - acceptable_merge_field_names: The user creating the Template will be forced to select one of the values provided.
|
154
|
+
# There will be no free-form name entry when adding merge fields to the Template.
|
155
|
+
# Ex. ["Location", "Tax ID", "Company Name"]
|
156
|
+
def generate_build_url(options={})
|
157
|
+
xml_hash = {:template => {}}
|
158
|
+
xml_hash[:template][:tags] = TagsHelper.array_to_xml_hash(options[:tags]) if options[:tags]
|
159
|
+
|
160
|
+
[:acceptable_merge_field_names, :acceptabled_role_names].each do |option|
|
161
|
+
xml_hash[:template][option] = array_to_acceptable_names_hash(options[option]) if options[option]
|
162
|
+
end
|
163
|
+
|
164
|
+
[:callback_location, :redirect_location].each do |other_option|
|
165
|
+
xml_hash[:template][other_option] = options[other_option] if options[other_option]
|
166
|
+
end
|
167
|
+
|
168
|
+
response = RightSignature::Connection.post "/api/templates/generate_build_token.xml", xml_hash
|
169
|
+
|
170
|
+
redirect_token = response["token"]["redirect_token"]
|
171
|
+
|
172
|
+
"#{RightSignature::Connection.site}/builder/new?rt=#{redirect_token}"
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|