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.
- data/README.md +42 -44
- data/lib/rightsignature.rb +0 -49
- data/lib/rightsignature/account.rb +14 -16
- data/lib/rightsignature/connection.rb +116 -64
- data/lib/rightsignature/connection/oauth_connection.rb +65 -55
- data/lib/rightsignature/connection/token_connection.rb +16 -11
- data/lib/rightsignature/document.rb +217 -220
- data/lib/rightsignature/template.rb +217 -221
- data/lib/rightsignature/version.rb +1 -1
- data/spec/account_spec.rb +22 -22
- data/spec/api_token_connection_spec.rb +13 -10
- data/spec/configuration_spec.rb +42 -42
- data/spec/connection_spec.rb +91 -91
- data/spec/document_spec.rb +60 -60
- data/spec/oauth_connnection_spec.rb +39 -34
- data/spec/spec_helper.rb +1 -1
- data/spec/template_spec.rb +62 -62
- metadata +2 -2
data/spec/account_spec.rb
CHANGED
@@ -3,52 +3,52 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
|
|
3
3
|
describe RightSignature::Account do
|
4
4
|
describe "user_details" do
|
5
5
|
it "should GET /api/users/user_details.xml" do
|
6
|
-
|
7
|
-
|
6
|
+
@rs.should_receive(:get).with('/api/users/user_details.xml')
|
7
|
+
@rs.user_details
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "add_user" do
|
12
12
|
it "should POST /api/users.xml with user email and name in hash" do
|
13
|
-
|
14
|
-
|
13
|
+
@rs.should_receive(:post).with('/api/users.xml', {:user => {:name => "Jimmy Cricket", :email => "jimmy@example.com"}})
|
14
|
+
@rs.add_user("Jimmy Cricket", "jimmy@example.com")
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
describe "usage_report" do
|
19
19
|
it "should GET /api/account/usage_report.xml" do
|
20
|
-
|
21
|
-
|
20
|
+
@rs.should_receive(:get).with('/api/account/usage_report.xml', {})
|
21
|
+
@rs.usage_report
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should GET /api/account/usage_report.xml with acceptable param for :since" do
|
25
|
-
|
26
|
-
|
25
|
+
@rs.should_receive(:get).with('/api/account/usage_report.xml', {:since => "week"})
|
26
|
+
@rs.usage_report("week")
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
@rs.should_receive(:get).with('/api/account/usage_report.xml', {:since => "month"})
|
29
|
+
@rs.usage_report("month")
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
@rs.should_receive(:get).with('/api/account/usage_report.xml', {:since => "day"})
|
32
|
+
@rs.usage_report("day")
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
@rs.should_receive(:get).with('/api/account/usage_report.xml', {})
|
35
|
+
@rs.usage_report("1/4/90")
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should GET /api/account/usage_report.xml with param :signed" do
|
39
|
-
|
40
|
-
|
39
|
+
@rs.should_receive(:get).with('/api/account/usage_report.xml', {:signed => "true"})
|
40
|
+
@rs.usage_report(nil, true)
|
41
41
|
|
42
|
-
|
43
|
-
|
42
|
+
@rs.should_receive(:get).with('/api/account/usage_report.xml', {:signed => "false"})
|
43
|
+
@rs.usage_report(nil, false)
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should GET /api/account/usage_report.xml with params :since and :signed" do
|
47
|
-
|
48
|
-
|
47
|
+
@rs.should_receive(:get).with('/api/account/usage_report.xml', {:signed => "true"})
|
48
|
+
@rs.usage_report(nil, true)
|
49
49
|
|
50
|
-
|
51
|
-
|
50
|
+
@rs.should_receive(:get).with('/api/account/usage_report.xml', {:signed => "false"})
|
51
|
+
@rs.usage_report(nil, false)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -2,23 +2,26 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
|
|
2
2
|
|
3
3
|
describe RightSignature::TokenConnection do
|
4
4
|
it "should raise error if no configuration is set" do
|
5
|
-
|
6
|
-
lambda{
|
5
|
+
token_connection = RightSignature::TokenConnection.new('')
|
6
|
+
lambda{token_connection.request(:get, "path", {:query => {:search => 'hey there'}})}.should raise_error(Exception, "Please set api_token")
|
7
7
|
end
|
8
8
|
|
9
|
-
it "should create 'api-token'
|
10
|
-
RightSignature::TokenConnection.
|
11
|
-
|
9
|
+
it "should create 'api-token' in headers with :api_token credentials, accept of '*/*', and content-type of xml with given method" do
|
10
|
+
token_connection = RightSignature::TokenConnection.new('APITOKEN')
|
11
|
+
token_connection.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))
|
12
|
+
token_connection.request(:get, "path", {:query => {:search => 'hey there'}})
|
12
13
|
end
|
13
14
|
|
14
15
|
it "should add 'api-token' to headers with :api_token credentials, accept of '*/*', and content-type of xml with given method" do
|
15
|
-
RightSignature::TokenConnection.
|
16
|
-
|
16
|
+
token_connection = RightSignature::TokenConnection.new('APITOKEN')
|
17
|
+
token_connection.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))
|
18
|
+
token_connection.request(:get, "path", {:query => {:search => 'hey there'}, :headers => {:my_header => "someHeader"}})
|
17
19
|
end
|
18
20
|
|
19
|
-
it "should create 'api-token'
|
20
|
-
RightSignature::TokenConnection.
|
21
|
-
|
21
|
+
it "should create 'api-token' in headers with :api_token credentials, accept of '*/*', and content-type of xml to POST method" do
|
22
|
+
token_connection = RightSignature::TokenConnection.new('APITOKEN')
|
23
|
+
token_connection.should_receive(:post).with("path", {:body => {:document => {:roles => []}}, :headers => {"api-token" => "APITOKEN", "Accept" => "*/*", "content-type" => "application/xml"}}).and_return(stub("HTTPartyResponse", :parsed_response => nil))
|
24
|
+
token_connection.request(:post, "path", {:body => {:document => {:roles => []}}})
|
22
25
|
end
|
23
26
|
|
24
27
|
end
|
data/spec/configuration_spec.rb
CHANGED
@@ -1,98 +1,98 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../lib/rightsignature'
|
2
2
|
|
3
|
-
describe RightSignature
|
3
|
+
describe RightSignature do
|
4
4
|
describe "load_configuration" do
|
5
5
|
it "should load api_token into configurations[:api_token]" do
|
6
|
-
RightSignature::
|
7
|
-
|
6
|
+
rs = RightSignature::Connection.new(:api_token => "MyToken")
|
7
|
+
rs.configuration[:api_token].should == "MyToken"
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should load OAuth consumer key, consumer secret, access token and access secret" do
|
11
|
-
RightSignature::
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
rs = RightSignature::Connection.new(:consumer_key => "key", :consumer_secret => "secret", :access_token => "atoken", :access_secret => "asecret")
|
12
|
+
rs.configuration[:consumer_key].should == "key"
|
13
|
+
rs.configuration[:consumer_secret].should == "secret"
|
14
|
+
rs.configuration[:access_token].should == "atoken"
|
15
|
+
rs.configuration[:access_secret].should == "asecret"
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
describe "check_credentials" do
|
20
20
|
it "should raise error if configuration is not set" do
|
21
|
-
RightSignature::
|
22
|
-
lambda {
|
21
|
+
rs = RightSignature::Connection.new()
|
22
|
+
lambda {rs.check_credentials}.should raise_error
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should raise error if api_token is blank and oauth credentials are not set" do
|
26
|
-
RightSignature::
|
27
|
-
lambda {
|
26
|
+
rs = RightSignature::Connection.new(:api_token => " ")
|
27
|
+
lambda {rs.check_credentials}.should raise_error
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should raise error if consumer_key, consumer_secret, access_token, or access_secret is not set" do
|
31
|
-
RightSignature::
|
32
|
-
lambda {
|
31
|
+
rs = RightSignature::Connection.new(:consumer_secret => "secret", :access_token => "atoken", :access_secret => "asecret")
|
32
|
+
lambda {rs.check_credentials}.should raise_error
|
33
33
|
|
34
|
-
RightSignature::
|
35
|
-
lambda {
|
34
|
+
rs = RightSignature::Connection.new(:consumer_key => "key", :access_token => "atoken", :access_secret => "asecret")
|
35
|
+
lambda {rs.check_credentials}.should raise_error
|
36
36
|
|
37
|
-
RightSignature::
|
38
|
-
lambda {
|
37
|
+
rs = RightSignature::Connection.new(:consumer_key => "key", :consumer_secret => "secret", :access_secret => "asecret")
|
38
|
+
lambda {rs.check_credentials}.should raise_error
|
39
39
|
|
40
|
-
RightSignature::
|
41
|
-
lambda {
|
40
|
+
rs = RightSignature::Connection.new(:consumer_key => "key", :consumer_secret => "secret", :access_token => "atoken")
|
41
|
+
lambda {rs.check_credentials}.should raise_error
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should not raise error if consumer_key, consumer_secret, access_token, and access_secret is set" do
|
45
|
-
RightSignature::
|
46
|
-
|
45
|
+
rs = RightSignature::Connection.new(:consumer_key => "key", :consumer_secret => "secret", :access_token => "atoken", :access_secret => "asecret")
|
46
|
+
rs.check_credentials
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should not raise error if api_token is set" do
|
50
|
-
RightSignature::
|
51
|
-
|
50
|
+
rs = RightSignature::Connection.new(:api_token => "asdf")
|
51
|
+
rs.check_credentials
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
55
|
describe "has_api_token?" do
|
56
56
|
it "should be false if configuration is not set" do
|
57
|
-
RightSignature::
|
58
|
-
|
57
|
+
rs = RightSignature::Connection.new()
|
58
|
+
rs.has_api_token?.should be_false
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should be false if api_token is blank" do
|
62
|
-
RightSignature::
|
63
|
-
|
62
|
+
rs = RightSignature::Connection.new(:api_token => " ")
|
63
|
+
rs.has_api_token?.should be_false
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should be true if api_token is set" do
|
67
|
-
RightSignature::
|
68
|
-
|
67
|
+
rs = RightSignature::Connection.new(:api_token => "abc")
|
68
|
+
rs.has_api_token?.should be_true
|
69
69
|
end
|
70
70
|
|
71
71
|
end
|
72
72
|
|
73
73
|
describe "has_oauth_credentials?" do
|
74
74
|
it "should be false if configuration is not set" do
|
75
|
-
RightSignature::
|
76
|
-
|
75
|
+
rs = RightSignature::Connection.new()
|
76
|
+
rs.has_oauth_credentials?.should be_false
|
77
77
|
end
|
78
78
|
|
79
79
|
it "should be false if consumer_key, consumer_secret, access_token, or access_secret is not set" do
|
80
|
-
RightSignature::
|
81
|
-
|
80
|
+
rs = RightSignature::Connection.new(:consumer_secret => "secret", :access_token => "atoken", :access_secret => "asecret")
|
81
|
+
rs.has_oauth_credentials?.should be_false
|
82
82
|
|
83
|
-
RightSignature::
|
84
|
-
|
83
|
+
rs = RightSignature::Connection.new(:consumer_key => "key", :access_token => "atoken", :access_secret => "asecret")
|
84
|
+
rs.has_oauth_credentials?.should be_false
|
85
85
|
|
86
|
-
RightSignature::
|
87
|
-
|
86
|
+
rs = RightSignature::Connection.new(:consumer_key => "key", :consumer_secret => "secret", :access_secret => "asecret")
|
87
|
+
rs.has_oauth_credentials?.should be_false
|
88
88
|
|
89
|
-
RightSignature::
|
90
|
-
|
89
|
+
rs = RightSignature::Connection.new(:consumer_key => "key", :consumer_secret => "secret", :access_token => "atoken")
|
90
|
+
rs.has_oauth_credentials?.should be_false
|
91
91
|
end
|
92
92
|
|
93
93
|
it "should be true if consumer_key, consumer_secret, access_token, and access_secret is set" do
|
94
|
-
RightSignature::
|
95
|
-
|
94
|
+
rs = RightSignature::Connection.new(:consumer_key => "key", :consumer_secret => "secret", :access_token => "atoken", :access_secret => "asecret")
|
95
|
+
rs.has_oauth_credentials?.should be_true
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
data/spec/connection_spec.rb
CHANGED
@@ -10,58 +10,58 @@ describe RightSignature::Connection do
|
|
10
10
|
describe "GET" do
|
11
11
|
describe "connection method" do
|
12
12
|
it "should default to RightSignature::57 if no api_token was specified" do
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
@rs = RightSignature::Connection.new({:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
|
14
|
+
@rs.oauth_connection.should_receive(:request).and_return(@net_http_response)
|
15
|
+
@rs.get("/path")
|
16
16
|
end
|
17
17
|
|
18
|
-
it "should use
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
it "should use Token Connection if api_token was specified" do
|
19
|
+
@rs = RightSignature::Connection.new({:api_token => "APITOKEN", :consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
|
20
|
+
@rs.token_connection.should_receive(:request).and_return(@httparty_response)
|
21
|
+
@rs.get("/path")
|
22
22
|
end
|
23
23
|
|
24
|
-
it "should use
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
it "should use Token Connection if only api_token was specified" do
|
25
|
+
@rs = RightSignature::Connection.new({:api_token => "APITOKEN"})
|
26
|
+
@rs.token_connection.should_receive(:request).and_return(@httparty_response)
|
27
|
+
@rs.get("/path")
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should raise error if no configuration is set" do
|
32
|
-
|
33
|
-
lambda{
|
32
|
+
@rs = RightSignature::Connection.new({})
|
33
|
+
lambda{@rs.get("/path")}.should raise_error
|
34
34
|
end
|
35
35
|
|
36
36
|
describe "using OauthConnection" do
|
37
37
|
it "should append params into path alphabetically and URI escaped" do
|
38
|
-
|
38
|
+
@rs = RightSignature::Connection.new({:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
|
39
39
|
@net_http_response.stub(:body).and_return('<document><subject>My Subject</subject></document>')
|
40
|
-
|
41
|
-
|
40
|
+
@rs.oauth_connection.should_receive(:request).with(:get, "/path?page=1&q=search%20me", {}).and_return(@net_http_response)
|
41
|
+
@rs.get("/path", {:q => 'search me', :page => 1})
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should return converted response body from XML to hash" do
|
45
|
-
|
45
|
+
@rs = RightSignature::Connection.new({:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
|
46
46
|
response = Net::HTTPSuccess.new('1.1', 200, 'OK')
|
47
47
|
response.stub(:body).and_return('<document><subject>My Subject</subject></document>')
|
48
|
-
|
49
|
-
|
48
|
+
@rs.oauth_connection.should_receive(:request).with(:get, "/path?page=1&q=search%20me", {}).and_return(response)
|
49
|
+
@rs.get("/path", {:q => 'search me', :page => 1}).should == {'document' => {'subject' => "My Subject"}}
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
describe "using TokenConnection" do
|
54
54
|
it "should append params and header into query option and header option" do
|
55
|
-
|
56
|
-
|
57
|
-
|
55
|
+
@rs = RightSignature::Connection.new({:api_token => 'token'})
|
56
|
+
@rs.token_connection.should_receive(:request).with(:get, "/path", {:query => {:q => 'search me', :page => 1}, :headers => {"User-Agent" => "me"}}).and_return(@httparty_response)
|
57
|
+
@rs.get("/path", {:q => 'search me', :page => 1}, {"User-Agent" => "me"})
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should return converted parsed_response from response" do
|
61
|
-
|
61
|
+
@rs = RightSignature::Connection.new({:api_token => 'token'})
|
62
62
|
@httparty_response.should_receive(:parsed_response).and_return({'document' => {'subject' => "My Subject"}})
|
63
|
-
|
64
|
-
|
63
|
+
@rs.token_connection.stub(:request).and_return(@httparty_response)
|
64
|
+
@rs.get("/path", {:q => 'search me', :page => 1}).should == {'document' => {'subject' => "My Subject"}}
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
@@ -69,31 +69,31 @@ describe RightSignature::Connection do
|
|
69
69
|
describe "POST" do
|
70
70
|
describe "connection method" do
|
71
71
|
before do
|
72
|
-
RightSignature::
|
73
|
-
|
72
|
+
@rs = RightSignature::Connection.new({:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
|
73
|
+
@rs.token_connection.stub(:request => @net_http_response)
|
74
|
+
@rs.oauth_connection.stub(:request => @httparty_response)
|
74
75
|
end
|
75
76
|
|
76
|
-
it "should default to
|
77
|
-
|
78
|
-
|
79
|
-
RightSignature::Connection.post("/path")
|
77
|
+
it "should default to Oauth Connection if no api_token was specified" do
|
78
|
+
@rs.oauth_connection.should_receive(:request).and_return(@net_http_response)
|
79
|
+
@rs.post("/path")
|
80
80
|
end
|
81
81
|
|
82
|
-
it "should default to
|
83
|
-
|
84
|
-
|
85
|
-
|
82
|
+
it "should default to Token Connection if api_token was specified" do
|
83
|
+
@rs = RightSignature::Connection.new({:api_token => "APITOKEN", :consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
|
84
|
+
@rs.token_connection.should_receive(:request).and_return(@httparty_response)
|
85
|
+
@rs.post("/path")
|
86
86
|
end
|
87
87
|
|
88
|
-
it "should default to
|
89
|
-
|
90
|
-
|
91
|
-
|
88
|
+
it "should default to Token Connection if only api_token was specified" do
|
89
|
+
@rs = RightSignature::Connection.new({:api_token => "APITOKEN"})
|
90
|
+
@rs.token_connection.should_receive(:request).and_return(@httparty_response)
|
91
|
+
@rs.post("/path")
|
92
92
|
end
|
93
93
|
|
94
94
|
it "should raise error if no configuration is set" do
|
95
|
-
|
96
|
-
lambda{
|
95
|
+
@rs = RightSignature::Connection.new({})
|
96
|
+
lambda{@rs.post("/path")}.should raise_error
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
@@ -101,59 +101,59 @@ describe RightSignature::Connection do
|
|
101
101
|
describe "DELETE" do
|
102
102
|
describe "connection method" do
|
103
103
|
it "should default to RightSignature::57 if no api_token was specified" do
|
104
|
-
|
105
|
-
|
106
|
-
|
104
|
+
@rs = RightSignature::Connection.new({:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
|
105
|
+
@rs.oauth_connection.should_receive(:request).and_return(@net_http_response)
|
106
|
+
@rs.delete("/path")
|
107
107
|
end
|
108
108
|
|
109
|
-
it "should use
|
110
|
-
|
111
|
-
|
112
|
-
|
109
|
+
it "should use Token Connection if api_token was specified" do
|
110
|
+
@rs = RightSignature::Connection.new({:api_token => "APITOKEN", :consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
|
111
|
+
@rs.token_connection.should_receive(:request).and_return(@httparty_response)
|
112
|
+
@rs.delete("/path")
|
113
113
|
end
|
114
114
|
|
115
|
-
it "should use
|
116
|
-
|
117
|
-
|
118
|
-
|
115
|
+
it "should use Token Connection if only api_token was specified" do
|
116
|
+
@rs = RightSignature::Connection.new({:api_token => "APITOKEN"})
|
117
|
+
@rs.token_connection.should_receive(:request).and_return(@httparty_response)
|
118
|
+
@rs.delete("/path")
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
122
|
it "should raise error if no configuration is set" do
|
123
|
-
|
124
|
-
lambda{
|
123
|
+
@rs = RightSignature::Connection.new({})
|
124
|
+
lambda{@rs.delete("/path")}.should raise_error
|
125
125
|
end
|
126
126
|
|
127
127
|
describe "using OauthConnection" do
|
128
128
|
it "should return converted response body from XML to hash" do
|
129
|
-
|
129
|
+
@rs = RightSignature::Connection.new({:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
|
130
130
|
response = Net::HTTPSuccess.new('1.1', 200, 'OK')
|
131
131
|
response.stub(:body).and_return('<document><subject>My Subject</subject></document>')
|
132
|
-
|
133
|
-
|
132
|
+
@rs.oauth_connection.should_receive(:request).with(:delete, "/path", {}).and_return(response)
|
133
|
+
@rs.delete("/path").should == {'document' => {'subject' => "My Subject"}}
|
134
134
|
end
|
135
135
|
|
136
136
|
it "should pass headers" do
|
137
|
-
|
137
|
+
@rs = RightSignature::Connection.new({:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
|
138
138
|
response = Net::HTTPSuccess.new('1.1', 200, 'OK')
|
139
139
|
response.stub(:body).and_return('<document><subject>My Subject</subject></document>')
|
140
|
-
|
141
|
-
|
140
|
+
@rs.oauth_connection.should_receive(:request).with(:delete, "/path", {"User-Agent" => "custom"}).and_return(response)
|
141
|
+
@rs.delete("/path", {"User-Agent" => "custom"}).should == {'document' => {'subject' => "My Subject"}}
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
145
145
|
describe "using TokenConnection" do
|
146
146
|
it "should append headers into headers option" do
|
147
|
-
|
148
|
-
|
149
|
-
|
147
|
+
@rs = RightSignature::Connection.new({:api_token => 'token'})
|
148
|
+
@rs.token_connection.should_receive(:request).with(:delete, "/path", {:headers => {"User-Agent" => "me"}}).and_return(@httparty_response)
|
149
|
+
@rs.delete("/path", {"User-Agent" => "me"})
|
150
150
|
end
|
151
151
|
|
152
152
|
it "should return converted parsed_response from response" do
|
153
|
-
|
153
|
+
@rs = RightSignature::Connection.new({:api_token => 'token'})
|
154
154
|
@httparty_response.should_receive(:parsed_response).and_return({'document' => {'subject' => "My Subject"}})
|
155
|
-
|
156
|
-
|
155
|
+
@rs.token_connection.stub(:request).and_return(@httparty_response)
|
156
|
+
@rs.delete("/path").should == {'document' => {'subject' => "My Subject"}}
|
157
157
|
end
|
158
158
|
end
|
159
159
|
end
|
@@ -161,58 +161,58 @@ describe RightSignature::Connection do
|
|
161
161
|
describe "PUT" do
|
162
162
|
describe "connection method" do
|
163
163
|
it "should default to RightSignature::57 if no api_token was specified" do
|
164
|
-
|
165
|
-
|
166
|
-
|
164
|
+
@rs = RightSignature::Connection.new({:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
|
165
|
+
@rs.oauth_connection.should_receive(:request).and_return(@net_http_response)
|
166
|
+
@rs.get("/path")
|
167
167
|
end
|
168
168
|
|
169
|
-
it "should use
|
170
|
-
|
171
|
-
|
172
|
-
|
169
|
+
it "should use Token Connection if api_token was specified" do
|
170
|
+
@rs = RightSignature::Connection.new({:api_token => "APITOKEN", :consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
|
171
|
+
@rs.token_connection.should_receive(:request).and_return(@httparty_response)
|
172
|
+
@rs.put("/path")
|
173
173
|
end
|
174
174
|
|
175
|
-
it "should use
|
176
|
-
|
177
|
-
|
178
|
-
|
175
|
+
it "should use Token Connection if only api_token was specified" do
|
176
|
+
@rs = RightSignature::Connection.new({:api_token => "APITOKEN"})
|
177
|
+
@rs.token_connection.should_receive(:request).and_return(@httparty_response)
|
178
|
+
@rs.put("/path")
|
179
179
|
end
|
180
180
|
end
|
181
181
|
|
182
182
|
it "should raise error if no configuration is set" do
|
183
|
-
|
184
|
-
lambda{
|
183
|
+
@rs = RightSignature::Connection.new({})
|
184
|
+
lambda{@rs.put("/path")}.should raise_error
|
185
185
|
end
|
186
186
|
|
187
187
|
describe "using OauthConnection" do
|
188
188
|
it "should convert body into XML" do
|
189
|
-
|
189
|
+
@rs = RightSignature::Connection.new({:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
|
190
190
|
@net_http_response.stub(:body).and_return('<document><subject>My Subject</subject></document>')
|
191
|
-
|
192
|
-
|
191
|
+
@rs.oauth_connection.should_receive(:request).with(:put, "/path", "<document><something>else</something><page>1</page></document>", {}).and_return(@net_http_response)
|
192
|
+
@rs.put("/path", {:document => {:something => "else", :page => 1}})
|
193
193
|
end
|
194
194
|
|
195
195
|
it "should return converted response body from XML to hash" do
|
196
|
-
|
196
|
+
@rs = RightSignature::Connection.new({:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
|
197
197
|
response = Net::HTTPSuccess.new('1.1', 200, 'OK')
|
198
198
|
response.stub(:body).and_return('<document><subject>My Subject</subject></document>')
|
199
|
-
|
200
|
-
|
199
|
+
@rs.oauth_connection.should_receive(:request).with(:put, "/path", "<document><something>else</something><page>1</page></document>", {}).and_return(response)
|
200
|
+
@rs.put("/path", {:document => {:something => "else", :page => 1}}).should == {'document' => {'subject' => "My Subject"}}
|
201
201
|
end
|
202
202
|
end
|
203
203
|
|
204
204
|
describe "using TokenConnection" do
|
205
205
|
it "should append params and header into query option and header option" do
|
206
|
-
|
207
|
-
|
208
|
-
|
206
|
+
@rs = RightSignature::Connection.new({:api_token => 'token'})
|
207
|
+
@rs.token_connection.should_receive(:request).with(:put, "/path", {:body => "<document><something>else</something><page>1</page></document>", :headers => {"User-Agent" => "me"}}).and_return(@httparty_response)
|
208
|
+
@rs.put("/path", {:document => {:something => "else", :page => 1}}, {"User-Agent" => "me"})
|
209
209
|
end
|
210
210
|
|
211
211
|
it "should return converted parsed_response from response" do
|
212
|
-
|
212
|
+
@rs = RightSignature::Connection.new({:api_token => 'token'})
|
213
213
|
@httparty_response.should_receive(:parsed_response).and_return({'document' => {'subject' => "My Subject"}})
|
214
|
-
|
215
|
-
|
214
|
+
@rs.token_connection.stub(:request).and_return(@httparty_response)
|
215
|
+
@rs.put("/path", {:document => {:something => "else", :page => 1}}).should == {'document' => {'subject' => "My Subject"}}
|
216
216
|
end
|
217
217
|
end
|
218
218
|
end
|