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,63 +1,73 @@
1
1
  module RightSignature
2
2
  class OauthConnection
3
+ attr_reader :request_token
4
+ attr_reader :consumer_key, :consumer_secret, :oauth_access_token, :oauth_access_secret
3
5
 
4
- class << self
5
- attr_reader :request_token
6
-
7
- def oauth_consumer
8
- check_credentials unless RightSignature::configuration[:consumer_key] && RightSignature::configuration[:consumer_secret]
9
- @oauth_consumer ||= OAuth::Consumer.new(
10
- RightSignature::configuration[:consumer_key],
11
- RightSignature::configuration[:consumer_secret],
12
- {
13
- :site => "https://rightsignature.com",
14
- :scheme => :header,
15
- :http_method => :post,
16
- :authorize_path =>'/oauth/authorize',
17
- :access_token_path =>'/oauth/access_token',
18
- :request_token_path=>'/oauth/request_token'
19
- }
20
- )
21
- end
22
-
23
- def access_token
24
- check_credentials
25
- @access_token = OAuth::AccessToken.new(oauth_consumer, RightSignature::configuration[:access_token], RightSignature::configuration[:access_secret])
26
- end
27
-
28
- def access_token
29
- check_credentials
30
- @access_token ||= OAuth::AccessToken.new(oauth_consumer, RightSignature::configuration[:access_token], RightSignature::configuration[:access_secret])
31
- end
32
-
33
- def set_access_token(access_token, access_secret)
34
- RightSignature::configuration[:access_token] = access_token
35
- RightSignature::configuration[:access_secret] = access_secret
36
- @access_token = OAuth::AccessToken.new(oauth_consumer, RightSignature::configuration[:access_token], RightSignature::configuration[:access_secret])
37
- end
38
-
39
- def new_request_token
40
- @request_token = RightSignature::OauthConnection.oauth_consumer.get_request_token
41
- end
42
-
43
- def generate_access_token(oauth_verifier)
44
- raise "Please set request token with new_request_token" unless @request_token
45
- @access_token = @request_token.get_access_token(:oauth_verifier => oauth_verifier)
46
- end
47
-
48
- def request(method, *options)
49
- options.last ||= {}
50
- options.last["Accept"] ||= "*/*"
51
- options.last["content-type"] ||= "application/xml"
6
+ def initialize(credentials={})
7
+ @consumer_key = credentials[:consumer_key]
8
+ @consumer_secret = credentials[:consumer_secret]
9
+ @oauth_access_token = credentials[:access_token]
10
+ @oauth_access_secret = credentials[:access_secret]
11
+ end
12
+
13
+ def oauth_consumer
14
+ check_credentials unless @consumer_key && @consumer_secret
15
+ @oauth_consumer ||= OAuth::Consumer.new(
16
+ @consumer_key,
17
+ @consumer_secret,
18
+ {
19
+ :site => "https://rightsignature.com",
20
+ :scheme => :header,
21
+ :http_method => :post,
22
+ :authorize_path =>'/oauth/authorize',
23
+ :access_token_path =>'/oauth/access_token',
24
+ :request_token_path=>'/oauth/request_token'
25
+ }
26
+ )
27
+ end
28
+
29
+ def access_token
30
+ check_credentials
31
+ @access_token ||= OAuth::AccessToken.new(oauth_consumer, @oauth_access_token, @oauth_access_secret)
32
+ end
33
+
34
+ def set_access_token(access_token, access_secret)
35
+ @oauth_access_token = access_token
36
+ @oauth_access_secret = access_secret
37
+ @access_token = OAuth::AccessToken.new(oauth_consumer, @oauth_access_token, @oauth_access_secret)
38
+ end
39
+
40
+ def new_request_token
41
+ @request_token = oauth_consumer.get_request_token
42
+ end
43
+
44
+ def generate_access_token(oauth_verifier)
45
+ raise "Please set request token with new_request_token" unless @request_token
46
+ @access_token = @request_token.get_access_token(:oauth_verifier => oauth_verifier)
47
+ @oauth_access_token = @access_token.token
48
+ @oauth_access_secret = @access_token.secret
49
+ @access_token
50
+ end
51
+
52
+ def request(method, *options)
53
+ options.last ||= {}
54
+ options.last["Accept"] ||= "*/*"
55
+ options.last["content-type"] ||= "application/xml"
52
56
 
