rightsignature 0.1.6 → 0.1.7
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/README.md +31 -4
- data/lib/rightsignature/connection/oauth_connection.rb +30 -1
- data/lib/rightsignature/connection/token_connection.rb +2 -0
- data/lib/rightsignature/connection.rb +44 -18
- data/lib/rightsignature/version.rb +1 -1
- data/lib/rightsignature.rb +0 -1
- data/spec/api_token_connection_spec.rb +5 -0
- data/spec/connection_spec.rb +137 -11
- data/spec/oauth_connnection_spec.rb +79 -2
- data/spec/template_spec.rb +8 -8
- metadata +2 -2
data/README.md
CHANGED
@@ -8,12 +8,12 @@ gem install rightsignature
|
|
8
8
|
```
|
9
9
|
or in your Gemfile
|
10
10
|
```
|
11
|
-
gem 'rightsignature', '~> 0.1.
|
11
|
+
gem 'rightsignature', '~> 0.1.7'
|
12
12
|
```
|
13
13
|
|
14
14
|
Setup
|
15
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::load_configuration.
|
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::load_configuration. Below are examples on how to use the gem as yourself.
|
17
17
|
|
18
18
|
#####Using Token authentication
|
19
19
|
```
|
@@ -31,8 +31,36 @@ RightSignature::load_configuration(
|
|
31
31
|
```
|
32
32
|
Note: if the both OAuth credentials and api_token are set, the default action is to use Token Authentication.
|
33
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 = RightSignature::OauthConnection.new_request_token
|
38
|
+
```
|
39
|
+
|
40
|
+
Now Visit the url generated from
|
41
|
+
```
|
42
|
+
RightSignature::OauthConnection.request_token.authorize_url
|
43
|
+
```
|
44
|
+
and log into the site.
|
45
|
+
|
46
|
+
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:
|
47
|
+
```
|
48
|
+
RightSignature::OauthConnection.generate_access_token(params[:oauth_verifer])
|
49
|
+
```
|
50
|
+
|
51
|
+
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.
|
52
|
+
```
|
53
|
+
RightSignature::OauthConnection.access_token.token
|
54
|
+
RightSignature::OauthConnection.access_token.secret
|
55
|
+
```
|
56
|
+
Will give you the Access Token's token and secret.
|
57
|
+
|
58
|
+
You can also load the Access Token and Secret by calling
|
59
|
+
```
|
60
|
+
RightSignature::OauthConnection.set_access_token(token, secret)
|
61
|
+
```
|
34
62
|
|
35
|
-
After loading the configuration, you can use wrappers in RightSignature::Document or RightSignature::
|
63
|
+
After loading the configuration, you can use wrappers in RightSignature::Document, RightSignature::Template, or RightSignature::Account to call the API. Or use RightSignature::Connection for a more custom call.
|
36
64
|
|
37
65
|
Documents
|
38
66
|
---------
|
@@ -393,4 +421,3 @@ $:.push File.expand_path("../lib", __FILE__); require "rightsignature"; RightSig
|
|
393
421
|
TODO:
|
394
422
|
-----
|
395
423
|
* Parse error message from response body on unsuccessful requests
|
396
|
-
* Have a way for to generate an OAuth Access Token from RightSignature
|
@@ -2,7 +2,10 @@ module RightSignature
|
|
2
2
|
class OauthConnection
|
3
3
|
|
4
4
|
class << self
|
5
|
+
attr_reader :request_token
|
6
|
+
|
5
7
|
def oauth_consumer
|
8
|
+
check_credentials unless RightSignature::configuration[:consumer_key] && RightSignature::configuration[:consumer_secret]
|
6
9
|
@oauth_consumer ||= OAuth::Consumer.new(
|
7
10
|
RightSignature::configuration[:consumer_key],
|
8
11
|
RightSignature::configuration[:consumer_secret],
|
@@ -18,7 +21,28 @@ module RightSignature
|
|
18
21
|
end
|
19
22
|
|
20
23
|
def access_token
|
21
|
-
|
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)
|
22
46
|
end
|
23
47
|
|
24
48
|
def request(method, *options)
|
@@ -28,6 +52,11 @@ module RightSignature
|
|
28
52
|
|
29
53
|
self.access_token.__send__(method, *options)
|
30
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
|
31
60
|
end
|
32
61
|
|
33
62
|
end
|
@@ -6,6 +6,8 @@ module RightSignature
|
|
6
6
|
|
7
7
|
class <<self
|
8
8
|
def request(method, url, options)
|
9
|
+
raise "Please set load_configuration with #{RightSignature::api_token_keys.join(', ')}" unless RightSignature::has_api_token?
|
10
|
+
|
9
11
|
options[:headers] ||= {}
|
10
12
|
options[:headers]['api-token'] = RightSignature::configuration[:api_token]
|
11
13
|
options[:headers]["Accept"] ||= "*/*"
|
@@ -8,7 +8,30 @@ module RightSignature
|
|
8
8
|
RightSignature::OauthConnection.oauth_consumer.site
|
9
9
|
end
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
|
+
def put(url, body={}, headers={})
|
13
|
+
if RightSignature::has_api_token?
|
14
|
+
options = {}
|
15
|
+
options[:headers] = headers
|
16
|
+
options[:body] = XmlFu.xml(body)
|
17
|
+
|
18
|
+
parse_response(RightSignature::TokenConnection.request(:put, url, options))
|
19
|
+
else
|
20
|
+
parse_response(RightSignature::OauthConnection.request(:put, url, XmlFu.xml(body), headers))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete(url, headers={})
|
25
|
+
if RightSignature::has_api_token?
|
26
|
+
options = {}
|
27
|
+
options[:headers] = headers
|
28
|
+
|
29
|
+
parse_response(RightSignature::TokenConnection.request(:delete, url, options))
|
30
|
+
else
|
31
|
+
parse_response(RightSignature::OauthConnection.request(:delete, url, headers))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
12
35
|
def get(url, params={}, headers={})
|
13
36
|
RightSignature::check_credentials
|
14
37
|
|
@@ -16,13 +39,12 @@ module RightSignature
|
|
16
39
|
options = {}
|
17
40
|
options[:headers] = headers
|
18
41
|
options[:query] = params
|
19
|
-
RightSignature::TokenConnection.request(:get, url, options)
|
42
|
+
parse_response(RightSignature::TokenConnection.request(:get, url, options))
|
20
43
|
else
|
21
44
|
unless params.empty?
|
22
45
|
url = "#{url}?#{params.sort.map{|param| URI.escape("#{param[0]}=#{param[1]}")}.join('&')}"
|
23
46
|
end
|
24
|
-
|
25
|
-
MultiXml.parse(res.body)
|
47
|
+
parse_response(RightSignature::OauthConnection.request(:get, url, headers))
|
26
48
|
end
|
27
49
|
end
|
28
50
|
|
@@ -33,26 +55,30 @@ module RightSignature
|
|
33
55
|
options = {}
|
34
56
|
options[:headers] = headers
|
35
57
|
options[:body] = XmlFu.xml(body)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
58
|
+
parse_response(RightSignature::TokenConnection.request(:post, url, options))
|
59
|
+
else
|
60
|
+
parse_response(RightSignature::OauthConnection.request(:post, url, XmlFu.xml(body), headers))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def parse_response(response)
|
65
|
+
if response.is_a? Net::HTTPResponse
|
66
|
+
unless response.is_a? Net::HTTPSuccess
|
67
|
+
puts response.body
|
68
|
+
raise RightSignature::ResponseError.new(response)
|
41
69
|
end
|
42
70
|
|
43
|
-
|
71
|
+
MultiXml.parse(response.body)
|
44
72
|
else
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
puts res.body
|
49
|
-
raise RightSignature::ResponseError.new(res)
|
73
|
+
unless response.success?
|
74
|
+
puts response.body
|
75
|
+
raise RightSignature::ResponseError.new(response)
|
50
76
|
end
|
51
|
-
|
52
|
-
|
77
|
+
|
78
|
+
response.parsed_response
|
53
79
|
end
|
54
80
|
end
|
81
|
+
|
55
82
|
end
|
56
|
-
|
57
83
|
end
|
58
84
|
end
|
data/lib/rightsignature.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
|
3
3
|
describe RightSignature::TokenConnection do
|
4
|
+
it "should raise error if no configuration is set" do
|
5
|
+
RightSignature::configuration = {}
|
6
|
+
lambda{RightSignature::TokenConnection.request(:get, "path", {:query => {:search => 'hey there'}})}.should raise_error(Exception, "Please set load_configuration with api_token")
|
7
|
+
end
|
8
|
+
|
4
9
|
it "should create 'api-token' to headers with :api_token credentials, accept of '*/*', and content-type of xml with given method" do
|
5
10
|
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
11
|
RightSignature::TokenConnection.request(:get, "path", {:query => {:search => 'hey there'}})
|
data/spec/connection_spec.rb
CHANGED
@@ -1,23 +1,29 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../lib/rightsignature'
|
2
2
|
|
3
3
|
describe RightSignature::Connection do
|
4
|
+
before do
|
5
|
+
@net_http_response = Net::HTTPOK.new('1.1', 200, 'OK')
|
6
|
+
@net_http_response.stub(:body => '')
|
7
|
+
@httparty_response = stub("HTTPartyResponse", :parsed_response => nil, :body => '', :success? => true)
|
8
|
+
end
|
9
|
+
|
4
10
|
describe "GET" do
|
5
11
|
describe "connection method" do
|
6
|
-
it "should default to RightSignature::
|
12
|
+
it "should default to RightSignature::57 if no api_token was specified" do
|
7
13
|
RightSignature::configuration = {:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"}
|
8
|
-
RightSignature::OauthConnection.should_receive(:request).and_return(
|
14
|
+
RightSignature::OauthConnection.should_receive(:request).and_return(@net_http_response)
|
9
15
|
RightSignature::Connection.get("/path")
|
10
16
|
end
|
11
17
|
|
12
18
|
it "should use RightSignature::TokenConnection if api_token was specified" do
|
13
19
|
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(
|
20
|
+
RightSignature::TokenConnection.should_receive(:request).and_return(@httparty_response)
|
15
21
|
RightSignature::Connection.get("/path")
|
16
22
|
end
|
17
23
|
|
18
24
|
it "should use RightSignature::TokenConnection if only api_token was specified" do
|
19
25
|
RightSignature::configuration = {:api_token => "APITOKEN"}
|
20
|
-
RightSignature::TokenConnection.should_receive(:request).and_return(
|
26
|
+
RightSignature::TokenConnection.should_receive(:request).and_return(@httparty_response)
|
21
27
|
RightSignature::Connection.get("/path")
|
22
28
|
end
|
23
29
|
end
|
@@ -30,13 +36,16 @@ describe RightSignature::Connection do
|
|
30
36
|
describe "using OauthConnection" do
|
31
37
|
it "should append params into path alphabetically and URI escaped" do
|
32
38
|
RightSignature::configuration = {:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"}
|
33
|
-
|
39
|
+
@net_http_response.stub(:body).and_return('<document><subject>My Subject</subject></document>')
|
40
|
+
RightSignature::OauthConnection.should_receive(:request).with(:get, "/path?page=1&q=search%20me", {}).and_return(@net_http_response)
|
34
41
|
RightSignature::Connection.get("/path", {:q => 'search me', :page => 1})
|
35
42
|
end
|
36
43
|
|
37
44
|
it "should return converted response body from XML to hash" do
|
38
45
|
RightSignature::configuration = {:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"}
|
39
|
-
|
46
|
+
response = Net::HTTPSuccess.new('1.1', 200, 'OK')
|
47
|
+
response.stub(:body).and_return('<document><subject>My Subject</subject></document>')
|
48
|
+
RightSignature::OauthConnection.should_receive(:request).with(:get, "/path?page=1&q=search%20me", {}).and_return(response)
|
40
49
|
RightSignature::Connection.get("/path", {:q => 'search me', :page => 1}).should == {'document' => {'subject' => "My Subject"}}
|
41
50
|
end
|
42
51
|
end
|
@@ -44,13 +53,14 @@ describe RightSignature::Connection do
|
|
44
53
|
describe "using TokenConnection" do
|
45
54
|
it "should append params and header into query option and header option" do
|
46
55
|
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(
|
56
|
+
RightSignature::TokenConnection.should_receive(:request).with(:get, "/path", {:query => {:q => 'search me', :page => 1}, :headers => {"User-Agent" => "me"}}).and_return(@httparty_response)
|
48
57
|
RightSignature::Connection.get("/path", {:q => 'search me', :page => 1}, {"User-Agent" => "me"})
|
49
58
|
end
|
50
59
|
|
51
60
|
it "should return converted parsed_response from response" do
|
52
61
|
RightSignature::configuration = {:api_token => 'token'}
|
53
|
-
|
62
|
+
@httparty_response.should_receive(:parsed_response).and_return({'document' => {'subject' => "My Subject"}})
|
63
|
+
RightSignature::TokenConnection.stub(:request).and_return(@httparty_response)
|
54
64
|
RightSignature::Connection.get("/path", {:q => 'search me', :page => 1}).should == {'document' => {'subject' => "My Subject"}}
|
55
65
|
end
|
56
66
|
end
|
@@ -59,9 +69,6 @@ describe RightSignature::Connection do
|
|
59
69
|
describe "POST" do
|
60
70
|
describe "connection method" do
|
61
71
|
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
72
|
RightSignature::TokenConnection.stub(:request => @net_http_response)
|
66
73
|
RightSignature::OauthConnection.stub(:request => @httparty_response)
|
67
74
|
end
|
@@ -89,7 +96,126 @@ describe RightSignature::Connection do
|
|
89
96
|
lambda{RightSignature::Connection.post("/path")}.should raise_error
|
90
97
|
end
|
91
98
|
end
|
99
|
+
|
92
100
|
|
101
|
+
describe "DELETE" do
|
102
|
+
describe "connection method" do
|
103
|
+
it "should default to RightSignature::57 if no api_token was specified" do
|
104
|
+
RightSignature::configuration = {:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"}
|
105
|
+
RightSignature::OauthConnection.should_receive(:request).and_return(@net_http_response)
|
106
|
+
RightSignature::Connection.delete("/path")
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should use RightSignature::TokenConnection if api_token was specified" do
|
110
|
+
RightSignature::configuration = {:api_token => "APITOKEN", :consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"}
|
111
|
+
RightSignature::TokenConnection.should_receive(:request).and_return(@httparty_response)
|
112
|
+
RightSignature::Connection.delete("/path")
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should use RightSignature::TokenConnection if only api_token was specified" do
|
116
|
+
RightSignature::configuration = {:api_token => "APITOKEN"}
|
117
|
+
RightSignature::TokenConnection.should_receive(:request).and_return(@httparty_response)
|
118
|
+
RightSignature::Connection.delete("/path")
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should raise error if no configuration is set" do
|
123
|
+
RightSignature::configuration = nil
|
124
|
+
lambda{RightSignature::Connection.delete("/path")}.should raise_error
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "using OauthConnection" do
|
128
|
+
it "should return converted response body from XML to hash" do
|
129
|
+
RightSignature::configuration = {:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"}
|
130
|
+
response = Net::HTTPSuccess.new('1.1', 200, 'OK')
|
131
|
+
response.stub(:body).and_return('<document><subject>My Subject</subject></document>')
|
132
|
+
RightSignature::OauthConnection.should_receive(:request).with(:delete, "/path", {}).and_return(response)
|
133
|
+
RightSignature::Connection.delete("/path").should == {'document' => {'subject' => "My Subject"}}
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should pass headers" do
|
137
|
+
RightSignature::configuration = {:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"}
|
138
|
+
response = Net::HTTPSuccess.new('1.1', 200, 'OK')
|
139
|
+
response.stub(:body).and_return('<document><subject>My Subject</subject></document>')
|
140
|
+
RightSignature::OauthConnection.should_receive(:request).with(:delete, "/path", {"User-Agent" => "custom"}).and_return(response)
|
141
|
+
RightSignature::Connection.delete("/path", {"User-Agent" => "custom"}).should == {'document' => {'subject' => "My Subject"}}
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "using TokenConnection" do
|
146
|
+
it "should append headers into headers option" do
|
147
|
+
RightSignature::configuration = {:api_token => 'token'}
|
148
|
+
RightSignature::TokenConnection.should_receive(:request).with(:delete, "/path", {:headers => {"User-Agent" => "me"}}).and_return(@httparty_response)
|
149
|
+
RightSignature::Connection.delete("/path", {"User-Agent" => "me"})
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should return converted parsed_response from response" do
|
153
|
+
RightSignature::configuration = {:api_token => 'token'}
|
154
|
+
@httparty_response.should_receive(:parsed_response).and_return({'document' => {'subject' => "My Subject"}})
|
155
|
+
RightSignature::TokenConnection.stub(:request).and_return(@httparty_response)
|
156
|
+
RightSignature::Connection.delete("/path").should == {'document' => {'subject' => "My Subject"}}
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
describe "PUT" do
|
162
|
+
describe "connection method" do
|
163
|
+
it "should default to RightSignature::57 if no api_token was specified" do
|
164
|
+
RightSignature::configuration = {:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"}
|
165
|
+
RightSignature::OauthConnection.should_receive(:request).and_return(@net_http_response)
|
166
|
+
RightSignature::Connection.get("/path")
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should use RightSignature::TokenConnection if api_token was specified" do
|
170
|
+
RightSignature::configuration = {:api_token => "APITOKEN", :consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"}
|
171
|
+
RightSignature::TokenConnection.should_receive(:request).and_return(@httparty_response)
|
172
|
+
RightSignature::Connection.put("/path")
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should use RightSignature::TokenConnection if only api_token was specified" do
|
176
|
+
RightSignature::configuration = {:api_token => "APITOKEN"}
|
177
|
+
RightSignature::TokenConnection.should_receive(:request).and_return(@httparty_response)
|
178
|
+
RightSignature::Connection.put("/path")
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should raise error if no configuration is set" do
|
183
|
+
RightSignature::configuration = nil
|
184
|
+
lambda{RightSignature::Connection.put("/path")}.should raise_error
|
185
|
+
end
|
186
|
+
|
187
|
+
describe "using OauthConnection" do
|
188
|
+
it "should convert body into XML" do
|
189
|
+
RightSignature::configuration = {:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"}
|
190
|
+
@net_http_response.stub(:body).and_return('<document><subject>My Subject</subject></document>')
|
191
|
+
RightSignature::OauthConnection.should_receive(:request).with(:put, "/path", "<document><something>else</something><page>1</page></document>", {}).and_return(@net_http_response)
|
192
|
+
RightSignature::Connection.put("/path", {:document => {:something => "else", :page => 1}})
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should return converted response body from XML to hash" do
|
196
|
+
RightSignature::configuration = {:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"}
|
197
|
+
response = Net::HTTPSuccess.new('1.1', 200, 'OK')
|
198
|
+
response.stub(:body).and_return('<document><subject>My Subject</subject></document>')
|
199
|
+
RightSignature::OauthConnection.should_receive(:request).with(:put, "/path", "<document><something>else</something><page>1</page></document>", {}).and_return(response)
|
200
|
+
RightSignature::Connection.put("/path", {:document => {:something => "else", :page => 1}}).should == {'document' => {'subject' => "My Subject"}}
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
describe "using TokenConnection" do
|
205
|
+
it "should append params and header into query option and header option" do
|
206
|
+
RightSignature::configuration = {:api_token => 'token'}
|
207
|
+
RightSignature::TokenConnection.should_receive(:request).with(:put, "/path", {:body => "<document><something>else</something><page>1</page></document>", :headers => {"User-Agent" => "me"}}).and_return(@httparty_response)
|
208
|
+
RightSignature::Connection.put("/path", {:document => {:something => "else", :page => 1}}, {"User-Agent" => "me"})
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should return converted parsed_response from response" do
|
212
|
+
RightSignature::configuration = {:api_token => 'token'}
|
213
|
+
@httparty_response.should_receive(:parsed_response).and_return({'document' => {'subject' => "My Subject"}})
|
214
|
+
RightSignature::TokenConnection.stub(:request).and_return(@httparty_response)
|
215
|
+
RightSignature::Connection.put("/path", {:document => {:something => "else", :page => 1}}).should == {'document' => {'subject' => "My Subject"}}
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
93
219
|
|
94
220
|
end
|
95
221
|
end
|
@@ -6,8 +6,19 @@ describe RightSignature::OauthConnection do
|
|
6
6
|
@access_token_mock = mock(OAuth::AccessToken)
|
7
7
|
end
|
8
8
|
|
9
|
-
describe "
|
10
|
-
|
9
|
+
describe "oauth_consumer" do
|
10
|
+
after do
|
11
|
+
# Reset caching of oauth_consumer
|
12
|
+
RightSignature::OauthConnection.instance_variable_set("@oauth_consumer", nil)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should raise error if no configuration is set" do
|
16
|
+
RightSignature::configuration = {}
|
17
|
+
lambda{RightSignature::OauthConnection.oauth_consumer}.should raise_error(Exception, "Please set load_configuration with consumer_key, consumer_secret, access_token, access_secret")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return consumer if consumer_key and consumer_secret is set" do
|
21
|
+
RightSignature::configuration = {:consumer_key => "Consumer123", :consumer_secret => "Secret098"}
|
11
22
|
OAuth::Consumer.should_receive(:new).with(
|
12
23
|
"Consumer123",
|
13
24
|
"Secret098",
|
@@ -19,13 +30,79 @@ describe RightSignature::OauthConnection do
|
|
19
30
|
:access_token_path =>'/oauth/access_token',
|
20
31
|
:request_token_path=>'/oauth/request_token'
|
21
32
|
}).and_return(@consumer_mock)
|
33
|
+
RightSignature::OauthConnection.oauth_consumer.should == @consumer_mock
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "access_token" do
|
38
|
+
after do
|
39
|
+
# Reset caching of oauth_consumer
|
40
|
+
RightSignature::OauthConnection.instance_variable_set("@access_token", nil)
|
41
|
+
RightSignature::OauthConnection.instance_variable_set("@oauth_consumer", nil)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should raise error if access_token is not set" do
|
45
|
+
RightSignature::configuration = {:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_secret => "Secret098"}
|
46
|
+
lambda{RightSignature::OauthConnection.access_token}.should raise_error(Exception, "Please set load_configuration with consumer_key, consumer_secret, access_token, access_secret")
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should raise error if access_secret is not set" do
|
50
|
+
RightSignature::configuration = {:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098"}
|
51
|
+
lambda{RightSignature::OauthConnection.access_token}.should raise_error(Exception, "Please set load_configuration with consumer_key, consumer_secret, access_token, access_secret")
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should create OAuth access token with credentials" do
|
55
|
+
RightSignature::configuration = {:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"}
|
56
|
+
OAuth::Consumer.should_receive(:new).and_return(@consumer_mock)
|
22
57
|
OAuth::AccessToken.should_receive(:new).with(@consumer_mock, 'AccessToken098', 'AccessSecret123')
|
23
58
|
|
24
59
|
RightSignature::OauthConnection.access_token
|
25
60
|
end
|
61
|
+
|
62
|
+
describe "set_access_token" do
|
63
|
+
it "should create new access_token with given token and secret" do
|
64
|
+
OAuth::Consumer.stub(:new).and_return(@consumer_mock)
|
65
|
+
OAuth::AccessToken.should_receive(:new).with(@consumer_mock, "newAToken", "newASecret").and_return(@access_token_mock)
|
66
|
+
|
67
|
+
RightSignature::OauthConnection.set_access_token("newAToken","newASecret")
|
68
|
+
RightSignature::OauthConnection.access_token.should == @access_token_mock
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "new_request_token" do
|
74
|
+
it "should generate new RequestToken from consumer" do
|
75
|
+
request_mock = mock(OAuth::RequestToken)
|
76
|
+
OAuth::Consumer.stub(:new).and_return(@consumer_mock)
|
77
|
+
@consumer_mock.should_receive(:get_request_token).and_return(request_mock)
|
78
|
+
RightSignature::OauthConnection.new_request_token
|
79
|
+
RightSignature::OauthConnection.request_token.should == request_mock
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "generate_access_token" do
|
84
|
+
it "should raise error if there is no request_token" do
|
85
|
+
# Reset request_token cache"
|
86
|
+
RightSignature::OauthConnection.instance_variable_set("@request_token", nil)
|
87
|
+
lambda{RightSignature::OauthConnection.generate_access_token("verifi123")}.should raise_error(Exception, "Please set request token with new_request_token")
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should get access token from request token with given verifier" do
|
91
|
+
request_token_mock = mock(OAuth::RequestToken)
|
92
|
+
request_token_mock.should_receive(:get_access_token).with({:oauth_verifier => "verifi123"}).and_return(@access_token_mock)
|
93
|
+
RightSignature::OauthConnection.instance_variable_set("@request_token", request_token_mock)
|
94
|
+
|
95
|
+
RightSignature::OauthConnection.generate_access_token("verifi123")
|
96
|
+
RightSignature::OauthConnection.access_token.should == @access_token_mock
|
97
|
+
end
|
26
98
|
end
|
27
99
|
|
28
100
|
describe "request" do
|
101
|
+
it "should raise error if no configuration is set" do
|
102
|
+
RightSignature::configuration = {}
|
103
|
+
lambda{RightSignature::OauthConnection.request(:get, "path", {"User-Agent" => 'My own'})}.should raise_error(Exception, "Please set load_configuration with consumer_key, consumer_secret, access_token, access_secret")
|
104
|
+
end
|
105
|
+
|
29
106
|
it "should create GET request with access token and path with custom headers as 3rd argument" do
|
30
107
|
@access_token_mock.should_receive(:get).with('path', {"User-Agent" => 'My own', "Accept"=>"*/*", "content-type"=>"application/xml"})
|
31
108
|
RightSignature::OauthConnection.stub(:access_token).and_return(@access_token_mock)
|
data/spec/template_spec.rb
CHANGED
@@ -301,10 +301,10 @@ describe RightSignature::Template do
|
|
301
301
|
]
|
302
302
|
}}).and_return(@sent_document_response)
|
303
303
|
RightSignature::Connection.should_receive(:get).with("/api/documents/ABCDEFGH123/signer_links.xml", {}).and_return({"document" => {
|
304
|
-
"signer_links" => [
|
305
|
-
{"
|
306
|
-
{"
|
307
|
-
]
|
304
|
+
"signer_links" => {"signer_link" => [
|
305
|
+
{"name" => "John Bellingham", "role" => "signer_A", "signer_token" => "slkfj2"},
|
306
|
+
{"name" => "Tim Else", "role" => "signer_B", "signer_token" => "asfd1"}
|
307
|
+
]}
|
308
308
|
}})
|
309
309
|
|
310
310
|
|
@@ -331,10 +331,10 @@ describe RightSignature::Template do
|
|
331
331
|
]
|
332
332
|
}}).and_return(@sent_document_response)
|
333
333
|
RightSignature::Connection.should_receive(:get).with("/api/documents/ABCDEFGH123/signer_links.xml", {}).and_return({"document" => {
|
334
|
-
"signer_links" => [
|
335
|
-
{"
|
336
|
-
{"
|
337
|
-
]
|
334
|
+
"signer_links" => {"signer_link" => [
|
335
|
+
{"name" => "John Bellingham", "email" => "dontchange@example.com", "role" => "signer_A", "signer_token" => "slkfj2"},
|
336
|
+
{"name" => "Tim Else", "role" => "signer_B", "signer_token" => "asfd1"}
|
337
|
+
]}
|
338
338
|
}})
|
339
339
|
|
340
340
|
results = RightSignature::Template.send_as_embedded_signers("TGUID", [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rightsignature
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-09-
|
14
|
+
date: 2012-09-28 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|