api-client 1.5.0 → 1.5.1

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.
@@ -1,5 +1,5 @@
1
1
  # High Level Namespace of the library ApiClient.
2
2
  module ApiClient
3
3
  # Version of the library.
4
- VERSION = "1.5.0"
4
+ VERSION = "1.5.1"
5
5
  end
@@ -17,6 +17,26 @@ describe ApiClient::Base do
17
17
  end
18
18
  end
19
19
 
20
+ describe "#remote_object" do
21
+ context "on a class without remote object specification" do
22
+ it "should return the class name" do
23
+ User.remote_object.should == "user"
24
+ end
25
+ end
26
+
27
+ context "on a class with remote object specification" do
28
+ it "should return the class name" do
29
+ Admin.remote_object.should == "user"
30
+ end
31
+ end
32
+ end
33
+
34
+ describe "#remote_object=" do
35
+ it "should set the remote object name" do
36
+ Admin.remote_object.should == "user"
37
+ end
38
+ end
39
+
20
40
  describe "#persisted?" do
21
41
  it "should return false" do
22
42
  User.new.should_not be_persisted
@@ -1,53 +1,103 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ApiClient::Dispatcher do
4
- describe "#_get" do
4
+ describe "#get" do
5
5
  before :each do
6
6
  FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "200")
7
7
  end
8
8
 
9
- it "should return the response code and body" do
10
- ApiClient::Base._get("http://api.example.com/user/5", {}).should be_a(Net::HTTPOK)
9
+ it "should return the request" do
10
+ ApiClient::Dispatcher.get("http://api.example.com/user/5", {}).should be_a(Net::HTTPOK)
11
+ end
12
+
13
+ context "when connection is refused" do
14
+ before :each do
15
+ FakeWeb.register_uri(:get, "http://api.example.com/user/5", :exception => Errno::ECONNREFUSED)
16
+ end
17
+
18
+ it "should return a ConnectionRefused exception" do
19
+ lambda { ApiClient::Dispatcher.get('http://api.example.com/user/5') }.should raise_error(ApiClient::Exceptions::ConnectionRefused)
20
+ end
11
21
  end
12
22
  end
13
23
 
14
- describe "#_post" do
24
+ describe "#post" do
15
25
  before :each do
16
26
  FakeWeb.register_uri(:post, "http://api.example.com/user/5", :status => "201")
17
27
  end
18
28
 