53
- self.access_token.__send__(method, *options)
54
- end
55
-
56
- private
57
- def check_credentials
58
- raise "Please set load_configuration with #{RightSignature::oauth_keys.join(', ')}" unless RightSignature::has_oauth_credentials?
59
- end
57
+ self.access_token.__send__(method, *options)
60
58
  end
59
+
60
+ private
61
+ def check_credentials
62
+ raise "Please set #{RightSignature::Connection.oauth_keys.join(', ')}" unless has_oauth_credentials?
63
+ end
64
+
65
+ def has_oauth_credentials?
66
+ [@consumer_key, @consumer_secret, @oauth_access_token, @oauth_access_secret].each do |cred|
67
+ return false if cred.nil? || cred.match(/^\s*$/)
68
+ end
61
69
 
70
+ true
71
+ end
62
72
  end
63
73
  end
@@ -3,19 +3,24 @@ module RightSignature
3
3
  include HTTParty
4
4
  base_uri 'https://rightsignature.com'
5
5
  format :xml
6
+
7
+ attr_reader :api_token
6
8
 
7
- class <<self
8
- def request(method, url, options)
9
- raise "Please set load_configuration with #{RightSignature::api_token_keys.join(', ')}" unless RightSignature::has_api_token?
10
-
11
- options[:headers] ||= {}
12
- options[:headers]['api-token'] = RightSignature::configuration[:api_token]
13
- options[:headers]["Accept"] ||= "*/*"
14
- options[:headers]["content-type"] ||= "application/xml"
15
- __send__(method, url, options)
16
- end
17
-
9
+ def initialize(api_token)
10
+ @api_token = api_token
18
11
  end
12
+
19
13
 
14
+ def request(method, url, options)
15
+ raise "Please set api_token" if @api_token.nil? || @api_token.empty?
16
+
17
+ options[:headers] ||= {}
18
+ options[:headers]['api-token'] = @api_token
19
+ options[:headers]["Accept"] ||= "*/*"
20
+ options[:headers]["content-type"] ||= "application/xml"
21
+ __send__(method, url, options)
22
+ end
23
+
20
24
  end
25
+
21
26
  end
@@ -1,234 +1,231 @@
1
1
  module RightSignature
