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.
@@ -0,0 +1,119 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe RightSignature::ResponseError do
4
+ describe "For OAuth response" do
5
+ before do
6
+ @net_http_response = Net::HTTPSuccess.new('1.1', '200', 'OK')
7
+ @error = RightSignature::ResponseError.new(@net_http_response)
8
+ end
9
+
10
+ it "response should return Net::HTTP response" do
11
+ @error.response.should == @net_http_response
12
+ end
13
+
14
+ it "code should return response code" do
15
+ @error.code.should == '200'
16
+ end
17
+
18
+ describe "message" do
19
+ it "should return response message" do
20
+ @error.message.should == 'OK'
21
+ end
22
+
23
+ it "should return specified message" do
24
+ error = RightSignature::ResponseError.new(@net_http_response, "No Way")
25
+ error.message.should == 'No Way'
26
+ end
27
+ end
28
+
29
+ describe "common_solutions" do
30
+ describe "on 406" do
31
+ it "should suggest to check Content-Type header, url, or Accept header" do
32
+ net_http_response = Net::HTTPNotAcceptable.new('1.1', '406', 'Not Acceptable')
33
+ error = RightSignature::ResponseError.new(net_http_response)
34
+ error.common_solutions.should match /Check the Content-Type/i
35
+ error.common_solutions.should match /ensure url has \.xml or \.json/i
36
+ error.common_solutions.should match /check 'Accept' header/i
37
+ end
38
+ end
39
+
40
+ describe "on 401" do
41
+ it "should suggest to check credentials" do
42
+ net_http_response = Net::HTTPUnauthorized.new('1.1', '401', 'Unauthorized Access')
43
+ error = RightSignature::ResponseError.new(net_http_response)
44
+ error.common_solutions.should match /Check your credentials/i
45
+ end
46
+ end
47
+
48
+ describe "on 500s" do
49
+ it "should suggest to check xml or json format" do
50
+ net_http_response = Net::HTTPInternalServerError.new('1.1', '500', 'Internal Server Error')
51
+ error = RightSignature::ResponseError.new(net_http_response)
52
+ error.common_solutions.should match /Check the format of your xml or json/i
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "For HTTParty response" do
59
+ before do
60
+ @net_http_response = Net::HTTPOK.new('1.1', 200, 'OK')
61
+ @net_http_response.stub(:body =>"{}")
62
+
63
+ @response = HTTParty::Response.new(HTTParty::Request.new(Net::HTTP::Get, '/'), @net_http_response, lambda { {} })
64
+ @error = RightSignature::ResponseError.new(@response)
65
+ end
66
+
67
+ it "response should return HTTParty response" do
68
+ @error.response.should == @response
69
+ end
70
+
71
+ it "code should return response code" do
72
+ @error.code.should == 200
73
+ end
74
+
75
+ describe "message" do
76
+ it "should return response message" do
77
+ @error.message.should == 'OK'
78
+ end
79
+ it "should return specified message" do
80
+ error = RightSignature::ResponseError.new(@response, "No Way")
81
+ error.message.should == 'No Way'
82
+ end
83
+ end
84
+
85
+ describe "common_solutions" do
86
+ describe "on 406" do
87
+ it "should suggest to check Content-Type header, url, or Accept header" do
88
+ net_http_response = Net::HTTPNotAcceptable.new('1.1', '406', 'Not Acceptable')
89
+ net_http_response.stub(:body =>"{}")
90
+ response = HTTParty::Response.new(HTTParty::Request.new(Net::HTTP::Get, '/'), net_http_response, lambda { {} })
91
+ error = RightSignature::ResponseError.new(response)
92
+ error.common_solutions.should match /Check the Content-Type/i
93
+ error.common_solutions.should match /ensure url has \.xml or \.json/i
94
+ error.common_solutions.should match /check 'Accept' header/i
95
+ end
96
+ end
97
+
98
+ describe "on 401" do
99
+ it "should suggest to check credentials" do
100
+ net_http_response = Net::HTTPUnauthorized.new('1.1', '401', 'Unauthorized Access')
101
+ net_http_response.stub(:body =>"{}")
102
+ response = HTTParty::Response.new(HTTParty::Request.new(Net::HTTP::Get, '/'), net_http_response, lambda { {} })
103
+ error = RightSignature::ResponseError.new(response)
104
+ error.common_solutions.should match /Check your credentials/i
105
+ end
106
+ end
107
+
108
+ describe "on 500s" do
109
+ it "should suggest to check xml or json format" do
110
+ net_http_response = Net::HTTPInternalServerError.new('1.1', '500', 'Internal Server Error')
111
+ net_http_response.stub(:body =>"{}")
112
+ response = HTTParty::Response.new(HTTParty::Request.new(Net::HTTP::Get, '/'), net_http_response, lambda { {} })
113
+ error = RightSignature::ResponseError.new(response)
114
+ error.common_solutions.should match /Check the format of your xml or json/i
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,42 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe RightSignature::OauthConnection do
4
+ before do
5
+ @consumer_mock = mock(OAuth::Consumer)
6
+ @access_token_mock = mock(OAuth::AccessToken)
7
+ end
8
+
9
+ describe "access_token" do
10
+ it "should create OAuth access token with credentials" do
11
+ OAuth::Consumer.should_receive(:new).with(
12
+ "Consumer123",
13
+ "Secret098",
14
+ {
15
+ :site => "https://rightsignature.com",
16
+ :scheme => :header,
17
+ :http_method => :post,
18
+ :authorize_path =>'/oauth/authorize',
19
+ :access_token_path =>'/oauth/access_token',
20
+ :request_token_path=>'/oauth/request_token'
21
+ }).and_return(@consumer_mock)
22
+ OAuth::AccessToken.should_receive(:new).with(@consumer_mock, 'AccessToken098', 'AccessSecret123')
23
+
24
+ RightSignature::OauthConnection.access_token
25
+ end
26
+ end
27
+
28
+ describe "request" do
29
+ it "should create GET request with access token and path with custom headers as 3rd argument" do
30
+ @access_token_mock.should_receive(:get).with('path', {"User-Agent" => 'My own', "Accept"=>"*/*", "content-type"=>"application/xml"})
31
+ RightSignature::OauthConnection.stub(:access_token).and_return(@access_token_mock)
32
+ RightSignature::OauthConnection.request(:get, "path", {"User-Agent" => 'My own'})
33
+ end
34
+
35
+ it "should create POST request with access token and path with body as 3rd argument and custom headers as 4th argument" do
36
+ @access_token_mock.should_receive(:post).with('path', "<template></template>", {"User-Agent" => 'My own', "Accept"=>"*/*", "content-type"=>"application/xml"})
37
+ RightSignature::OauthConnection.stub(:access_token).and_return(@access_token_mock)
38
+ RightSignature::OauthConnection.request(:post, "path", "<template></template>", {"User-Agent" => 'My own'})
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+
4
+ require File.dirname(__FILE__) + '/../lib/rightsignature'
5
+
6
+ RSpec.configure do |c|
7
+ c.mock_with :rspec
8
+
9
+ c.before(:each) do
10
+ RightSignature::configuration = {:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123", :api_token => "APITOKEN"}
11
+ end
12
+ end
@@ -0,0 +1,189 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe RightSignature::Template do
4
+ describe "list" do
5
+ it "should GET /api/templates.xml" do
6
+ RightSignature::Connection.should_receive(:get).with('/api/templates.xml', {})
7
+ RightSignature::Template.list
8
+ end
9
+
10
+ it "should pass search options to /api/templates.xml" do
11
+ RightSignature::Connection.should_receive(:get).with('/api/templates.xml', {:search => "search", :page => 2})
12
+ RightSignature::Template.list(:search => "search", :page => 2)
13
+ end
14
+
15
+ it "should convert tags array of mixed strings and hashes into into normalized Tag string" do
16
+ RightSignature::Connection.should_receive(:get).with('/api/templates.xml', {:tags => "hello,abc:def,there"})
17
+ RightSignature::Template.list(:tags => ["hello", {"abc" => "def"}, "there"])
18
+ end
19
+
20
+ it "should keep tags as string if :tags is a string" do
21
+ RightSignature::Connection.should_receive(:get).with('/api/templates.xml', {:tags => "voice,no:way,microphone"})
22
+ RightSignature::Template.list(:tags => "voice,no:way,microphone")
23
+ end
24
+ end
25
+
26
+ describe "details" do
27
+ it "should GET /api/templates/MYGUID.xml" do
28
+ RightSignature::Connection.should_receive(:get).with('/api/templates/MYGUID.xml', {})
29
+ RightSignature::Template.details('MYGUID')
30
+ end
31
+ end
32
+
33
+ describe "prepackage" do
34
+ it "should POST /api/templates/MYGUID/prepackage.xml" do
35
+ RightSignature::Connection.should_receive(:post).with('/api/templates/MYGUID/prepackage.xml', {})
36
+ RightSignature::Template.prepackage('MYGUID')
37
+ end
38
+ end
39
+
40
+
41
+ describe "prepackage_and_send" do
42
+ it "should POST /api/templates/GUID123/prepackage.xml and POST /api/templates.xml using guid, and subject from prepackage response" do
43
+ RightSignature::Connection.should_receive(:post).with('/api/templates/GUID123/prepackage.xml',
44
+ {}
45
+ ).and_return({"template" => {
46
+ "guid" => "a_123985_1z9v8pd654",
47
+ "subject" => "subject template",
48
+ "message" => "Default message here"
49
+ }})
50
+ RightSignature::Connection.should_receive(:post).with('/api/templates.xml', {:template => {
51
+ :guid => "a_123985_1z9v8pd654",
52
+ :action => "send",
53
+ :subject => "sign me",
54
+ :roles => []
55
+ }})
56
+ RightSignature::Template.prepackage_and_send("GUID123", "sign me", [])
57
+ end
58
+ end
59
+
60
+ describe "prefill/send_template" do
61
+ it "should POST /api/templates.xml with action of 'prefill', MYGUID guid, roles, and \"sign me\" subject in template hash" do
62
+ RightSignature::Connection.should_receive(:post).with('/api/templates.xml', {:template => {:guid => "MYGUID", :action => "prefill", :subject => "sign me", :roles => []}})
63
+ RightSignature::Template.prefill("MYGUID", "sign me", [])
64
+ end
65
+
66
+ it "should add \"@role_name\"=>'Employee' key to roles in xml hash" do
67
+ RightSignature::Connection.should_receive(:post).with('/api/templates.xml', {
68
+ :template => {
69
+ :guid => "MYGUID",
70
+ :action => "prefill",
71
+ :subject => "sign me",
72
+ :roles => [
73
+ {:role => {
74
+ :name => "John Employee",
75
+ :email => "john@employee.com",
76
+ "@role_name" => "Employee"
77
+ }}
78
+ ]
79
+ }
80
+ })
81
+ RightSignature::Template.prefill("MYGUID", "sign me", [{"Employee" => {:name => "John Employee", :email => "john@employee.com"}}])
82
+ end
83
+
84
+ describe "optional options" do
85
+ it "should add \"@merge_field_name\"=>'Tax_id' key to merge_fields in xml hash" do
86
+ RightSignature::Connection.should_receive(:post).with('/api/templates.xml', {
87
+ :template => {
88
+ :guid => "MYGUID",
89
+ :action => "prefill",
90
+ :subject => "sign me",
91
+ :roles => [
92
+ ],
93
+ :merge_fields => [{:merge_field => {:value => "123456", "@merge_field_name" => "Tax_id"}}]
94
+ }
95
+ })
96
+ RightSignature::Template.prefill("MYGUID", "sign me", [], {:merge_fields => [{"Tax_id" => "123456"}]})
97
+ end
98
+
99
+ it "should add \"tag\" key to tags in xml hash" do
100
+ RightSignature::Connection.should_receive(:post).with('/api/templates.xml', {
101
+ :template => {
102
+ :guid => "MYGUID",
103
+ :action => "prefill",
104
+ :subject => "sign me",
105
+ :roles => [],
106
+ :tags => [{:tag => {:name => "I_Key", :value => "I_Value"}}, {:tag => {:name => "Alone"}}]
107
+ }
108
+ })
109
+ RightSignature::Template.prefill("MYGUID", "sign me", [], {:tags => [{"I_Key" => "I_Value"}, "Alone"]})
110
+ end
111
+
112
+ it "should include options :expires_in, :description, and :callback_url" do
113
+ RightSignature::Connection.should_receive(:post).with('/api/templates.xml', {
114
+ :template => {
115
+ :guid => "MYGUID",
116
+ :action => "prefill",
117
+ :subject => "sign me",
118
+ :roles => [],
119
+ :expires_in => 15,
120
+ :description => "Hey, I'm a description",
121
+ :callback_url => 'http://example.com/callie'
122
+ }
123
+ })
124
+ RightSignature::Template.prefill("MYGUID", "sign me", [], {:expires_in => 15, :description => "Hey, I'm a description", :callback_url => "http://example.com/callie"})
125
+ end
126
+ end
127
+
128
+ it "should POST /api/templates.xml with action of 'send', MYGUID guid, roles, and \"sign me\" subject in template hash" do
129
+ RightSignature::Connection.should_receive(:post).with('/api/templates.xml', {:template => {:guid => "MYGUID", :action => "send", :subject => "sign me", :roles => []}})
130
+ RightSignature::Template.send_template("MYGUID", "sign me", [])
131
+ end
132
+ end
133
+
134
+ describe "generate_build_url" do
135
+ it "should POST /api/templates/generate_build_token.xml" do
136
+ RightSignature::Connection.should_receive(:post).with("/api/templates/generate_build_token.xml", {:template => {}}).and_return({"token"=>{"redirect_token" => "REDIRECT_TOKEN"}})
137
+ RightSignature::Template.generate_build_url
138
+ end
139
+
140
+ it "should return https://rightsignature.com/builder/new?rt=REDIRECT_TOKEN" do
141
+ RightSignature::Connection.should_receive(:post).with("/api/templates/generate_build_token.xml", {:template => {}}).and_return({"token"=>{"redirect_token" => "REDIRECT_TOKEN"}})
142
+ RightSignature::Template.generate_build_url.should == "#{RightSignature::Connection.site}/builder/new?rt=REDIRECT_TOKEN"
143
+ end
144
+
145
+ describe "options" do
146
+ it "should include normalized :acceptable_merge_field_names in params" do
147
+ RightSignature::Connection.should_receive(:post).with("/api/templates/generate_build_token.xml", {:template =>
148
+ {:acceptable_merge_field_names =>
149
+ [
150
+ {:name => "Site ID"},
151
+ {:name => "Starting City"}
152
+ ]}
153
+ }).and_return({"token"=>{"redirect_token" => "REDIRECT_TOKEN"}})
154
+ RightSignature::Template.generate_build_url(:acceptable_merge_field_names => ["Site ID", "Starting City"])
155
+ end
156
+
157
+ it "should include normalized :acceptabled_role_names, in params" do
158
+ RightSignature::Connection.should_receive(:post).with("/api/templates/generate_build_token.xml", {:template =>
159
+ {:acceptabled_role_names =>
160
+ [
161
+ {:name => "Http Monster"},
162
+ {:name => "Party Monster"}
163
+ ]}
164
+ }).and_return({"token"=>{"redirect_token" => "REDIRECT_TOKEN"}})
165
+ RightSignature::Template.generate_build_url(:acceptabled_role_names => ["Http Monster", "Party Monster"])
166
+ end
167
+
168
+ it "should include normalized :tags in params" do
169
+ RightSignature::Connection.should_receive(:post).with("/api/templates/generate_build_token.xml", {:template =>
170
+ {:tags =>
171
+ [
172
+ {:tag => {:name => "Site"}},
173
+ {:tag => {:name => "Starting City", :value => "NY"}}
174
+ ]}
175
+ }).and_return({"token"=>{"redirect_token" => "REDIRECT_TOKEN"}})
176
+ RightSignature::Template.generate_build_url(:tags => ["Site", "Starting City" => "NY"])
177
+ end
178
+
179
+ it "should include :callback_location and :redirect_location in params" do
180
+ RightSignature::Connection.should_receive(:post).with("/api/templates/generate_build_token.xml", {:template => {
181
+ :callback_location => "http://example.com/done_signing",
182
+ :redirect_location => "http://example.com/come_back_here"
183
+ }}).and_return({"token"=>{"redirect_token" => "REDIRECT_TOKEN"}})
184
+
185
+ RightSignature::Template.generate_build_url(:callback_location => "http://example.com/done_signing", :redirect_location => "http://example.com/come_back_here")
186
+ end
187
+ end
188
+ end
189
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rightsignature
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alex Chee
9
+ - Geoff Ereth
10
+ - Cary Dunn
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-09-24 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: bundler
18
+ requirement: &70117188199340 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.0
24
+ type: :development
25
+ prerelease: false
26
+ version_requirements: *70117188199340
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: &70117188198600 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: 2.11.0
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: *70117188198600
38
+ - !ruby/object:Gem::Dependency
39
+ name: bundler
40
+ requirement: &70117204029320 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.0
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: *70117204029320
49
+ - !ruby/object:Gem::Dependency
50
+ name: oauth
51
+ requirement: &70117204028660 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - =
55
+ - !ruby/object:Gem::Version
56
+ version: 0.4.3
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: *70117204028660
60
+ - !ruby/object:Gem::Dependency
61
+ name: httparty
62
+ requirement: &70117204027840 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: 0.9.0
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: *70117204027840
71
+ - !ruby/object:Gem::Dependency
72
+ name: xml-fu
73
+ requirement: &70117204026860 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: 0.1.7
79
+ type: :runtime
80
+ prerelease: false
81
+ version_requirements: *70117204026860
82
+ description: Provides a wrapper for the RightSignature API.
83
+ email:
84
+ - dev@rightsignature.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - .gitignore
90
+ - Gemfile
91
+ - Gemfile.lock
92
+ - README.md
93
+ - lib/rightsignature.rb
94
+ - lib/rightsignature/connection.rb
95
+ - lib/rightsignature/connection/oauth_connection.rb
96
+ - lib/rightsignature/connection/token_connection.rb
97
+ - lib/rightsignature/document.rb
98
+ - lib/rightsignature/errors.rb
99
+ - lib/rightsignature/helpers/normalizing.rb
100
+ - lib/rightsignature/template.rb
101
+ - lib/rightsignature/version.rb
102
+ - rightsignature-api.gemspec
103
+ - spec/api_token_connection_spec.rb
104
+ - spec/configuration_spec.rb
105
+ - spec/connection_spec.rb
106
+ - spec/document_spec.rb
107
+ - spec/errors_spec.rb
108
+ - spec/oauth_connnection_spec.rb
109
+ - spec/spec_helper.rb
110
+ - spec/template_spec.rb
111
+ homepage: http://github.com/alexchee/rightsignature-api
112
+ licenses: []
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 1.8.10
132
+ signing_key:
133
+ specification_version: 3
134
+ summary: API wrapper for RightSignature
135
+ test_files: []
136
+ has_rdoc: