api-client 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -1
- data/README.md +21 -11
- data/examples/controllers/user_controller.rb +1 -1
- data/examples/models/user.rb +4 -0
- data/lib/api-client/base.rb +56 -142
- data/lib/api-client/dispatcher.rb +19 -11
- data/lib/api-client/errors.rb +11 -2
- data/lib/api-client/parser.rb +15 -14
- data/lib/api-client/version.rb +1 -1
- data/spec/api-client/base_spec.rb +20 -0
- data/spec/api-client/dispatcher_spec.rb +65 -15
- data/spec/api-client/errors_spec.rb +12 -2
- data/spec/api-client/parser_spec.rb +74 -22
- metadata +8 -7
- data/spec/api-client/base/delete_spec.rb +0 -134
- data/spec/api-client/base/get_spec.rb +0 -134
- data/spec/api-client/base/patch_spec.rb +0 -134
- data/spec/api-client/base/post_spec.rb +0 -134
- data/spec/api-client/base/put_spec.rb +0 -134
@@ -1,134 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ApiClient::Base do
|
4
|
-
let(:user) { User.new(:a => "a", :b => "b") }
|
5
|
-
|
6
|
-
describe "#get" do
|
7
|
-
context "when connection is refused" do
|
8
|
-
before :each do
|
9
|
-
FakeWeb.register_uri(:get, "http://api.example.com/user/5", :exception => Errno::ECONNREFUSED)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should return a ConnectionRefused exception" do
|
13
|
-
lambda { ApiClient::Base.get('http://api.example.com/user/5') }.should raise_error(ApiClient::Exceptions::ConnectionRefused)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context "when response code is 401" do
|
18
|
-
before :each do
|
19
|
-
FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "401")
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should return a Unauthorized exception" do
|
23
|
-
lambda { ApiClient::Base.get('http://api.example.com/user/5') }.should raise_error(ApiClient::Exceptions::Unauthorized)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context "when response code is 403" do
|
28
|
-
before :each do
|
29
|
-
FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "403")
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should return a Forbidden exception" do
|
33
|
-
lambda { ApiClient::Base.get('http://api.example.com/user/5') }.should raise_error(ApiClient::Exceptions::Forbidden)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "when response code is 404" do
|
38
|
-
before :each do
|
39
|
-
FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "404")
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should return a NotFound exception" do
|
43
|
-
lambda { ApiClient::Base.get('http://api.example.com/user/5') }.should raise_error(ApiClient::Exceptions::NotFound)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context "when response code is 500" do
|
48
|
-
before :each do
|
49
|
-
FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "500")
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should return a InternalServerError exception" do
|
53
|
-
lambda { ApiClient::Base.get('http://api.example.com/user/5') }.should raise_error(ApiClient::Exceptions::InternalServerError)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context "when response code is 502" do
|
58
|
-
before :each do
|
59
|
-
FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "502")
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should return a BadGateway exception" do
|
63
|
-
lambda { ApiClient::Base.get('http://api.example.com/user/5') }.should raise_error(ApiClient::Exceptions::BadGateway)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context "when response code is 503" do
|
68
|
-
before :each do
|
69
|
-
FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "503")
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should return a ServiceUnavailable exception" do
|
73
|
-
lambda { ApiClient::Base.get('http://api.example.com/user/5') }.should raise_error(ApiClient::Exceptions::ServiceUnavailable)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context "when response code is 2xx" do
|
78
|
-
context "without any specifications" do
|
79
|
-
before :each do
|
80
|
-
FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "201", :body => '{"a": "a", "b": "b"}')
|
81
|
-
User.stub(:new).and_return(user)
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should return a object initialized with the response" do
|
85
|
-
User.get('http://api.example.com/user/5').should == user
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context "with a specified port" do
|
90
|
-
before :each do
|
91
|
-
FakeWeb.register_uri(:get, "http://api.example.com:3001/user/5", :status => "201", :body => '{"a": "a", "b": "b"}')
|
92
|
-
User.stub(:new).and_return(user)
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should return a object initialized with the response" do
|
96
|
-
User.get('http://api.example.com:3001/user/5', {}).should == user
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
context "with a specified remote object name" do
|
101
|
-
before :each do
|
102
|
-
FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "201", :body => '{"user": {"a": "a", "b": "b"} }')
|
103
|
-
Admin.stub(:new).and_return(user)
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should return a object initialized with the response" do
|
107
|
-
Admin.get('http://api.example.com/user/5', {}).should == user
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context "with a collection" do
|
112
|
-
before :each do
|
113
|
-
FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "201", :body => '{"users": [ {"a": "a", "b": "b"}, {"a": "a", "b": "b"} ] }')
|
114
|
-
User.stub(:new).and_return(user)
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should return a collection of objects initialized with the response" do
|
118
|
-
User.get('http://api.example.com/user/5', {}).should == [ user, user ]
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
context "with a collection and a specified remote object name" do
|
123
|
-
before :each do
|
124
|
-
FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "201", :body => '{"users": [ {"a": "a", "b": "b"}, {"a": "a", "b": "b"} ] }')
|
125
|
-
Admin.stub(:new).and_return(user)
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should return a collection of objects initialized with the response" do
|
129
|
-
Admin.get('http://api.example.com/user/5', {}).should == [ user, user ]
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
@@ -1,134 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ApiClient::Base do
|
4
|
-
let(:user) { User.new(:a => "a", :b => "b") }
|
5
|
-
|
6
|
-
describe "#patch" do
|
7
|
-
context "when connection is refused" do
|
8
|
-
before :each do
|
9
|
-
FakeWeb.register_uri(:patch, "http://api.example.com/user/5", :exception => Errno::ECONNREFUSED)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should return a ConnectionRefused exception" do
|
13
|
-
lambda { ApiClient::Base.patch('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::ConnectionRefused)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context "when response code is 401" do
|
18
|
-
before :each do
|
19
|
-
FakeWeb.register_uri(:patch, "http://api.example.com/user/5", :status => "401")
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should return a Unauthorized exception" do
|
23
|
-
lambda { ApiClient::Base.patch('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::Unauthorized)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context "when response code is 403" do
|
28
|
-
before :each do
|
29
|
-
FakeWeb.register_uri(:patch, "http://api.example.com/user/5", :status => "403")
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should return a Forbidden exception" do
|
33
|
-
lambda { ApiClient::Base.patch('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::Forbidden)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "when response code is 404" do
|
38
|
-
before :each do
|
39
|
-
FakeWeb.register_uri(:patch, "http://api.example.com/user/5", :status => "404")
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should return a NotFound exception" do
|
43
|
-
lambda { ApiClient::Base.patch('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::NotFound)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context "when response code is 500" do
|
48
|
-
before :each do
|
49
|
-
FakeWeb.register_uri(:patch, "http://api.example.com/user/5", :status => "500")
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should return a InternalServerError exception" do
|
53
|
-
lambda { ApiClient::Base.patch('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::InternalServerError)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context "when response code is 502" do
|
58
|
-
before :each do
|
59
|
-
FakeWeb.register_uri(:patch, "http://api.example.com/user/5", :status => "502")
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should return a BadGateway exception" do
|
63
|
-
lambda { ApiClient::Base.patch('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::BadGateway)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context "when response code is 503" do
|
68
|
-
before :each do
|
69
|
-
FakeWeb.register_uri(:patch, "http://api.example.com/user/5", :status => "503")
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should return a ServiceUnavailable exception" do
|
73
|
-
lambda { ApiClient::Base.patch('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::ServiceUnavailable)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context "when response code is 2xx" do
|
78
|
-
context "without any specifications" do
|
79
|
-
before :each do
|
80
|
-
FakeWeb.register_uri(:patch, "http://api.example.com/user/5", :status => "201", :body => '{"a": "a", "b": "b"}')
|
81
|
-
User.stub(:new).and_return(user)
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should return a object initialized with the response" do
|
85
|
-
User.patch('http://api.example.com/user/5', {}).should == user
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context "with a specified port" do
|
90
|
-
before :each do
|
91
|
-
FakeWeb.register_uri(:patch, "http://api.example.com:3001/user/5", :status => "201", :body => '{"a": "a", "b": "b"}')
|
92
|
-
User.stub(:new).and_return(user)
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should return a object initialized with the response" do
|
96
|
-
User.patch('http://api.example.com:3001/user/5', {}).should == user
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
context "with a specified remote object name" do
|
101
|
-
before :each do
|
102
|
-
FakeWeb.register_uri(:patch, "http://api.example.com/user/5", :status => "201", :body => '{"user": {"a": "a", "b": "b"} }')
|
103
|
-
Admin.stub(:new).and_return(user)
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should return a object initialized with the response" do
|
107
|
-
Admin.patch('http://api.example.com/user/5', {}).should == user
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context "with a collection" do
|
112
|
-
before :each do
|
113
|
-
FakeWeb.register_uri(:patch, "http://api.example.com/user/5", :status => "201", :body => '{"users": [ {"a": "a", "b": "b"}, {"a": "a", "b": "b"} ] }')
|
114
|
-
User.stub(:new).and_return(user)
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should return a collection of objects initialized with the response" do
|
118
|
-
User.patch('http://api.example.com/user/5', {}).should == [ user, user ]
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
context "with a collection and a specified remote object name" do
|
123
|
-
before :each do
|
124
|
-
FakeWeb.register_uri(:patch, "http://api.example.com/user/5", :status => "201", :body => '{"users": [ {"a": "a", "b": "b"}, {"a": "a", "b": "b"} ] }')
|
125
|
-
Admin.stub(:new).and_return(user)
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should return a collection of objects initialized with the response" do
|
129
|
-
Admin.patch('http://api.example.com/user/5', {}).should == [ user, user ]
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
@@ -1,134 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ApiClient::Base do
|
4
|
-
let(:user) { User.new(:a => "a", :b => "b") }
|
5
|
-
|
6
|
-
describe "#post" do
|
7
|
-
context "when connection is refused" do
|
8
|
-
before :each do
|
9
|
-
FakeWeb.register_uri(:post, "http://api.example.com/user/5", :exception => Errno::ECONNREFUSED)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should return a ConnectionRefused exception" do
|
13
|
-
lambda { ApiClient::Base.post('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::ConnectionRefused)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context "when response code is 401" do
|
18
|
-
before :each do
|
19
|
-
FakeWeb.register_uri(:post, "http://api.example.com/user/5", :status => "401")
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should return a Unauthorized exception" do
|
23
|
-
lambda { ApiClient::Base.post('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::Unauthorized)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context "when response code is 403" do
|
28
|
-
before :each do
|
29
|
-
FakeWeb.register_uri(:post, "http://api.example.com/user/5", :status => "403")
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should return a Forbidden exception" do
|
33
|
-
lambda { ApiClient::Base.post('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::Forbidden)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "when response code is 404" do
|
38
|
-
before :each do
|
39
|
-
FakeWeb.register_uri(:post, "http://api.example.com/user/5", :status => "404")
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should return a NotFound exception" do
|
43
|
-
lambda { ApiClient::Base.post('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::NotFound)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context "when response code is 500" do
|
48
|
-
before :each do
|
49
|
-
FakeWeb.register_uri(:post, "http://api.example.com/user/5", :status => "500")
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should return a InternalServerError exception" do
|
53
|
-
lambda { ApiClient::Base.post('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::InternalServerError)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context "when response code is 502" do
|
58
|
-
before :each do
|
59
|
-
FakeWeb.register_uri(:post, "http://api.example.com/user/5", :status => "502")
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should return a BadGateway exception" do
|
63
|
-
lambda { ApiClient::Base.post('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::BadGateway)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context "when response code is 503" do
|
68
|
-
before :each do
|
69
|
-
FakeWeb.register_uri(:post, "http://api.example.com/user/5", :status => "503")
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should return a ServiceUnavailable exception" do
|
73
|
-
lambda { ApiClient::Base.post('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::ServiceUnavailable)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context "when response code is 2xx" do
|
78
|
-
context "without a specified port" do
|
79
|
-
before :each do
|
80
|
-
FakeWeb.register_uri(:post, "http://api.example.com/user/5", :status => "201", :body => '{"a": "a", "b": "b"}')
|
81
|
-
User.stub(:new).and_return(user)
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should return a object initialized with the response" do
|
85
|
-
User.post('http://api.example.com/user/5', {}).should == user
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context "with a specified port" do
|
90
|
-
before :each do
|
91
|
-
FakeWeb.register_uri(:post, "http://api.example.com:3001/user/5", :status => "201", :body => '{"a": "a", "b": "b"}')
|
92
|
-
User.stub(:new).and_return(user)
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should return a object initialized with the response" do
|
96
|
-
User.post('http://api.example.com:3001/user/5', {}).should == user
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
context "with a specified remote object name" do
|
101
|
-
before :each do
|
102
|
-
FakeWeb.register_uri(:post, "http://api.example.com/user/5", :status => "201", :body => '{"user": {"a": "a", "b": "b"} }')
|
103
|
-
Admin.stub(:new).and_return(user)
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should return a object initialized with the response" do
|
107
|
-
Admin.post('http://api.example.com/user/5', {}).should == user
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context "with a collection" do
|
112
|
-
before :each do
|
113
|
-
FakeWeb.register_uri(:post, "http://api.example.com/user/5", :status => "201", :body => '{"users": [ {"a": "a", "b": "b"}, {"a": "a", "b": "b"} ] }')
|
114
|
-
User.stub(:new).and_return(user)
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should return a collection of objects initialized with the response" do
|
118
|
-
User.post('http://api.example.com/user/5', {}).should == [ user, user ]
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
context "with a collection and a specified remote object name" do
|
123
|
-
before :each do
|
124
|
-
FakeWeb.register_uri(:post, "http://api.example.com/user/5", :status => "201", :body => '{"users": [ {"a": "a", "b": "b"}, {"a": "a", "b": "b"} ] }')
|
125
|
-
Admin.stub(:new).and_return(user)
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should return a collection of objects initialized with the response" do
|
129
|
-
Admin.post('http://api.example.com/user/5', {}).should == [ user, user ]
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
@@ -1,134 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ApiClient::Base do
|
4
|
-
let(:user) { User.new(:a => "a", :b => "b") }
|
5
|
-
|
6
|
-
describe "#put" do
|
7
|
-
context "when connection is refused" do
|
8
|
-
before :each do
|
9
|
-
FakeWeb.register_uri(:put, "http://api.example.com/user/5", :exception => Errno::ECONNREFUSED)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should return a ConnectionRefused exception" do
|
13
|
-
lambda { ApiClient::Base.put('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::ConnectionRefused)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context "when response code is 401" do
|
18
|
-
before :each do
|
19
|
-
FakeWeb.register_uri(:put, "http://api.example.com/user/5", :status => "401")
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should return a Unauthorized exception" do
|
23
|
-
lambda { ApiClient::Base.put('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::Unauthorized)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context "when response code is 403" do
|
28
|
-
before :each do
|
29
|
-
FakeWeb.register_uri(:put, "http://api.example.com/user/5", :status => "403")
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should return a Forbidden exception" do
|
33
|
-
lambda { ApiClient::Base.put('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::Forbidden)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "when response code is 404" do
|
38
|
-
before :each do
|
39
|
-
FakeWeb.register_uri(:put, "http://api.example.com/user/5", :status => "404")
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should return a NotFound exception" do
|
43
|
-
lambda { ApiClient::Base.put('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::NotFound)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context "when response code is 500" do
|
48
|
-
before :each do
|
49
|
-
FakeWeb.register_uri(:put, "http://api.example.com/user/5", :status => "500")
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should return a InternalServerError exception" do
|
53
|
-
lambda { ApiClient::Base.put('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::InternalServerError)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context "when response code is 502" do
|
58
|
-
before :each do
|
59
|
-
FakeWeb.register_uri(:put, "http://api.example.com/user/5", :status => "502")
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should return a BadGateway exception" do
|
63
|
-
lambda { ApiClient::Base.put('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::BadGateway)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context "when response code is 503" do
|
68
|
-
before :each do
|
69
|
-
FakeWeb.register_uri(:put, "http://api.example.com/user/5", :status => "503")
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should return a ServiceUnavailable exception" do
|
73
|
-
lambda { ApiClient::Base.put('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::ServiceUnavailable)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context "when response code is 2xx" do
|
78
|
-
context "without a specified port" do
|
79
|
-
before :each do
|
80
|
-
FakeWeb.register_uri(:put, "http://api.example.com/user/5", :status => "201", :body => '{"a": "a", "b": "b"}')
|
81
|
-
User.stub(:new).and_return(user)
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should return a object initialized with the response" do
|
85
|
-
User.put('http://api.example.com/user/5', {}).should == user
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context "with any specifications" do
|
90
|
-
before :each do
|
91
|
-
FakeWeb.register_uri(:put, "http://api.example.com:3001/user/5", :status => "201", :body => '{"a": "a", "b": "b"}')
|
92
|
-
User.stub(:new).and_return(user)
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should return a object initialized with the response" do
|
96
|
-
User.put('http://api.example.com:3001/user/5', {}).should == user
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
context "with a specified remote object name" do
|
101
|
-
before :each do
|
102
|
-
FakeWeb.register_uri(:put, "http://api.example.com/user/5", :status => "201", :body => '{"user": {"a": "a", "b": "b"} }')
|
103
|
-
Admin.stub(:new).and_return(user)
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should return a object initialized with the response" do
|
107
|
-
Admin.put('http://api.example.com/user/5', {}).should == user
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context "with a collection" do
|
112
|
-
before :each do
|
113
|
-
FakeWeb.register_uri(:put, "http://api.example.com/user/5", :status => "201", :body => '{"users": [ {"a": "a", "b": "b"}, {"a": "a", "b": "b"} ] }')
|
114
|
-
User.stub(:new).and_return(user)
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should return a collection of objects initialized with the response" do
|
118
|
-
User.put('http://api.example.com/user/5', {}).should == [ user, user ]
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
context "with a collection and a specified remote object name" do
|
123
|
-
before :each do
|
124
|
-
FakeWeb.register_uri(:put, "http://api.example.com/user/5", :status => "201", :body => '{"users": [ {"a": "a", "b": "b"}, {"a": "a", "b": "b"} ] }')
|
125
|
-
Admin.stub(:new).and_return(user)
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should return a collection of objects initialized with the response" do
|
129
|
-
Admin.put('http://api.example.com/user/5', {}).should == [ user, user ]
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|