2
- class Document
3
- extend RightSignature::Helpers
2
+ module Document
3
+ include RightSignature::Helpers
4
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
5
+ def documents_list(options={})
6
+ options[:tags] = TagsHelper.mixed_array_to_string_array(options[:tags]) if options[:tags]
7
+ options[:state] = options[:state].join(',') if options[:state] && options[:state].is_a?(Array)
8
+ get "/api/documents.xml", options
9
+ end
10
+
11
+ def document_details(guid)
12
+ get "/api/documents/#{guid}.xml"
13
+ end
14
+
15
+ def documents_batch_details(guids)
16
+ get "/api/documents/#{guids.join(',')}/batch_details.xml"
17
+ end
18
+
19
+ def send_reminder(guid)
20
+ post "/api/documents/#{guid}/send_reminders.xml", {}
21
+ end
22
+
23
+ def trash_document(guid)
24
+ post "/api/documents/#{guid}/trash.xml", {}
25
+ end
28
26
 
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
27
+ def extend_document_expiration(guid)
28
+ post "/api/documents/#{guid}/extend_expiration.xml", {}
29
+ end
30
+
31
+ # This will REPLACE the tags on a document
32
+ # tags are an array of 'tag_name' or {'tag_name' => 'value'}
33
+ # Hash style:
34
+ # {:name => value}
35
+ def update_document_tags(guid, tags)
36
+ post "/api/documents/#{guid}/update_tags.xml", { :tags => TagsHelper.array_to_xml_hash(tags) }
37
+ end
38
+
39
+ # Creates a document from a raw data
40
+ # * file: file binary. Ex. File.read('myfile.pdf')
41
+ # * filename: original filename
42
+ # * subject: subject of the document that'll appear in email
43
+ # * recipients: Recipients of the document, should be an array of hashes with :name, :email, and :role ('cc' or 'signer').
44
+ # An optional :is_sender (true/false) is used to referrence the API User and won't need to supply :name and :email
45
+ # Ex. CC to support@rightsignature.com, with sender and john@rightsignature.com as a signer
46
+ # [
47
+ # {:name => "RightSignature", :email => "support@rightsignature.com", :role => 'cc'},
48
+ # {:name => "John Bellingham", :email => "john@rightsignature.com", :role => 'signer'},
49
+ # {'is_sender' => true, :role => 'signer'},
50
+ # ]
51
+ # * options: other optional values
52
+ # - description: document description that'll appear in the email
53
+ # - action: 'send' or 'redirect'. Redirect will return a token that will allow another person to send the document under API user's account
54
+ # - expires_in: number of days before expiring the document. API only allows 2,5,15, or 30.
55
+ # - tags: document tags, an array of string or hashes 'single_tag' (for simple tag) or {'tag_name' => 'tag_value'} (for tuples pairs)
56
+ # Ex. ['sent_from_api', {"user_id" => "32"}]
57
+ # - 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.
58
+ # Ex. "http://yoursite/callback"
59
+ # - use_text_tags: Document has special Text Tags that RightSignature parse. true or false.
60
+ # More info: https://rightsignature.com/apidocs/text_tags
61
+ def send_document_from_data(file_data, filename, subject, recipients, options={})
62
+ send_document(subject, recipients, {:type => "base64", :filename => filename, :value => Base64::encode64(file_data)}, options)
63
+ end
64
+
65
+ # Creates a document from a File or path to file
66
+ # * file: Path to file or File object
67
+ # * subject: subject of the document that'll appear in email
68
+ # * recipients: Recipients of the document, should be an array of hashes with :name, :email, and :role ('cc' or 'signer').
69
+ # An optional :is_sender (true/false) is used to referrence the API User and won't need to supply :name and :email
70
+ # Ex. CC to support@rightsignature.com, with sender and john@rightsignature.com as a signer
71
+ # [
72
+ # {:name => "RightSignature", :email => "support@rightsignature.com", :role => 'cc'},
73
+ # {:name => "John Bellingham", :email => "john@rightsignature.com", :role => 'signer'},
74
+ # {'is_sender' => true, :role => 'signer'},
75
+ # ]
76
+ # * options: other optional values
77
+ # - description: document description that'll appear in the email
78
+ # - action: 'send' or 'redirect'. Redirect will return a token that will allow another person to send the document under API user's account
79
+ # - expires_in: number of days before expiring the document. API only allows 2,5,15, or 30.
80
+ # - tags: document tags, an array of string or hashes 'single_tag' (for simple tag) or {'tag_name' => 'tag_value'} (for tuples pairs)
81
+ # Ex. ['sent_from_api', {"user_id" => "32"}]
82
+ # - 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.
83
+ # Ex. "http://yoursite/callback"
84
+ # - use_text_tags: Document has special Text Tags that RightSignature parse. true or false.
85
+ # More info: https://rightsignature.com/apidocs/text_tags
86
+ def send_document_from_file(file, subject, recipients, options={})
87
+ send_document(subject, recipients, {:type => "base64", :filename => File.basename(file), :value => Base64::encode64(File.read(file)) }, options)
88
+ end
89
+
90
+ # Creates a document from URL
91
+ # * url: URL to file
92
+ # * subject: subject of the document that'll appear in email
93
+ # * recipients: Recipients of the document, should be an array of hashes with :name, :email, and :role ('cc' or 'signer').
94
+ # An optional :is_sender (true/false) is used to referrence the API User and won't need to supply :name and :email
95
+ # Ex. CC to support@rightsignature.com, with sender and john@rightsignature.com as a signer
96
+ # [
97
+ # {:name => "RightSignature", :email => "support@rightsignature.com", :role => 'cc'},
98
+ # {:name => "John Bellingham", :email => "john@rightsignature.com", :role => 'signer'},
99
+ # {'is_sender' => true, :role => 'signer'},
100
+ # ]
101
+ # * options: other optional values
102
+ # - description: document description that'll appear in the email
103
+ # - action: 'send' or 'redirect'. Redirect will return a token that will allow another person to send the document under API user's account
104
+ # - expires_in: number of days before expiring the document. API only allows 2,5,15, or 30.
105
+ # - tags: document tags, an array of string or hashes 'single_tag' (for simple tag) or {'tag_name' => 'tag_value'} (for tuples pairs)
106
+ # Ex. ['sent_from_api', {"user_id" => "32"}]
107
+ # - 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.
108
+ # Ex. "http://yoursite/callback"
109
+ # - use_text_tags: Document has special Text Tags that RightSignature parse. true or false.
110
+ # More info: https://rightsignature.com/apidocs/text_tags
111
+ def send_document_from_url(url, subject, recipients, options={})
112
+ send_document(subject, recipients, {:type => "url", :filename => File.basename(url), :value => url }, options)
113
+ end
114
+
115
+ # Creates a document from a base64 encoded file or publicly available URL
116
+ # * document_data: hash of document source :type ('base64' or 'url'), :filename to be used, :value of source (url or base64 encoded binary)
117
+ # * subject: subject of the document that'll appear in email
118
+ # * recipients: Recipients of the document, should be an array of hashes with :name, :email, and :role ('cc' or 'signer').
119
+ # An optional :is_sender (true/false) is used to referrence the API User and won't need to supply :name and :email
120
+ # Ex. CC to support@rightsignature.com, with sender and john@rightsignature.com as a signer
121
+ # [
122
+ # {:name => "RightSignature", :email => "support@rightsignature.com", :role => 'cc'},
123
+ # {:name => "John Bellingham", :email => "john@rightsignature.com", :role => 'signer'},
124
+ # {'is_sender' => true, :role => 'signer'},
125
+ # ]
126
+ # * options: other optional values
127
+ # - description: document description that'll appear in the email
128
+ # - action: 'send' or 'redirect'. Redirect will return a token that will allow another person to send the document under API user's account
129
+ # - expires_in: number of days before expiring the document. API only allows 2,5,15, or 30.
130
+ # - tags: document tags, an array of string or hashes 'single_tag' (for simple tag) or {'tag_name' => 'tag_value'} (for tuples pairs)
131
+ # Ex. ['sent_from_api', {"user_id" => "32"}]
132
+ # - 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.
133
+ # Ex. "http://yoursite/callback"
134
+ # - use_text_tags: Document has special Text Tags that RightSignature parse. true or false.
135
+ # More info: https://rightsignature.com/apidocs/text_tags
136
+ # Ex.
137
+ # recipients = [
138
+ # {:name => "RightSignature", :email => "support@rightsignature.com", :role => 'cc'},
139
+ # {:name => "John Bellingham", :email => "john@rightsignature.com", :role => 'signer'},
140
+ # {'is_sender' => true, :role => 'signer'},
141
+ # ]
142
+ # document_data = {:type => 'base64', :filename => "originalfile.pdf", :value => Base64.encode64(File.read('myfile.pdf','r'))}
143
+ # options = {
144
+ # :tags => ['sent_from_api', 'user_id' => '12345'],
145
+ # :expires_in => '5 days',
146
+ # :action => "redirect",
147
+ # 'callback_location' => "http://example.com/doc_callback",
148
+ # 'use_text_tags' => false
149
+ # }
150
+ # RightSignature::send_document( "My Subject", recipients, document_data, options)
151
+ #
152
+ def send_document(subject, recipients, document_data, options={})
153
+ document_hash = {:document => {
154
+ :subject => subject,
155
+ :action => "send",
156
+ :document_data => document_data
157
+ }}
66
158
 
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)
159
+ document_hash[:document][:recipients] = []
160
+ recipients.each do |recipient_hash|
161
+ document_hash[:document][:recipients] << { :recipient => recipient_hash}
90
162
  end
