rightsignature-railstyle 1.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d6dac84b987a3973b7100641164500f413f80746
4
+ data.tar.gz: 5e5f3de36c945c0ea489af01545306a2b20914a5
5
+ SHA512:
6
+ metadata.gz: e64eb512785e4a09a1be4448edd8111f50491d3ff3914f363ed50747d2c7d9c59e6dded30d5aaad5cbc60861789ae5b217dd91527234459d18b022d9fb1b6b9e
7
+ data.tar.gz: 840e1bcacf410f46eb61a661907ebb4f7a6b3cdd6b0316b11eb2a9c1f2676b581f28c0c6dba89757510d7b818507810d944ccf36014c041ad9963526ed7b1b76
@@ -0,0 +1,8 @@
1
+ .DS_Store
2
+ .rbenv-version
3
+ .rvmrc
4
+ *.swp
5
+ *.swo
6
+ *.gem
7
+ Gemfile.lock
8
+ pkg
@@ -0,0 +1,26 @@
1
+ Contributing
2
+ ------------
3
+ Awesome! Here are some guidelines:
4
+ * **Contributions will not be accepted without tests.**
5
+ * If you're creating a small fix or patch to an existing feature, just a simple
6
+ test will do. Please stay in the confines of the current test suite and use
7
+ [RSpec](https://github.com/rspec/rspec).
8
+ * If your contribution changes any behavior, make sure to update the
9
+ documentation.
10
+ * Please follow the [GitHub Ruby Styleguide](https://github.com/styleguide/ruby)
11
+ when modifying Ruby code.
12
+
13
+ Running the tests
14
+ -----------------
15
+ ```
16
+ rspec spec/*_spec.rb
17
+ ```
18
+
19
+ Basic Steps
20
+ -----------
21
+ * Fork it
22
+ * Create your feature branch (git checkout -b my-new-feature)
23
+ * Commit your changes (git commit -am 'Add some feature')
24
+ * Make sure the tests pass (rspec spec/*_spec.rb)
25
+ * Push to the branch (git push origin my-new-feature)
26
+ * Create new [Pull Request](https://help.github.com/articles/using-pull-requests)
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
@@ -0,0 +1,443 @@
1
+ RightSignature API
2
+ ==================
3
+ This gem is a wrapper to RightSignature's API for both OAuth authentication and Token authentication
4
+
5
+ #####Install
6
+ ```
7
+ gem install rightsignature
8
+ ```
9
+ or in your Gemfile
10
+ ```
11
+ gem 'rightsignature', '~> 1.0.0'
12
+ ```
13
+
14
+ Setup
15
+ -----
16
+ After getting an API key from RightSignature, you can use the Secure Token or generate an Access Token with the OAuth key and secret using RightSignature::Connection.new. Below are examples on how to use the gem as yourself.
17
+
18
+ #####Using Token authentication
19
+ ```
20
+ @rs_connection = RightSignature::Connection.new(:api_token => YOUR_TOKEN)
21
+ ```
22
+
23
+ #####Using OAuth authentication
24
+ ```
25
+ @rs_connection = RightSignature::Connection.new(
26
+ :consumer_key => "Consumer123",
27
+ :consumer_secret => "Secret098",
28
+ :access_token => "AccessToken098",
29
+ :access_secret => "AccessSecret123"
30
+ )
31
+ ```
32
+ Note: if the both OAuth credentials and api_token are set, the default action is to use Token Authentication.
33
+
34
+ #####Getting Access Token
35
+ Make sure you have a server that is can recieve the parameters from RightSignature and the callback is setup correctly in the RightSignature API settings (https://rightsignature.com/oauth_clients).
36
+ ```
37
+ request_token = @rs_connection.oauth_connection.new_request_token
38
+ ```
39
+
40
+ Now Visit the url generated from
41
+ ```
42
+ @rs_oauth = @rs_connection.oauth_connection
43
+ @rs_oauth.request_token.authorize_url
44
+ ```
45
+ and log into the site.
46
+
47
+ After approving the application, you will be redirected to the callback url that is in the RightSignature API settings (https://rightsignature.com/oauth_clients). The OAuth verifier should be in the params "oauth_verifier". Put the verifier in:
48
+ ```
49
+ @rs_oauth = @rs_connection.oauth_connection
50
+ @rs_oauth.generate_access_token(params[:oauth_verifer])
51
+ ```
52
+
53
+ Now, you should have your Connection setup. You can save the access token and access token secret for later use and skip the previous steps.
54
+ ```
55
+ @rs_oauth.access_token.token
56
+ @rs_oauth.access_token.secret
57
+ ```
58
+ Will give you the Access Token's token and secret.
59
+
60
+ You can also load the Access Token and Secret by calling
61
+ ```
62
+ @rs_oauth.set_access_token(token, secret)
63
+ ```
64
+
65
+ If you need to set the Request Token for the OAuth Consumer:
66
+ ```
67
+ @rs_oauth.set_request_token(token, secret)
68
+ ```
69
+
70
+ After loading the configuration, you can use wrappers in RightSignature::Connection to call the API, or use RightSignature::Connection for more custom calls.
71
+
72
+ Documents
73
+ ---------
74
+ #####Listing Document
75
+ For showing all documents
76
+ ```
77
+ @rs_connection.documents_list
78
+ ```
79
+
80
+ For showing page 1 of completed and trashed documents, with 20 per page, matching search term 'me', with tag "single_tag" and tag "key" with value of "with_value"
81
+ ```
82
+ options = {
83
+ :state => ['completed', 'trashed'],
84
+ :page => 1,
85
+ :per_page => 20,
86
+ :search => "me",
87
+ :tags => ["single_tag", "key" => "with_value"]
88
+ }
89
+ @rs_connection.documents_list(options)
90
+ ```
91
+ Optional Options:
92
+ * page: page number
93
+ * per_page: number of documents to return per page.
94
+ API only supports 10, 20, 30, 40, or 50. Default is 10.
95
+ * tags: filter documents with given tags. Tags are an array of strings (single tag) and hashes (tag_name => tag_value).
96
+ Ex. ["single_tag",{"tag_key" => "tag_value"}] would filter documents with 'single_tag' and the name/value of 'tag_key' with value 'tag_value'.
97
+ * search: filter documents with given term.
98
+ * state: An array of document states to filter documents by.
99
+ API supports 'pending', 'completed', 'trash', and 'pending'.
100
+ * sort: sort documents by given attribute.
101
+ API supports 'created', 'completed', and 'activity'
102
+ * range: return documents with a certain date range.
103
+ API only supports 'today', 'thisweek', 'thismonth', 'alltime', or a Date
104
+ * recipient_email: filter document where it has a recipient with given email and involves the current OAuth user.
105
+ * account: include all documents in current account if true. Should be true or false
106
+ Only available for account admins and owners.
107
+
108
+ #####Document Details
109
+ ```
110
+ @rs_connection.document_details(guid)
111
+ ```
112
+
113
+ #####Document Details for Multiple documents
114
+ ```
115
+ @rs_connection.documents_batch_details(guids)
116
+ ```
117
+ * guids: Array of document GUIDs
118
+
119
+ #####Send Reminder
120
+ ```
121
+ @rs_connection.send_reminder(guid)
122
+ ```
123
+
124
+ #####Trash Document
125
+ ```
126
+ @rs_connection.trash_document(guid)
127
+ ```
128
+
129
+ #####Extend Expiration of Document by 7 days
130
+ ```
131
+ @rs_connection.extend_document_expiration(guid)
132
+ ```
133
+
134
+ #####Replace Tags on Document
135
+ ```
136
+ tags=['sent_from_api', {'user_id' => '12345'}]
137
+ @rs_connection.update_document_tags(guid, tags)
138
+ ```
139
+ * guid
140
+ * tags: An array of 'tag_name' or {'tag_name' => 'tag_value'}
141
+
142
+ #####Sending New Documents
143
+ From file:
144
+ ```
145
+ recipients = [
146
+ {:name => "RightSignature", :email => "support@rightsignature.com", :role => 'cc'},
147
+ {:name => "John Bellingham", :email => "john@rightsignature.com", :role => 'signer'},
148
+ {'is_sender' => true, :role => 'signer'}
149
+ ]
150
+ options={
151
+ :tags => [{:tag => {:name => 'sent_from_api'}}, {:tag => {:name => 'user_id', :value => '12345'}}],
152
+ :expires_in => '5 days',
153
+ :action => "redirect",
154
+ 'callback_location' => "http://example.com/doc_callback",
155
+ 'use_text_tags' => false
156
+ }
157
+
158
+ @rs_connection.send_document_from_file("here/is/myfile.pdf", 'My Subject', recipients, options)
159
+ ```
160
+ Or
161
+ ```
162
+ @rs_connection.send_document_from_file(File.open("here/is/myfile.pdf", 'r'), 'My Subject', recipients)
163
+ ```
164
+ * subject: Document subject
165
+ * recipients: Recipients of the document, should be an array of hashes with :name, :email, and :role ('cc' or 'signer').
166
+ One recipient requires a :is_sender => true to reference the API User and doesn't need to supply :name and :email. Ex. {:is_sender => true, :role => "cc"}
167
+ * Optional options:
168
+ * description: document description that'll appear in the email
169
+ * action: 'send' or 'redirect'. Redirect will prefill the document and generate a redirect token that can be used on for someone to send document under API user's account.
170
+ * expires_in: number of days before expiring the document. API only allows 2,5,15, or 30.
171
+ * tags: document tags, an array of string or hashes 'single_tag' (for simple tag) or {'tag_name' => 'tag_value'} (for tuples pairs)
172
+ Ex. ['sent_from_api', {"user_id" => "32"}]
173
+ * callback_location: A URI encoded URL that specifies the location for API to POST a callback notification to when the document has been created and signed.
174
+ Ex. "http://yoursite/callback"
175
+ * use_text_tags: Parse document for special Text Tags. true or false.
176
+ More info: https://rightsignature.com/apidocs/text_tags
177
+
178
+ From raw data:
179
+ ```
180
+ recipients = [
181
+ {:name => "RightSignature", :email => "support@rightsignature.com", :role => 'cc'},
182
+ {:name => "John Bellingham", :email => "john@rightsignature.com", :role => 'signer'},
183
+ {'is_sender' => true, :role => 'signer'}
184
+ ]
185
+ raw_data = File.read("here/is/myfile.pdf")
186
+ filename = "Desired Filename.pdf"
187
+ @rs_connection.send_document_from_file(raw_data, filename, 'My Subject', recipients)
188
+ ```
189
+
190
+ #####Embedded Signing Links
191
+ Generates URLs for the embedded signing page for documents with recipients with email of 'noemail@rightsignature.com'.
192
+ Returns an array of {:name => "John Bellingham", "url" => "https://rightsignature.com/signatures/embedded?rt=1234"}
193
+ ```
194
+ @rs_connection.get_document_signer_links_for(guid, redirect_location=nil)
195
+ ```
196
+ Optional Option:
197
+ * redirect_location: URL to redirect user after signing.
198
+
199
+
200
+ Templates
201
+ ---------
202
+ #####Listing Templates
203
+ ```
204
+ @rs_connection.templates_list(options={})
205
+ ```
206
+ Optional Options:
207
+ * page: page number
208
+ * per_page: number of documents to return per page.
209
+ API only supports 10, 20, 30, 40, or 50. Default is 10.
210
+ * tags: filter documents with given tags. Tags are an array of strings, name and value in a name/value tag should be separated by colon (:).
211
+ Ex. ["single_tag","tag_key:tag_value"] would filter documents with 'single_tag' and the name/value of 'tag_key' with value 'tag_value'.
212
+ * search: filter documents with given term.
213
+
214
+ #####Template Details
215
+ ```
216
+ @rs_connection.template_details(guid)
217
+ ```
218
+
219
+ #####Prepackage and Send template
220
+ Most common use of API, clones a template and sends it for signature.
221
+ ```
222
+ @rs_connection.prepackage_and_send(guid, roles, options={})
223
+ ```
224
+ * guid: template guid to use. Should be a template that was prepackaged
225
+ * roles: recipient names in array of {:name => "Person's Name", :email => "Email"} hashed by Role ID. Ex. {"signer_A" => {:name => "Your Name", :email => "a@example.com"}}
226
+ Optional options:
227
+ * subject: document subject. Defaults to the subject in prepackage response.
228
+ * description: document description that'll appear in the email
229
+ * merge_fields: document merge fields, should be an array of merge_field_values in a hash with the merge_field_name.
230
+ Ex. [{"Salary" => "$1,000,000"}]
231
+ * expires_in: number of days before expiring the document. API only allows 2,5,15, or 30.
232
+ * tags: document tags, an array of string or hashes 'single_tag' (for simple tag) or {'tag_name' => 'tag_value'} (for tuples pairs)
233
+ Ex. ['sent_from_api', {"user_id" => "32"}]
234
+ * callback_location: A URI encoded URL that specifies the location for API to POST a callback notification to when the document has been created and signed.
235
+ Ex. "http://yoursite/callback"
236
+ * use_merge_field_ids: Using merge field ids instead of merge field name for merge_fields. true or false.
237
+
238
+ #####Template Prepacking
239
+ For cloning a Template before sending it.
240
+ ```
241
+ @rs_connection.prepackage(guid)
242
+ ```
243
+
244
+ #####Template Prefilling
245
+ After prepacking, the new template can be updated with prefill data. This won't send out the template as a document.
246
+ ```
247
+ @rs_connection.prefill(guid, subject, roles, options={})
248
+ ```
249
+ * guid: template guid to use. Should be a template that was prepackaged
250
+ * subject: document subject.
251
+ * roles: recipient names in array of {:name => "Person's Name", :email => "Email"} hashed by Role ID. Ex. {"signer_A" => {:name => "Your Name", :email => "a@example.com"}}
252
+ * Optional options:
253
+ * description: document description that'll appear in the email
254
+ * merge_fields: document merge fields, should be an array of merge_field_values in a hash with the merge_field_name.
255
+ Ex. [{"Salary" => "$1,000,000"}]
256
+ * expires_in: number of days before expiring the document. API only allows 2,5,15, or 30.
257
+ * tags: document tags, an array of string or hashes 'single_tag' (for simple tag) or {'tag_name' => 'tag_value'} (for tuples pairs)
258
+ Ex. ['sent_from_api', {"user_id" => "32"}]
259
+ * callback_location: A URI encoded URL that specifies the location for API to POST a callback notification to when the document has been created and signed.
260
+ Ex. "http://yoursite/callback"
261
+ * use_merge_field_ids: Using merge field ids instead of merge field name for merge_fields. true or false.
262
+
263
+ ```
264
+ options = {
265
+ :description => "Please read over the handbook and sign it.",
266
+ :merge_fields => [
267
+ { "Department" => "Fun and games" },
268
+ { "Salary" => "$1,000,000" }
269
+ ],
270
+ :expires_in => 5,
271
+ :tags => [
272
+ {:name => 'sent_from_api'},
273
+ {:name => 'user_id', :value => '32'}
274
+ ],
275
+ :callback_location => "http://yoursite/callback"
276
+ }
277
+ @rs_connection.prefill(guid, subject, roles, options)
278
+ ```
279
+
280
+
281
+ #####Template Sending
282
+ Send template as a document for signing. Same options as prefill.
283
+ ```
284
+ @rs_connection.send_template(guid, subject, roles, options={})
285
+ ```
286
+ * guid: template guid to use. Should be a template that was prepackaged
287
+ * subject: document subject.
288
+ * roles: recipient names in array of {:name => "Person's Name", :email => "Email"} hashed by Role ID. Ex. {"signer_A" => {:name => "Your Name", :email => "a@example.com"}}
289
+ * Optional options:
290
+ * description: document description that'll appear in the email
291
+ * merge_fields: document merge fields, should be an array of merge_field_values in a hash with the merge_field_name.
292
+ Ex. [{"Salary" => "$1,000,000"}]
293
+ * expires_in: number of days before expiring the document. API only allows 2,5,15, or 30.
294
+ * tags: document tags, an array of string or hashes 'single_tag' (for simple tag) or {'tag_name' => 'tag_value'} (for tuples pairs)
295
+ Ex. ['sent_from_api', {"user_id" => "32"}]
296
+ * callback_location: A URI encoded URL that specifies the location for API to POST a callback notification to when the document has been created and signed.
297
+ Ex. "http://yoursite/callback"
298
+ * use_merge_field_ids: Using merge field ids instead of merge field name for merge_fields. true or false.
299
+
300
+ ```
301
+ options = {
302
+ :description => "Please read over the handbook and sign it.",
303
+ :merge_fields => [
304
+ { "Department" => "Fun and games" },
305
+ { "Salary" => "$1,000,000" }
306
+ ],
307
+ :expires_in => 5,
308
+ :tags => [
309
+ {:name => 'sent_from_api'},
310
+ {:name => 'user_id', :value => '32'}
311
+ ],
312
+ :callback_location => "http://yoursite/callback"
313
+ }
314
+ @rs_connection.send_template(guid, subject, roles, options)
315
+ ```
316
+
317
+ #####Embedded Signing Links for Sent Template
318
+ Prepackages a template, and sends it out with each recipients marked as a embedded signer (email as noemail@rightsignature.com), then generates embedded signing URLs.
319
+ Returns an array of {:name => "John Bellingham", "url" => "https://rightsignature.com/signatures/embedded?rt=1234"}
320
+ ```
321
+ @rs_connection.send_as_embedded_signers(guid, recipients, options={})
322
+ ```
323
+ * guid: guid of template to create document with
324
+ * recipient: recipient names in array of {:name => "Person's Name"} hashed by Role ID. Ex. {"signer_A" => {:name => "Your Name"}}
325
+ * options:
326
+ * subject: document subject that'll appear in the email
327
+ * description: document description that'll appear in the email
328
+ * merge_fields: document merge fields, should be an array of merge_field_values in a hash with the merge_field_name.
329
+ Ex. [{"Salary" => "$1,000,000"}]
330
+ * expires_in: number of days before expiring the document. API only allows 2,5,15, or 30.
331
+ * tags: document tags, an array of string or hashes 'single_tag' (for simple tag) or {'tag_name' => 'tag_value'} (for tuples pairs)
332
+ Ex. ['sent_from_api', {"user_id" => "32"}]
333
+ * callback_location: A URI encoded URL that specifies the location for API to POST a callback notification to when the document has been created and signed.
334
+ Ex. "http://yoursite/callback"
335
+ * redirect_location: URL to redirect users after signing.
336
+ * use_merge_field_ids: Using merge field ids instead of merge field name for merge_fields. true or false.
337
+
338
+ #####Create New Template Link
339
+ Generate a url that let's someone upload and create a template under OAuth user's account.
340
+ ```
341
+ @rs_connection.generate_build_url
342
+ ```
343
+
344
+ You can also add restrictions to what the person can do:
345
+ * callback_location: URI encoded URL that specifies the location we will POST a callback notification to when the template has been created.
346
+ * redirect_location: A URI encoded URL that specifies the location we will redirect the user to, after they have created a template.
347
+ * tags: tags to add to the template. an array of strings (for simple tag) or hashes like {'tag_name' => 'tag_value'} (for tuples pairs)
348
+ Ex. ['created_from_api', {"user_id" => "123"}]
349
+ * acceptable_role_names: The user creating the Template will be forced to select one of the values provided.
350
+ There will be no free-form name entry when adding roles to the Template. An array of strings.
351
+ Ex. ["Employee", "Employeer"]
352
+ * acceptable_merge_field_names: The user creating the Template will be forced to select one of the values provided.
353
+ There will be no free-form name entry when adding merge fields to the Template.
354
+ Ex. ["Location", "Tax ID", "Company Name"]
355
+
356
+ ```
357
+ options = {
358
+ :acceptable_merge_field_names =>
359
+ [
360
+ "Site ID",
361
+ "Starting City"
362
+ ],
363
+ :acceptable_role_names =>
364
+ [
365
+ "Http Monster",
366
+ "Party Monster"
367
+ ],
368
+ :callback_location => "http://example.com/done_signing",
369
+ :redirect_location => "http://example.com/come_back_here"
370
+ }
371
+ @rs_connection.generate_build_url(options)
372
+ ```
373
+
374
+
375
+ Account
376
+ ---------
377
+ API calls involving API user's account.
378
+
379
+ #####User Details
380
+ ```
381
+ @rs_connection.user_details
382
+ ```
383
+
384
+ #####Add User to Account
385
+ ```
386
+ @rs_connection.add_user(name, email)
387
+ ```
388
+
389
+ #####Usage Report
390
+ Returns number of documents sent. Can scope to week, month, or day and count only signed, unsigned, or all documents.
391
+ ```
392
+ @rs_connection.usage_report(since=nil, signed=nil)
393
+ ```
394
+ * since: Only count documents sent withing the 'week', 'month', or 'day'.
395
+ * signed: Only count signed documents if 'true', else all documents
396
+
397
+ Custom API calls using RightSignature::Connection
398
+ -------------------------------------------------
399
+
400
+ In case there are new API paths, RightSignature::Connection allows a specific path to be specified.
401
+ #####Ex. GET https://rightsignature.com/api/documents.xml
402
+ ```
403
+ @rs_connection.get('/api/documents.xml', {:my => 'params'}, {'custom_header' => 'headerValue'})
404
+ ```
405
+
406
+ #####Ex. POST https://rightsignature.com/api/documents.xml
407
+ ```
408
+ request_hash= {
409
+ :document => {
410
+ :subject => "Your Form",
411
+ 'document_data' => {:type => 'url', :value => 'http://localhost:3000/sub.pdf' }
412
+ }
413
+ }
414
+ @rs_connection.post('/api/documents.xml', request_hash, {'custom_header' => 'headerValue'})
415
+ ```
416
+
417
+ Getting API Error Messages
418
+ --------------------------
419
+ If a request does not return a success response (200), a RightSignature::ResponseError is raised. You can rescue the error and inspect the response object or call detailed_message. detailed_message only returns if the response from the server contains an error message in the XML.
420
+ #####Ex. Trying to parse the error message response from API
421
+ ```
422
+ begin
423
+ @rs_connection.post('/api/documents.xml', {:bad => 'params'})
424
+ rescue RightSignature::ResponseError => error
425
+ puts error.detailed_message
426
+ end
427
+ ```
428
+
429
+ #####Ex. Trying to inspect the response object for more information
430
+ ```
431
+ begin
432
+ @rs_connection.post('/api/documents.xml', {:bad => 'params'})
433
+ rescue RightSignature::ResponseError => error
434
+ puts error.response.inspect
435
+ end
436
+ ```
437
+
438
+ Development Notes
439
+ -----------------
440
+ To load in irb from project root:
441
+ ```
442
+ $:.push File.expand_path("../lib", __FILE__); require "rightsignature"; RightSignature::Connection.new(MY_KEYS)
443
+ ```