19
- it "should return the response code and body" do
20
- ApiClient::Base._post("http://api.example.com/user/5", {}, {}).should be_a(Net::HTTPCreated)
29
+ it "should return the request" do
30
+ ApiClient::Dispatcher.post("http://api.example.com/user/5", {}, {}).should be_a(Net::HTTPCreated)
31
+ end
32
+
33
+ context "when connection is refused" do
34
+ before :each do
35
+ FakeWeb.register_uri(:post, "http://api.example.com/user/5", :exception => Errno::ECONNREFUSED)
36
+ end
37
+
38
+ it "should return a ConnectionRefused exception" do
39
+ lambda { ApiClient::Dispatcher.post('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::ConnectionRefused)
40
+ end
21
41
  end
22
42
  end
23
43
 
24
- describe "#_put" do
44
+ describe "#put" do
25
45
  before :each do
26
46
  FakeWeb.register_uri(:put, "http://api.example.com/user/5", :status => "200")
27
47
  end
28
48
 
29
- it "should return the response code and body" do
30
- ApiClient::Base._put("http://api.example.com/user/5", {}, {}).should be_a(Net::HTTPOK)
49
+ it "should return the request" do
50
+ ApiClient::Dispatcher.put("http://api.example.com/user/5", {}, {}).should be_a(Net::HTTPOK)
51
+ end
52
+
53
+ context "when connection is refused" do
54
+ before :each do
55
+ FakeWeb.register_uri(:put, "http://api.example.com/user/5", :exception => Errno::ECONNREFUSED)
56
+ end
57
+
58
+ it "should return a ConnectionRefused exception" do
59
+ lambda { ApiClient::Dispatcher.put('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::ConnectionRefused)
60
+ end
31
61
  end
32
62
  end
33
63
 
34
- describe "#_patch" do
64
+ describe "#patch" do
35
65
  before :each do
36
66
  FakeWeb.register_uri(:patch, "http://api.example.com/user/5", :status => "200")
37
67
  end
38
68
 
39
- it "should return the response code and body" do
40
- ApiClient::Base._patch("http://api.example.com/user/5", {}, {}).should be_a(Net::HTTPOK)
69
+ it "should return the request" do
70
+ ApiClient::Dispatcher.patch("http://api.example.com/user/5", {}, {}).should be_a(Net::HTTPOK)
71
+ end
72
+
73
+ context "when connection is refused" do
74
+ before :each do
75
+ FakeWeb.register_uri(:patch, "http://api.example.com/user/5", :exception => Errno::ECONNREFUSED)
76
+ end
77
+
78
+ it "should return a ConnectionRefused exception" do
79
+ lambda { ApiClient::Dispatcher.patch('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::ConnectionRefused)
80
+ end
41
81
  end
42
82
  end
43
83
 
44
- describe "#_delete" do
84
+ describe "#delete" do
45
85
  before :each do
46
86
  FakeWeb.register_uri(:delete, "http://api.example.com/user/5", :status => "200")
47
87
  end
48
88
 
49
- it "should return the response code and body" do
50
- ApiClient::Base._delete("http://api.example.com/user/5", {}).should be_a(Net::HTTPOK)
89
+ it "should return the request" do
90
+ ApiClient::Dispatcher.delete("http://api.example.com/user/5", {}).should be_a(Net::HTTPOK)
91
+ end
92
+
93
+ context "when connection is refused" do
94
+ before :each do
95
+ FakeWeb.register_uri(:delete, "http://api.example.com/user/5", :exception => Errno::ECONNREFUSED)
96
+ end
97
+
98
+ it "should return a ConnectionRefused exception" do
99
+ lambda { ApiClient::Dispatcher.delete('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::ConnectionRefused)
100
+ end
51
101
  end
52
102
  end
53
103
  end
@@ -1,14 +1,24 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ApiClient::Errors do
4
+ describe "#add_errors" do
5
+ before :each do
6
+ @errors = ApiClient::Errors.new(self).add_errors({:a => 'b'})
7
+ end
8
+
9
+ it "should initialize a new object" do
10
+ @errors[:a].should == 'b'
11
+ end
12
+ end
13
+
4
14
  describe "#unique_messages" do
5
15
  before :each do
6
16
  @user = User.new
7
17
  @user.valid?
8
18
  end
9
19
 
10
- it "should set #a" do
20
+ it "should set a unique message for each attribute" do
11
21
  @user.errors.unique_messages.should == { :a => "can't be blank and is not included in the list" }
12
22
  end
13
23
  end
14
- end
24
+ end
@@ -1,18 +1,22 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ApiClient::Parser do
4
- describe "#_response" do
4
+ describe "#response" do
5
+ before :each do
6
+ @remote_object = ApiClient::Base.remote_object
7
+ end
8
+
5
9
  context "with a valid json response" do
6
10
  context "without a root node" do
7
11
  before :each do
8
12
  FakeWeb.register_uri(:post, "http://api.example.com/user/5",
9
13
  :body => { :a => :b }.to_json,
10
14
  :status => "201")
11
- @response = ApiClient::Base._post('http://api.example.com/user/5', {}, {})
15
+ @response = ApiClient::Dispatcher.post('http://api.example.com/user/5', {}, {})
12
16
  end
13
17
 
14
18
  it "should return the response code and the body parsed" do
15
- ApiClient::Base._response(@response).should == ['201', { "a" => "b" }]
19
+ ApiClient::Parser.response(@response, @remote_object).should == { "a" => "b" }
16
20
  end
17
21
  end
18
22
 
@@ -21,11 +25,11 @@ describe ApiClient::Parser do
21
25
  FakeWeb.register_uri(:post, "http://api.example.com/user/5",
22
26
  :body => { :base => { :a => :b } }.to_json,
23
27
  :status => "201")
24
- @response = ApiClient::Base._post('http://api.example.com/user/5', {}, {})
28
+ @response = ApiClient::Dispatcher.post('http://api.example.com/user/5', {}, {})
25
29
  end
26
30
 
27
31
  it "should return the response code and the body parsed" do
28
- ApiClient::Base._response(@response).should == ['201', { "a" => "b" }]
32
+ ApiClient::Parser.response(@response, @remote_object).should == { "a" => "b" }
29
33
  end
30
34
  end
31
35
  end
@@ -35,32 +39,80 @@ describe ApiClient::Parser do
35
39
  FakeWeb.register_uri(:post, "http://api.example.com/user/5",
36
40
  :body => "wrong",
37
41
  :status => "201")
38
- @response = ApiClient::Base._post('http://api.example.com/user/5', {}, {})
42
+ @response = ApiClient::Dispatcher.post('http://api.example.com/user/5', {}, {})
39
43
  end
40
44
 
41
- it "should return the response code and a nil body" do
42
- ApiClient::Base._response(@response).should == ['201', nil]
45
+ it "should return the response code and an empty hash" do
46
+ ApiClient::Parser.response(@response, @remote_object).should == {}
43
47
  end
44
48
  end
45
- end
46
49
 
47
- describe "#remote_object" do
48
- context "on a class without remote object specification" do
49
- it "should return the class name" do
50
- User.remote_object.should == "user"
50
+ context "with a response code of" do
51
+ context "401" do
52
+ before :each do
53
+ FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "401")
54
+ @response = ApiClient::Dispatcher.get('http://api.example.com/user/5')
55
+ end
56
+
57
+ it "should return a Unauthorized exception" do
58
+ lambda { ApiClient::Parser.response(@response, @remote_object) }.should raise_error(ApiClient::Exceptions::Unauthorized)
59
+ end
51
60
  end
52
- end
53
61
 
54
- context "on a class with remote object specification" do
55
- it "should return the class name" do
56
- Admin.remote_object.should == "user"
62
+ context "403" do
63
+ before :each do
64
+ FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "403")
65
+ @response = ApiClient::Dispatcher.get('http://api.example.com/user/5')
66
+ end
67
+
68
+ it "should return a Forbidden exception" do
69
+ lambda { ApiClient::Parser.response(@response, @remote_object) }.should raise_error(ApiClient::Exceptions::Forbidden)
70
+ end
57
71
  end
58
- end
59
- end
60
72
 
61
- describe "#remote_object=" do
62
- it "should set the remote object name" do
63
- Admin.remote_object.should == "user"
73
+ context "404" do
74
+ before :each do
75
+ FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "404")
76
+ @response = ApiClient::Dispatcher.get('http://api.example.com/user/5')
77
+ end
78
+
79
+ it "should return a NotFound exception" do
80
+ lambda { ApiClient::Parser.response(@response, @remote_object) }.should raise_error(ApiClient::Exceptions::NotFound)
81
+ end
82
+ end
83
+
84
+ context "500" do
85
+ before :each do
86
+ FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "500")
87
+ @response = ApiClient::Dispatcher.get('http://api.example.com/user/5')
88
+ end
89
+
90
+ it "should return a InternalServerError exception" do
91
+ lambda { ApiClient::Parser.response(@response, @remote_object) }.should raise_error(ApiClient::Exceptions::InternalServerError)
92
+ end
93
+ end
94
+
95
+ context "502" do
96
+ before :each do
97
+ FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "502")
98
+ @response = ApiClient::Dispatcher.get('http://api.example.com/user/5')
99
+ end
100
+
101
+ it "should return a BadGateway exception" do
102
+ lambda { ApiClient::Parser.response(@response, @remote_object) }.should raise_error(ApiClient::Exceptions::BadGateway)
103
+ end
104
+ end
105
+
106
+ context "503" do
107
+ before :each do
108
+ FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "503")
109
+ @response = ApiClient::Dispatcher.get('http://api.example.com/user/5')
110
+ end
111
+
112
+ it "should return a ServiceUnavailable exception" do
113
+ lambda { ApiClient::Parser.response(@response, @remote_object) }.should raise_error(ApiClient::Exceptions::ServiceUnavailable)
114
+ end
115
+ end
64
116
  end
65
117
  end
66
118
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-16 00:00:00.000000000 Z
12
+ date: 2012-09-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -141,11 +141,6 @@ files:
141
141
  - lib/api-client/exceptions/unauthorized.rb
142
142
  - lib/api-client/parser.rb
143
143
  - lib/api-client/version.rb
144
- - spec/api-client/base/delete_spec.rb
145
- - spec/api-client/base/get_spec.rb
146
- - spec/api-client/base/patch_spec.rb
147
- - spec/api-client/base/post_spec.rb
148
- - spec/api-client/base/put_spec.rb
149
144
  - spec/api-client/base_spec.rb
150
145
  - spec/api-client/dispatcher_spec.rb
151
146
  - spec/api-client/errors_spec.rb
@@ -163,12 +158,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
158
  - - ! '>='
164
159
  - !ruby/object:Gem::Version
165
160
  version: '0'
161
+ segments:
162
+ - 0
163
+ hash: -3101266763150892507
166
164
  required_rubygems_version: !ruby/object:Gem::Requirement
167
165
  none: false
168
166
  requirements:
169
167
  - - ! '>='
170
168
  - !ruby/object:Gem::Version
171
169
  version: '0'
170
+ segments:
171
+ - 0
172
+ hash: -3101266763150892507
172
173
  requirements: []
173
174
  rubyforge_project:
174
175
  rubygems_version: 1.8.24
@@ -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 "#delete" do
7
- context "when connection is refused" do
8
- before :each do
9
- FakeWeb.register_uri(:delete, "http://api.example.com/user/5", :exception => Errno::ECONNREFUSED)
10
- end
11
-
12
- it "should return a ConnectionRefused exception" do
13
- lambda { ApiClient::Base.delete('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(:delete, "http://api.example.com/user/5", :status => "401")
20
- end
21
-
22
- it "should return a Unauthorized exception" do
23
- lambda { ApiClient::Base.delete('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(:delete, "http://api.example.com/user/5", :status => "403")
30
- end
31
-
32
- it "should return a Forbidden exception" do
33
- lambda { ApiClient::Base.delete('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(:delete, "http://api.example.com/user/5", :status => "404")
40
- end
41
-
42
- it "should return a NotFound exception" do
43
- lambda { ApiClient::Base.delete('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(:delete, "http://api.example.com/user/5", :status => "500")
50
- end
51
-
52
- it "should return a InternalServerError exception" do
53
- lambda { ApiClient::Base.delete('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(:delete, "http://api.example.com/user/5", :status => "502")
60
- end
61
-
62
- it "should return a BadGateway exception" do
63
- lambda { ApiClient::Base.delete('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(:delete, "http://api.example.com/user/5", :status => "503")
70
- end
71
-
72
- it "should return a ServiceUnavailable exception" do
73
- lambda { ApiClient::Base.delete('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(:delete, "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.delete('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(:delete, "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.delete('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(:delete, "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.delete('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(:delete, "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.delete('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(:delete, "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.delete('http://api.example.com/user/5', {}).should == [ user, user ]
130
- end
131
- end
132
- end
133
- end
134
- end