91
163
 
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
164
+ document_hash[:document].merge!(options)
165
+ post "/api/documents.xml", document_hash
166
+ end
167
+
168
+ # 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
169
+ # * document_data: hash of document source :type ('base64' or 'url'), :filename to be used, :value of source (url or base64 encoded binary)
170
+ # * subject: subject of the document that'll appear in email
171
+ # * recipients: Recipients of the document, should be an array of hashes with :name, :email, and :role ('cc' or 'signer').
172
+ # An optional :is_sender (true/false) is used to referrence the API User and won't need to supply :name and :email
173
+ # Ex. CC to support@rightsignature.com, with sender and john@rightsignature.com as a signer
174
+ # [
175
+ # {:name => "RightSignature", :email => "support@rightsignature.com", :role => 'cc'},
176
+ # {:name => "John Bellingham", :email => "john@rightsignature.com", :role => 'signer'},
177
+ # {'is_sender' => true, :role => 'signer'},
178
+ # ]
179
+ # * options: other optional values
180
+ # - description: document description that'll appear in the email
181
+ # - action: 'send' or 'redirect'. Redirect will return a token that will allow another person to send the document under API user's account
182
+ # - expires_in: number of days before expiring the document. API only allows 2,5,15, or 30.
183
+ # - tags: document tags, an array of string or hashes 'single_tag' (for simple tag) or {'tag_name' => 'tag_value'} (for tuples pairs)
184
+ # Ex. ['sent_from_api', {"user_id" => "32"}]
185
+ # - 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.
186
+ # Ex. "http://yoursite/callback"
187
+ # - use_text_tags: Document has special Text Tags that RightSignature parse. true or false.
188
+ # More info: https://rightsignature.com/apidocs/text_tags
189
+ # Ex.
190
+ # recipients = [
191
+ # {:name => "RightSignature", :email => "support@rightsignature.com", :role => 'cc'},
192
+ # {:name => "John Bellingham", :email => "john@rightsignature.com", :role => 'signer'},
193
+ # {'is_sender' => true, :role => 'signer'},
194
+ # ]
195
+ # document_data = {:type => 'base64', :filename => "originalfile.pdf", :value => Base64.encode64(File.read('myfile.pdf','r'))}
196
+ # options = {
197
+ # :tags => ['sent_from_api', 'user_id' => '12345'],
198
+ # :expires_in => '5 days',
199
+ # :action => "redirect",
200
+ # 'callback_location' => "http://example.com/doc_callback",
201
+ # 'use_text_tags' => false
202
+ # }
203
+ # RightSignature::generate_document_redirect_url( "My Subject", recipients, document_data, options)
204
+ #
205
+ def generate_document_redirect_url(subject, recipients, document_data, options={})
206
+ options[:action] = "redirect"
207
+ response = send_document(subject, recipients, document_data, options)
116
208
 
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
209
+ "#{site}/builder/new?rt=#{response['document']['redirect_token']}"
210
+ end
211
+
212
+ def get_document_signer_links_for(guid, redirect_location = nil)
213
+ params = {}
214
+ params[:redirect_location] = URI.encode(redirect_location) if redirect_location
215
+ response = get "/api/documents/#{guid}/signer_links.xml", params
169
216
 
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
217
+ signer_links = []
213
218
 
