rightsignature 0.1.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.
- 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,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rightsignature/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rightsignature"
|
7
|
+
s.version = RightSignature::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Alex Chee", "Geoff Ereth", "Cary Dunn"]
|
10
|
+
s.email = ["dev@rightsignature.com"]
|
11
|
+
s.homepage = "http://github.com/alexchee/rightsignature-api"
|
12
|
+
s.summary = "API wrapper for RightSignature"
|
13
|
+
s.description = "Provides a wrapper for the RightSignature API."
|
14
|
+
|
15
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
16
|
+
s.add_development_dependency "rspec", ">= 2.11.0"
|
17
|
+
|
18
|
+
s.add_dependency "bundler", ">= 1.0.0"
|
19
|
+
s.add_dependency "oauth", "= 0.4.3"
|
20
|
+
s.add_dependency "httparty", ">= 0.9.0"
|
21
|
+
s.add_dependency 'xml-fu', '>= 0.1.7'
|
22
|
+
|
23
|
+
s.files = `git ls-files`.split("\n")
|
24
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
25
|
+
s.require_path = 'lib'
|
26
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe RightSignature::TokenConnection do
|
4
|
+
it "should create 'api-token' to headers with :api_token credentials, accept of '*/*', and content-type of xml with given method" do
|
5
|
+
RightSignature::TokenConnection.should_receive(:get).with("path", {:query => {:search => 'hey there'}, :headers => {"api-token" => "APITOKEN", "Accept" => "*/*", "content-type" => "application/xml"}}).and_return(stub("HTTPartyResponse", :parsed_response => nil))
|
6
|
+
RightSignature::TokenConnection.request(:get, "path", {:query => {:search => 'hey there'}})
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should add 'api-token' to headers with :api_token credentials, accept of '*/*', and content-type of xml with given method" do
|
10
|
+
RightSignature::TokenConnection.should_receive(:get).with("path", {:query => {:search => 'hey there'}, :headers => {"api-token" => "APITOKEN", "Accept" => "*/*", "content-type" => "application/xml", :my_header => "someHeader"}}).and_return(stub("HTTPartyResponse", :parsed_response => nil))
|
11
|
+
RightSignature::TokenConnection.request(:get, "path", {:query => {:search => 'hey there'}, :headers => {:my_header => "someHeader"}})
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should create 'api-token' to headers with :api_token credentials, accept of '*/*', and content-type of xml to POST method" do
|
15
|
+
RightSignature::TokenConnection.should_receive(:post).with("path", {:body => {:document => {:roles => []}}, :headers => {"api-token" => "APITOKEN", "Accept" => "*/*", "content-type" => "application/xml"}}).and_return(stub("HTTPartyResponse", :parsed_response => nil))
|
16
|
+
RightSignature::TokenConnection.request(:post, "path", {:body => {:document => {:roles => []}}})
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../lib/rightsignature'
|
2
|
+
|
3
|
+
describe RightSignature::configuration do
|
4
|
+
describe "load_configuration" do
|
5
|
+
it "should load api_token into configurations[:api_token]" do
|
6
|
+
RightSignature::load_configuration(:api_token => "MyToken")
|
7
|
+
RightSignature::configuration[:api_token].should == "MyToken"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should load OAuth consumer key, consumer secret, access token and access secret" do
|
11
|
+
RightSignature::load_configuration(:consumer_key => "key", :consumer_secret => "secret", :access_token => "atoken", :access_secret => "asecret")
|
12
|
+
RightSignature::configuration[:consumer_key].should == "key"
|
13
|
+
RightSignature::configuration[:consumer_secret].should == "secret"
|
14
|
+
RightSignature::configuration[:access_token].should == "atoken"
|
15
|
+
RightSignature::configuration[:access_secret].should == "asecret"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "check_credentials" do
|
20
|
+
it "should raise error if configuration is not set" do
|
21
|
+
RightSignature::load_configuration()
|
22
|
+
lambda {RightSignature::check_credentials}.should raise_error
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should raise error if api_token is blank and oauth credentials are not set" do
|
26
|
+
RightSignature::load_configuration(:api_token => " ")
|
27
|
+
lambda {RightSignature::check_credentials}.should raise_error
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should raise error if consumer_key, consumer_secret, access_token, or access_secret is not set" do
|
31
|
+
RightSignature::load_configuration(:consumer_secret => "secret", :access_token => "atoken", :access_secret => "asecret")
|
32
|
+
lambda {RightSignature::check_credentials}.should raise_error
|
33
|
+
|
34
|
+
RightSignature::load_configuration(:consumer_key => "key", :access_token => "atoken", :access_secret => "asecret")
|
35
|
+
lambda {RightSignature::check_credentials}.should raise_error
|
36
|
+
|
37
|
+
RightSignature::load_configuration(:consumer_key => "key", :consumer_secret => "secret", :access_secret => "asecret")
|
38
|
+
lambda {RightSignature::check_credentials}.should raise_error
|
39
|
+
|
40
|
+
RightSignature::load_configuration(:consumer_key => "key", :consumer_secret => "secret", :access_token => "atoken")
|
41
|
+
lambda {RightSignature::check_credentials}.should raise_error
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should not raise error if consumer_key, consumer_secret, access_token, and access_secret is set" do
|
45
|
+
RightSignature::load_configuration(:consumer_key => "key", :consumer_secret => "secret", :access_token => "atoken", :access_secret => "asecret")
|
46
|
+
RightSignature::check_credentials
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should not raise error if api_token is set" do
|
50
|
+
RightSignature::load_configuration(:api_token => "asdf")
|
51
|
+
RightSignature::check_credentials
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "has_api_token?" do
|
56
|
+
it "should be false if configuration is not set" do
|
57
|
+
RightSignature::load_configuration()
|
58
|
+
RightSignature::has_api_token?.should be_false
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should be false if api_token is blank" do
|
62
|
+
RightSignature::load_configuration(:api_token => " ")
|
63
|
+
RightSignature::has_api_token?.should be_false
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should be true if api_token is set" do
|
67
|
+
RightSignature::load_configuration(:api_token => "abc")
|
68
|
+
RightSignature::has_api_token?.should be_true
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "has_oauth_credentials?" do
|
74
|
+
it "should be false if configuration is not set" do
|
75
|
+
RightSignature::load_configuration()
|
76
|
+
RightSignature::has_oauth_credentials?.should be_false
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should be false if consumer_key, consumer_secret, access_token, or access_secret is not set" do
|
80
|
+
RightSignature::load_configuration(:consumer_secret => "secret", :access_token => "atoken", :access_secret => "asecret")
|
81
|
+
RightSignature::has_oauth_credentials?.should be_false
|
82
|
+
|
83
|
+
RightSignature::load_configuration(:consumer_key => "key", :access_token => "atoken", :access_secret => "asecret")
|
84
|
+
RightSignature::has_oauth_credentials?.should be_false
|
85
|
+
|
86
|
+
RightSignature::load_configuration(:consumer_key => "key", :consumer_secret => "secret", :access_secret => "asecret")
|
87
|
+
RightSignature::has_oauth_credentials?.should be_false
|
88
|
+
|
89
|
+
RightSignature::load_configuration(:consumer_key => "key", :consumer_secret => "secret", :access_token => "atoken")
|
90
|
+
RightSignature::has_oauth_credentials?.should be_false
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should be true if consumer_key, consumer_secret, access_token, and access_secret is set" do
|
94
|
+
RightSignature::load_configuration(:consumer_key => "key", :consumer_secret => "secret", :access_token => "atoken", :access_secret => "asecret")
|
95
|
+
RightSignature::has_oauth_credentials?.should be_true
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../lib/rightsignature'
|
2
|
+
|
3
|
+
describe RightSignature::Connection do
|
4
|
+
describe "GET" do
|
5
|
+
describe "connection method" do
|
6
|
+
it "should default to RightSignature::OauthConnection if no api_token was specified" do
|
7
|
+
RightSignature::configuration = {:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"}
|
8
|
+
RightSignature::OauthConnection.should_receive(:request).and_return(stub('Response', :body => ''))
|
9
|
+
RightSignature::Connection.get("/path")
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should use RightSignature::TokenConnection if api_token was specified" do
|
13
|
+
RightSignature::configuration = {:api_token => "APITOKEN", :consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"}
|
14
|
+
RightSignature::TokenConnection.should_receive(:request).and_return(stub('Response', :parsed_response => {}))
|
15
|
+
RightSignature::Connection.get("/path")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should use RightSignature::TokenConnection if only api_token was specified" do
|
19
|
+
RightSignature::configuration = {:api_token => "APITOKEN"}
|
20
|
+
RightSignature::TokenConnection.should_receive(:request).and_return(stub('Response', :parsed_response => {}))
|
21
|
+
RightSignature::Connection.get("/path")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should raise error if no configuration is set" do
|
26
|
+
RightSignature::configuration = nil
|
27
|
+
lambda{RightSignature::Connection.get("/path")}.should raise_error
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "using OauthConnection" do
|
31
|
+
it "should append params into path alphabetically and URI escaped" do
|
32
|
+
RightSignature::configuration = {:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"}
|
33
|
+
RightSignature::OauthConnection.should_receive(:request).with(:get, "/path?page=1&q=search%20me", {}).and_return(stub('Response', :body => '<document><subject>My Subject</subject></document>'))
|
34
|
+
RightSignature::Connection.get("/path", {:q => 'search me', :page => 1})
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return converted response body from XML to hash" do
|
38
|
+
RightSignature::configuration = {:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"}
|
39
|
+
RightSignature::OauthConnection.stub(:request).and_return(stub('Response', :body => '<document><subject>My Subject</subject></document>'))
|
40
|
+
RightSignature::Connection.get("/path", {:q => 'search me', :page => 1}).should == {'document' => {'subject' => "My Subject"}}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "using TokenConnection" do
|
45
|
+
it "should append params and header into query option and header option" do
|
46
|
+
RightSignature::configuration = {:api_token => 'token'}
|
47
|
+
RightSignature::TokenConnection.should_receive(:request).with(:get, "/path", {:query => {:q => 'search me', :page => 1}, :headers => {"User-Agent" => "me"}}).and_return(stub('Response', :parsed_response => {}))
|
48
|
+
RightSignature::Connection.get("/path", {:q => 'search me', :page => 1}, {"User-Agent" => "me"})
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should return converted parsed_response from response" do
|
52
|
+
RightSignature::configuration = {:api_token => 'token'}
|
53
|
+
RightSignature::TokenConnection.stub(:request).and_return(stub('Response', :parsed_response => {'document' => {'subject' => "My Subject"}}))
|
54
|
+
RightSignature::Connection.get("/path", {:q => 'search me', :page => 1}).should == {'document' => {'subject' => "My Subject"}}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "POST" do
|
60
|
+
describe "connection method" do
|
61
|
+
before do
|
62
|
+
@net_http_response = Net::HTTPOK.new('1.1', 200, 'OK')
|
63
|
+
@net_http_response.stub(:body =>"{}", :body => '')
|
64
|
+
@httparty_response = stub("HTTPartyResponse", :parsed_response => nil, :body => '', :success? => true)
|
65
|
+
RightSignature::TokenConnection.stub(:request => @net_http_response)
|
66
|
+
RightSignature::OauthConnection.stub(:request => @httparty_response)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should default to RightSignature::OauthConnection if no api_token was specified" do
|
70
|
+
RightSignature::configuration = {:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"}
|
71
|
+
RightSignature::OauthConnection.should_receive(:request).and_return(@net_http_response)
|
72
|
+
RightSignature::Connection.post("/path")
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should default to RightSignature::TokenConnection if api_token was specified" do
|
76
|
+
RightSignature::configuration = {:api_token => "APITOKEN", :consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"}
|
77
|
+
RightSignature::TokenConnection.should_receive(:request).and_return(@httparty_response)
|
78
|
+
RightSignature::Connection.post("/path")
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should default to RightSignature::TokenConnection if only api_token was specified" do
|
82
|
+
RightSignature::configuration = {:api_token => "APITOKEN"}
|
83
|
+
RightSignature::TokenConnection.should_receive(:request).and_return(@httparty_response)
|
84
|
+
RightSignature::Connection.post("/path")
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should raise error if no configuration is set" do
|
88
|
+
RightSignature::configuration = nil
|
89
|
+
lambda{RightSignature::Connection.post("/path")}.should raise_error
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,256 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe RightSignature::Document do
|
4
|
+
describe "list" do
|
5
|
+
it "should GET /documents.xml" do
|
6
|
+
RightSignature::Connection.should_receive(:get).with('/api/documents.xml', {})
|
7
|
+
RightSignature::Document.list
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should pass search options to /api/templates.xml" do
|
11
|
+
RightSignature::Connection.should_receive(:get).with('/api/documents.xml', {:search => "search", :page => 2})
|
12
|
+
RightSignature::Document.list(:search => "search", :page => 2)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should convert array in options :tags into a string" do
|
16
|
+
RightSignature::Connection.should_receive(:get).with('/api/documents.xml', {:tags => "hello,what_is:up"})
|
17
|
+
RightSignature::Document.list(:tags => ['hello', {'what_is' => "up"}])
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should convert array of options :state into a string" do
|
21
|
+
RightSignature::Connection.should_receive(:get).with('/api/documents.xml', {:state => 'pending,trashed'})
|
22
|
+
RightSignature::Document.list(:state => ['pending', 'trashed'])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "details" do
|
27
|
+
it "should GET /api/documentsMYGUID.xml" do
|
28
|
+
RightSignature::Connection.should_receive(:get).with('/api/documents/MYGUID.xml')
|
29
|
+
RightSignature::Document.details('MYGUID')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "details" do
|
34
|
+
it "should GET /api/documentsMYGUID.xml" do
|
35
|
+
RightSignature::Connection.should_receive(:get).with('/api/documents/MYGUID.xml')
|
36
|
+
RightSignature::Document.details('MYGUID')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "batch_details" do
|
41
|
+
it "should GET /api/documentsMYGUID1,MYGUID2.xml" do
|
42
|
+
RightSignature::Connection.should_receive(:get).with('/api/documents/MYGUID1,MYGUID2/batch_details.xml')
|
43
|
+
RightSignature::Document.batch_details(['MYGUID1','MYGUID2'])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "send_reminder" do
|
48
|
+
it "should POST /api/documentsMYGUID/send_reminders.xml" do
|
49
|
+
RightSignature::Connection.should_receive(:post).with('/api/documents/MYGUID/send_reminders.xml', {})
|
50
|
+
RightSignature::Document.send_reminder('MYGUID')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "trash" do
|
55
|
+
it "should POST /api/documents/MYGUID/trash.xml" do
|
56
|
+
RightSignature::Connection.should_receive(:post).with('/api/documents/MYGUID/trash.xml', {})
|
57
|
+
RightSignature::Document.trash('MYGUID')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "extend_expiration" do
|
62
|
+
it "should POST /api/documents/MYGUID/extend_expiration.xml" do
|
63
|
+
RightSignature::Connection.should_receive(:post).with('/api/documents/MYGUID/extend_expiration.xml', {})
|
64
|
+
RightSignature::Document.extend_expiration('MYGUID')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "update_tags" do
|
69
|
+
it "should POST /api/documents/MYGUID/update_tags.xml" do
|
70
|
+
RightSignature::Connection.should_receive(:post).with('/api/documents/MYGUID/update_tags.xml', {:tags => []})
|
71
|
+
RightSignature::Document.update_tags('MYGUID', [])
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should normalize tags array into expected hash format" do
|
75
|
+
RightSignature::Connection.should_receive(:post).with('/api/documents/MYGUID/update_tags.xml', {
|
76
|
+
:tags => [{:tag => {:name => 'myNewOne'}}, {:tag => {:name => 'should_replace', :value => 'the_old_new'}}]
|
77
|
+
})
|
78
|
+
RightSignature::Document.update_tags('MYGUID', ["myNewOne", {"should_replace" => "the_old_new"}])
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should allow empty tags array" do
|
82
|
+
RightSignature::Connection.should_receive(:post).with('/api/documents/MYGUID/update_tags.xml', {
|
83
|
+
:tags => []
|
84
|
+
})
|
85
|
+
RightSignature::Document.update_tags('MYGUID', [])
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "send_document" do
|
90
|
+
it "should POST /api/documents.xml with document hash containing given subject, document data, recipients, and action of 'send'" do
|
91
|
+
RightSignature::Connection.should_receive(:post).with("/api/documents.xml", {
|
92
|
+
:document => {
|
93
|
+
:subject => "subby",
|
94
|
+
:document_data => {:type => 'base64', :filename => "originalfile.pdf", :value => "mOio90cv"},
|
95
|
+
:recipients => [],
|
96
|
+
:action => "send"
|
97
|
+
}
|
98
|
+
})
|
99
|
+
document_data = {:type => 'base64', :filename => "originalfile.pdf", :value => "mOio90cv"}
|
100
|
+
RightSignature::Document.send_document("subby", [], document_data)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should POST /api/documents.xml should convert recipients into normalized format" do
|
104
|
+
RightSignature::Connection.should_receive(:post).with("/api/documents.xml", {
|
105
|
+
:document => {
|
106
|
+
:subject => "subby",
|
107
|
+
:document_data => {:type => 'base64', :filename => "originalfile.pdf", :value => "mOio90cv"},
|
108
|
+
:recipients => [
|
109
|
+
{:recipient => {:name => "Signy Sign", :email => "signy@example.com", :role => "signer"}},
|
110
|
+
{:recipient =>{:name => "Cee Cee", :email => "ccme@example.com", :role => "cc"}}
|
111
|
+
],
|
112
|
+
:action => "send"
|
113
|
+
}
|
114
|
+
})
|
115
|
+
document_data = {:type => 'base64', :filename => "originalfile.pdf", :value => "mOio90cv"}
|
116
|
+
recipients = [{:name => "Signy Sign", :email => "signy@example.com", :role => "signer"}, {:name => "Cee Cee", :email => "ccme@example.com", :role => "cc"}]
|
117
|
+
|
118
|
+
RightSignature::Document.send_document("subby", recipients, document_data)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should POST /api/documents.xml with options" do
|
122
|
+
RightSignature::Connection.should_receive(:post).with("/api/documents.xml", {
|
123
|
+
:document => {
|
124
|
+
:subject => "subby",
|
125
|
+
:document_data => {:type => 'base64', :filename => "originalfile.pdf", :value => "mOio90cv"},
|
126
|
+
:recipients => [
|
127
|
+
{:recipient => {:name => "Signy Sign", :email => "signy@example.com", :role => "signer"}},
|
128
|
+
{:recipient =>{:name => "Cee Cee", :email => "ccme@example.com", :role => "cc"}}
|
129
|
+
],
|
130
|
+
:action => "send",
|
131
|
+
:description => "My descript",
|
132
|
+
:callback_url => "http://example.com/call"
|
133
|
+
}
|
134
|
+
})
|
135
|
+
document_data = {:type => 'base64', :filename => "originalfile.pdf", :value => "mOio90cv"}
|
136
|
+
recipients = [{:name => "Signy Sign", :email => "signy@example.com", :role => "signer"}, {:name => "Cee Cee", :email => "ccme@example.com", :role => "cc"}]
|
137
|
+
|
138
|
+
options = {
|
139
|
+
:description => "My descript",
|
140
|
+
:callback_url => "http://example.com/call"
|
141
|
+
}
|
142
|
+
RightSignature::Document.send_document("subby", recipients, document_data, options)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "send_document_from_data" do
|
147
|
+
it "should POST /api/documents.xml with document hash containing given subject, Base64 encoded version of document data, recipients, and action of 'send'" do
|
148
|
+
RightSignature::Connection.should_receive(:post).with("/api/documents.xml", {
|
149
|
+
:document => {
|
150
|
+
:subject => "subby",
|
151
|
+
:document_data => {:type => 'base64', :filename => "my fresh upload.pdf", :value => Base64::encode64("THIS IS MY data")},
|
152
|
+
:recipients => [],
|
153
|
+
:action => "send"
|
154
|
+
}
|
155
|
+
})
|
156
|
+
RightSignature::Document.send_document_from_data("THIS IS MY data", "my fresh upload.pdf", "subby", [])
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should POST /api/documents.xml with options" do
|
160
|
+
RightSignature::Connection.should_receive(:post).with("/api/documents.xml", {
|
161
|
+
:document => {
|
162
|
+
:subject => "subby",
|
163
|
+
:action => "send",
|
164
|
+
:document_data => {:type => 'base64', :filename => "uploaded.pdf", :value => Base64::encode64("THIS")},
|
165
|
+
:recipients => [
|
166
|
+
{:recipient => {:name => "Signy Sign", :email => "signy@example.com", :role => "signer"}},
|
167
|
+
{:recipient =>{:name => "Cee Cee", :email => "ccme@example.com", :role => "cc"}}
|
168
|
+
],
|
169
|
+
:description => "My descript",
|
170
|
+
:callback_url => "http://example.com/call"
|
171
|
+
}
|
172
|
+
})
|
173
|
+
|
174
|
+
recipients = [{:name => "Signy Sign", :email => "signy@example.com", :role => "signer"}, {:name => "Cee Cee", :email => "ccme@example.com", :role => "cc"}]
|
175
|
+
options = {
|
176
|
+
:description => "My descript",
|
177
|
+
:callback_url => "http://example.com/call"
|
178
|
+
}
|
179
|
+
RightSignature::Document.send_document_from_data("THIS", "uploaded.pdf", "subby", recipients, options)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe "send_document_from_file" do
|
184
|
+
it "should open File and base64 encode it" do
|
185
|
+
# Probably get a fixture or something here
|
186
|
+
file = File.new(File.dirname(__FILE__) + '/spec_helper.rb')
|
187
|
+
fake_data = "abc"
|
188
|
+
File.should_receive(:read).with(file).and_return(fake_data)
|
189
|
+
RightSignature::Connection.should_receive(:post).with("/api/documents.xml", {
|
190
|
+
:document => {
|
191
|
+
:subject => "subby",
|
192
|
+
:action => "send",
|
193
|
+
:document_data => {:type => 'base64', :filename => "spec_helper.rb", :value => Base64::encode64(fake_data)},
|
194
|
+
:recipients => []
|
195
|
+
}
|
196
|
+
})
|
197
|
+
|
198
|
+
RightSignature::Document.send_document_from_file(file, "subby", [])
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should open path to file and base64 encode it" do
|
202
|
+
file_path = '/tmp/temp.pdf'
|
203
|
+
fake_data = "abc"
|
204
|
+
File.should_receive(:read).with(file_path).and_return(fake_data)
|
205
|
+
RightSignature::Connection.should_receive(:post).with("/api/documents.xml", {
|
206
|
+
:document => {
|
207
|
+
:subject => "subby",
|
208
|
+
:action => "send",
|
209
|
+
:document_data => {:type => 'base64', :filename => "temp.pdf", :value => Base64::encode64(fake_data)},
|
210
|
+
:recipients => []
|
211
|
+
}
|
212
|
+
})
|
213
|
+
RightSignature::Document.send_document_from_file(file_path, "subby", [])
|
214
|
+
end
|
215
|
+
|
216
|
+
it "should POST /api/documents.xml with options" do
|
217
|
+
file_path = '/tmp/temp.pdf'
|
218
|
+
fake_data = "abc"
|
219
|
+
File.should_receive(:read).with(file_path).and_return(fake_data)
|
220
|
+
RightSignature::Connection.should_receive(:post).with("/api/documents.xml", {
|
221
|
+
:document => {
|
222
|
+
:subject => "subby",
|
223
|
+
:action => "send",
|
224
|
+
:document_data => {:type => 'base64', :filename => "temp.pdf", :value => Base64::encode64(fake_data)},
|
225
|
+
:recipients => [
|
226
|
+
{:recipient => {:name => "Signy Sign", :email => "signy@example.com", :role => "signer"}},
|
227
|
+
{:recipient =>{:name => "Cee Cee", :email => "ccme@example.com", :role => "cc"}}
|
228
|
+
],
|
229
|
+
:description => "My descript",
|
230
|
+
:callback_url => "http://example.com/call"
|
231
|
+
}
|
232
|
+
})
|
233
|
+
|
234
|
+
recipients = [{:name => "Signy Sign", :email => "signy@example.com", :role => "signer"}, {:name => "Cee Cee", :email => "ccme@example.com", :role => "cc"}]
|
235
|
+
options = {
|
236
|
+
:description => "My descript",
|
237
|
+
:callback_url => "http://example.com/call"
|
238
|
+
}
|
239
|
+
RightSignature::Document.send_document_from_file(file_path, "subby", recipients, options)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
describe "generate_document_url" do
|
244
|
+
it "should POST /api/documents.xml with redirect action and return https://rightsignature.com/builder/new?rt=REDIRECT_TOKEN" do
|
245
|
+
RightSignature::Connection.should_receive(:post).with("/api/documents.xml", {
|
246
|
+
:document => {
|
247
|
+
:subject => "subjy",
|
248
|
+
:action => "redirect",
|
249
|
+
:document_data => {},
|
250
|
+
:recipients => [],
|
251
|
+
}
|
252
|
+
}).and_return({"document"=>{"redirect_token" => "REDIRECT_TOKEN"}})
|
253
|
+
RightSignature::Document.generate_document_redirect_url("subjy", [], {}).should == "#{RightSignature::Connection.site}/builder/new?rt=REDIRECT_TOKEN"
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|