214
- def get_signer_links_for(guid, redirect_location = nil)
215
- params = {}
216
- params[:redirect_location] = URI.encode(redirect_location) if redirect_location
217
- response = RightSignature::Connection.get "/api/documents/#{guid}/signer_links.xml", params
218
-
219
- signer_links = []
220
-
221
- if response["document"]["signer_links"]["signer_link"].is_a? Array
222
- response["document"]["signer_links"]["signer_link"].each do |signer_link|
223
- signer_links << {"name" => signer_link["name"], "url" => "#{RightSignature::Connection.site}/signatures/embedded?rt=#{signer_link["signer_token"]}"}
224
- end
225
- else
226
- signer_link = response["document"]["signer_links"]["signer_link"]
227
- signer_links << {"name" => signer_link["name"], "url" => "#{RightSignature::Connection.site}/signatures/embedded?rt=#{signer_link["signer_token"]}"}
219
+ if response["document"]["signer_links"]["signer_link"].is_a? Array
220
+ response["document"]["signer_links"]["signer_link"].each do |signer_link|
221
+ signer_links << {"name" => signer_link["name"], "url" => "#{site}/signatures/embedded?rt=#{signer_link["signer_token"]}"}
228
222
  end
229
- signer_links
223
+ else
224
+ signer_link = response["document"]["signer_links"]["signer_link"]
225
+ signer_links << {"name" => signer_link["name"], "url" => "#{site}/signatures/embedded?rt=#{signer_link["signer_token"]}"}
230
226
  end
231
-
227
+ signer_links
232
228
  end
229
+
233
230
  end
234
231
  end