api-client 2.3.0 → 2.4.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/CHANGELOG.md +5 -0
- data/api-client.gemspec +2 -0
- data/examples/controllers/book_controller.rb +45 -0
- data/examples/controllers/user_controller.rb +3 -3
- data/lib/api-client/base.rb +23 -1
- data/lib/api-client/class_methods.rb +5 -7
- data/lib/api-client/collection.rb +3 -2
- data/lib/api-client/configuration.rb +19 -3
- data/lib/api-client/dispatcher/net-http.rb +16 -18
- data/lib/api-client/exceptions.rb +6 -6
- data/lib/api-client/exceptions/{not_configured.rb → badly_configured.rb} +3 -3
- data/lib/api-client/instance_methods.rb +5 -5
- data/lib/api-client/version.rb +1 -1
- data/spec/api-client/base_spec.rb +27 -1
- data/spec/api-client/class_methods_spec.rb +3 -3
- data/spec/api-client/collection_spec.rb +1 -1
- data/spec/api-client/configuration_spec.rb +14 -4
- data/spec/api-client/instance_methods_spec.rb +3 -0
- metadata +9 -6
data/CHANGELOG.md
CHANGED
data/api-client.gemspec
CHANGED
@@ -13,6 +13,8 @@ Gem::Specification.new do |gem|
|
|
13
13
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
14
14
|
gem.require_paths = %w(lib)
|
15
15
|
|
16
|
+
gem.license = 'MIT'
|
17
|
+
|
16
18
|
gem.add_development_dependency 'rake'
|
17
19
|
gem.add_development_dependency 'webmock'
|
18
20
|
gem.add_development_dependency 'rspec'
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# It will works with respond_with.
|
2
|
+
# Your action should looks like any other one: A model with a method call. =D
|
3
|
+
class BookController < ApplicationController
|
4
|
+
# It will hit http://api.example.com/books with a get request
|
5
|
+
def index
|
6
|
+
@books = Book.all
|
7
|
+
respond_with(@books)
|
8
|
+
end
|
9
|
+
|
10
|
+
# It will initialize a new object based on the attribute accessors
|
11
|
+
def new
|
12
|
+
@book = Book.new
|
13
|
+
respond_with(@book)
|
14
|
+
end
|
15
|
+
|
16
|
+
# It will hit http://api.example.com/books with a post request
|
17
|
+
def create
|
18
|
+
@book = Book.create(:book => params[:book])
|
19
|
+
respond_with(@user)
|
20
|
+
end
|
21
|
+
|
22
|
+
# It will hit http://api.example.com/books/1 with a get request
|
23
|
+
def edit
|
24
|
+
@book = Book.find(params[:id])
|
25
|
+
respond_with(@book)
|
26
|
+
end
|
27
|
+
|
28
|
+
# It will hit http://api.example.com/books with a put request
|
29
|
+
def update
|
30
|
+
@book = Book.update_attributes({ :book => params[:book] })
|
31
|
+
respond_with(@book)
|
32
|
+
end
|
33
|
+
|
34
|
+
# It will hit http://api.example.com/books/1 with a get request
|
35
|
+
def show
|
36
|
+
@book = Book.find(params[:id])
|
37
|
+
respond_with(@book)
|
38
|
+
end
|
39
|
+
|
40
|
+
# It will hit http://api.example.com/books/1 with a delete request
|
41
|
+
def delete
|
42
|
+
@book = Book.destroy(params[:id])
|
43
|
+
respond_with(@book)
|
44
|
+
end
|
45
|
+
end
|
@@ -15,7 +15,7 @@ class UserController < ApplicationController
|
|
15
15
|
|
16
16
|
# It will hit http://api.example.com/users with a post request
|
17
17
|
def create
|
18
|
-
@user = User.post(:user => params[:user])
|
18
|
+
@user = User.post({ :user => params[:user] })
|
19
19
|
respond_with(@user)
|
20
20
|
end
|
21
21
|
|
@@ -25,9 +25,9 @@ class UserController < ApplicationController
|
|
25
25
|
respond_with(@user)
|
26
26
|
end
|
27
27
|
|
28
|
-
# It will hit http://api.example.com/users
|
28
|
+
# It will hit http://api.example.com/users with a patch request
|
29
29
|
def update
|
30
|
-
@user = User.patch(
|
30
|
+
@user = User.patch({ :user => params[:user] })
|
31
31
|
respond_with(@user)
|
32
32
|
end
|
33
33
|
|
data/lib/api-client/base.rb
CHANGED
@@ -42,6 +42,28 @@ module ApiClient
|
|
42
42
|
false
|
43
43
|
end
|
44
44
|
|
45
|
+
|
46
|
+
# Return the api name to be used by this model.
|
47
|
+
#
|
48
|
+
# @return [False] return the default api name.
|
49
|
+
def self.path
|
50
|
+
@path || :default
|
51
|
+
end
|
52
|
+
|
53
|
+
# Return the api name to be used by this model.
|
54
|
+
#
|
55
|
+
# @return [False] return the default api name.
|
56
|
+
def self.path=(path)
|
57
|
+
@path = path.to_sym
|
58
|
+
end
|
59
|
+
|
60
|
+
# Return the api name to be used by this model.
|
61
|
+
#
|
62
|
+
# @return [False] return the default api name.
|
63
|
+
def path
|
64
|
+
self.class.path
|
65
|
+
end
|
66
|
+
|
45
67
|
# Return the resource path of the object on the api url.
|
46
68
|
#
|
47
69
|
# @return [String] the resource path on the api for this object.
|
@@ -129,7 +151,7 @@ module ApiClient
|
|
129
151
|
# @param [String] url to get the collection.
|
130
152
|
# @return [Collection] a collection of objects.
|
131
153
|
def self.collection
|
132
|
-
ApiClient::Collection.new(self, self.resource_path).collection
|
154
|
+
ApiClient::Collection.new(self, self.path, self.resource_path).collection
|
133
155
|
end
|
134
156
|
|
135
157
|
class << self
|
@@ -18,7 +18,7 @@ module ApiClient
|
|
18
18
|
# @return [Base] the object initialized.
|
19
19
|
def get(id, header = {})
|
20
20
|
return build(:id => id) if ApiClient.config.mock
|
21
|
-
url = "#{ApiClient.config.path}#{self.resource_path}/#{id}"
|
21
|
+
url = "#{ApiClient.config.path[path]}#{self.resource_path}/#{id}"
|
22
22
|
response = ApiClient::Dispatcher.get(url, header)
|
23
23
|
params = ApiClient::Parser.response(response, url)
|
24
24
|
build(params)
|
@@ -33,7 +33,7 @@ module ApiClient
|
|
33
33
|
# @return [Base] the object initialized.
|
34
34
|
def post(attributes, header = {})
|
35
35
|
return build(attributes) if ApiClient.config.mock
|
36
|
-
url = "#{ApiClient.config.path}#{self.resource_path}"
|
36
|
+
url = "#{ApiClient.config.path[path]}#{self.resource_path}"
|
37
37
|
response = ApiClient::Dispatcher.post(url, attributes, header)
|
38
38
|
params = ApiClient::Parser.response(response, url)
|
39
39
|
build(params)
|
@@ -43,13 +43,12 @@ module ApiClient
|
|
43
43
|
|
44
44
|
# Make a put requisition and initialize an object with the response.
|
45
45
|
#
|
46
|
-
# @param [Integer] id id of the object.
|
47
46
|
# @param [Hash] attributes hash with the attributes to send.
|
48
47
|
# @param [Hash] header hash with the header options.
|
49
48
|
# @return [Base] the object initialized.
|
50
49
|
def put(attributes, header = {})
|
51
50
|
return build(attributes) if ApiClient.config.mock
|
52
|
-
url = "#{ApiClient.config.path}#{self.resource_path}"
|
51
|
+
url = "#{ApiClient.config.path[path]}#{self.resource_path}"
|
53
52
|
response = ApiClient::Dispatcher.put(url, attributes, header)
|
54
53
|
params = ApiClient::Parser.response(response, url)
|
55
54
|
build(params)
|
@@ -59,13 +58,12 @@ module ApiClient
|
|
59
58
|
|
60
59
|
# Make a patch requisition and initialize an object with the response.
|
61
60
|
#
|
62
|
-
# @param [Integer] id id of the object.
|
63
61
|
# @param [Hash] attributes hash with the attributes to send.
|
64
62
|
# @param [Hash] header hash with the header options.
|
65
63
|
# @return [Base] the object initialized.
|
66
64
|
def patch(attributes, header = {})
|
67
65
|
return build(attributes) if ApiClient.config.mock
|
68
|
-
url = "#{ApiClient.config.path}#{self.resource_path}"
|
66
|
+
url = "#{ApiClient.config.path[path]}#{self.resource_path}"
|
69
67
|
response = ApiClient::Dispatcher.patch(url, attributes, header)
|
70
68
|
params = ApiClient::Parser.response(response, url)
|
71
69
|
build(params)
|
@@ -78,7 +76,7 @@ module ApiClient
|
|
78
76
|
# @return [Base] the object initialized.
|
79
77
|
def delete(id, header = {})
|
80
78
|
return build(:id => id) if ApiClient.config.mock
|
81
|
-
url = "#{ApiClient.config.path}#{self.resource_path}/#{id}"
|
79
|
+
url = "#{ApiClient.config.path[path]}#{self.resource_path}/#{id}"
|
82
80
|
response = ApiClient::Dispatcher.delete(url, header)
|
83
81
|
params = ApiClient::Parser.response(response, url)
|
84
82
|
build(params)
|
@@ -7,10 +7,11 @@ class ApiClient::Collection
|
|
7
7
|
# Initialize a collection of given objects
|
8
8
|
#
|
9
9
|
# @param [Class] klass The class to instantiate the objects.
|
10
|
+
# @param [String] path The url of the api.
|
10
11
|
# @param [String] resource_path The url to get the data.
|
11
12
|
# @return [Collection] the collection of objects.
|
12
|
-
def initialize(klass, resource_path)
|
13
|
-
url = "#{ApiClient.config.path}#{resource_path}"
|
13
|
+
def initialize(klass, path, resource_path)
|
14
|
+
url = "#{ApiClient.config.path[path]}#{resource_path}"
|
14
15
|
@collection = ApiClient::Parser.response(ApiClient::Dispatcher.get(url), url)
|
15
16
|
@collection.map! do |attributes|
|
16
17
|
klass.new(attributes)
|
@@ -8,8 +8,10 @@ module ApiClient
|
|
8
8
|
#
|
9
9
|
# @return [String] the api url.
|
10
10
|
def path
|
11
|
-
|
12
|
-
|
11
|
+
@paths.each do |name, path|
|
12
|
+
raise Exceptions::BadlyConfigured.new(name) unless path.size > 1
|
13
|
+
end
|
14
|
+
@paths
|
13
15
|
end
|
14
16
|
|
15
17
|
# Set the api url.
|
@@ -17,7 +19,21 @@ module ApiClient
|
|
17
19
|
# @param [String] path api url.
|
18
20
|
def path=(path)
|
19
21
|
path = "#{path}/" unless path[path.size - 1, 1] == '/'
|
20
|
-
@
|
22
|
+
@paths = { :default => path }
|
23
|
+
end
|
24
|
+
|
25
|
+
# Set several api urls.
|
26
|
+
#
|
27
|
+
# @param [Hash] hash with paths to api urls.
|
28
|
+
def paths=(paths = {})
|
29
|
+
@paths = {}
|
30
|
+
paths.each do |name, path|
|
31
|
+
if path[path.size - 1, 1] == '/'
|
32
|
+
@paths[name] = path
|
33
|
+
else
|
34
|
+
@paths[name] = "#{path}/"
|
35
|
+
end
|
36
|
+
end
|
21
37
|
end
|
22
38
|
|
23
39
|
# Set the default params of header.
|
@@ -9,8 +9,7 @@ module ApiClient::Dispatcher::NetHttp
|
|
9
9
|
# @param [Hash] header attributes of the request.
|
10
10
|
# @return [HTTP] the response object.
|
11
11
|
def self.get(url, header = {})
|
12
|
-
|
13
|
-
call { @http.get(@uri.request_uri, ApiClient.config.header.merge(header)) }
|
12
|
+
dispatch(:get, url, { :header => header })
|
14
13
|
end
|
15
14
|
|
16
15
|
# Make a post request and returns it.
|
@@ -20,8 +19,7 @@ module ApiClient::Dispatcher::NetHttp
|
|
20
19
|
# @param [Hash] header attributes of the request.
|
21
20
|
# @return [HTTP] the response object.
|
22
21
|
def self.post(url, args, header = {})
|
23
|
-
|
24
|
-
call { @http.post(@uri.request_uri, args.to_json, ApiClient.config.header.merge(header)) }
|
22
|
+
dispatch(:post, url, { :args => args, :header => header })
|
25
23
|
end
|
26
24
|
|
27
25
|
# Make a put request and returns it.
|
@@ -31,8 +29,7 @@ module ApiClient::Dispatcher::NetHttp
|
|
31
29
|
# @param [Hash] header attributes of the request.
|
32
30
|
# @return [HTTP] the response object.
|
33
31
|
def self.put(url, args, header = {})
|
34
|
-
|
35
|
-
call { @http.put(@uri.request_uri, args.to_json, ApiClient.config.header.merge(header)) }
|
32
|
+
dispatch(:put, url, { :args => args, :header => header })
|
36
33
|
end
|
37
34
|
|
38
35
|
# Make a patch request and returns it.
|
@@ -42,8 +39,7 @@ module ApiClient::Dispatcher::NetHttp
|
|
42
39
|
# @param [Hash] header attributes of the request.
|
43
40
|
# @return [HTTP] the response object.
|
44
41
|
def self.patch(url, args, header = {})
|
45
|
-
|
46
|
-
call { @http.patch(@uri.request_uri, args.to_json, ApiClient.config.header.merge(header)) }
|
42
|
+
dispatch(:patch, url, { :args => args, :header => header })
|
47
43
|
end
|
48
44
|
|
49
45
|
# Make a delete request and returns it.
|
@@ -52,22 +48,24 @@ module ApiClient::Dispatcher::NetHttp
|
|
52
48
|
# @param [Hash] header attributes of the request.
|
53
49
|
# @return [HTTP] the response object.
|
54
50
|
def self.delete(url, header = {})
|
55
|
-
|
56
|
-
call { @http.delete(@uri.request_uri, header) }
|
51
|
+
dispatch(:delete, url, { :header => header })
|
57
52
|
end
|
58
53
|
|
59
54
|
protected
|
60
55
|
|
61
|
-
def self.
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
def self.call
|
56
|
+
def self.dispatch(method, url, options = {})
|
57
|
+
args = options[:args].to_json if options[:args]
|
58
|
+
header = ApiClient.config.header.merge(options[:header])
|
59
|
+
uri = URI(url)
|
60
|
+
http = Net::HTTP.start(uri.host, uri.port)
|
67
61
|
begin
|
68
|
-
|
62
|
+
if args
|
63
|
+
http.send(method, uri.request_uri, args, header)
|
64
|
+
else
|
65
|
+
http.send(method, uri.request_uri, header)
|
66
|
+
end
|
69
67
|
rescue Errno::ECONNREFUSED
|
70
68
|
raise ApiClient::Exceptions::ConnectionRefused
|
71
69
|
end
|
72
70
|
end
|
73
|
-
end
|
71
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# Namespace for the ApiClient Exceptions.
|
2
2
|
module ApiClient::Exceptions
|
3
|
-
autoload :
|
4
|
-
autoload :
|
5
|
-
autoload :
|
3
|
+
autoload :BadGateway, 'api-client/exceptions/bad_gateway'
|
4
|
+
autoload :BadlyConfigured, 'api-client/exceptions/badly_configured'
|
5
|
+
autoload :ConnectionRefused, 'api-client/exceptions/connection_refused'
|
6
6
|
autoload :Forbidden, 'api-client/exceptions/forbidden'
|
7
|
+
autoload :Generic, 'api-client/exceptions/generic'
|
7
8
|
autoload :InternalServerError, 'api-client/exceptions/internal_server_error'
|
8
|
-
autoload :
|
9
|
+
autoload :NotFound, 'api-client/exceptions/not_found'
|
9
10
|
autoload :ServiceUnavailable, 'api-client/exceptions/service_unavailable'
|
10
|
-
autoload :
|
11
|
-
autoload :NotConfigured, 'api-client/exceptions/not_configured'
|
11
|
+
autoload :Unauthorized, 'api-client/exceptions/unauthorized'
|
12
12
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# Exception for requests where the full path is not properly configured.
|
2
|
-
class ApiClient::Exceptions::
|
2
|
+
class ApiClient::Exceptions::BadlyConfigured < StandardError
|
3
3
|
# Initialize a new exception.
|
4
4
|
#
|
5
5
|
# @return [NotConfigured] a new exception.
|
6
|
-
def self.initialize
|
7
|
-
super(
|
6
|
+
def self.initialize(name)
|
7
|
+
super("The api path #{name} is not properly configured!")
|
8
8
|
end
|
9
9
|
end
|
@@ -20,7 +20,7 @@ module ApiClient
|
|
20
20
|
# @return [Base] the object updated.
|
21
21
|
def get(header = {})
|
22
22
|
return update({}) if ApiClient.config.mock
|
23
|
-
url = "#{ApiClient.config.path}#{self.class.resource_path}/#{id}"
|
23
|
+
url = "#{ApiClient.config.path[path]}#{self.class.resource_path}/#{id}"
|
24
24
|
response = ApiClient::Dispatcher.get(url, header)
|
25
25
|
attributes = ApiClient::Parser.response(response, url)
|
26
26
|
update(attributes)
|
@@ -34,7 +34,7 @@ module ApiClient
|
|
34
34
|
# @return [Base] the object updated.
|
35
35
|
def post(header = {})
|
36
36
|
return update({}) if ApiClient.config.mock
|
37
|
-
url = "#{ApiClient.config.path}#{self.class.resource_path}"
|
37
|
+
url = "#{ApiClient.config.path[path]}#{self.class.resource_path}"
|
38
38
|
response = ApiClient::Dispatcher.post(url, self.to_hash, header)
|
39
39
|
attributes = ApiClient::Parser.response(response, url)
|
40
40
|
update(attributes)
|
@@ -48,7 +48,7 @@ module ApiClient
|
|
48
48
|
# @return [Base] the object updated.
|
49
49
|
def put(header = {})
|
50
50
|
return update({}) if ApiClient.config.mock
|
51
|
-
url = "#{ApiClient.config.path}#{self.class.resource_path}"
|
51
|
+
url = "#{ApiClient.config.path[path]}#{self.class.resource_path}"
|
52
52
|
response = ApiClient::Dispatcher.put(url, self.to_hash, header)
|
53
53
|
attributes = ApiClient::Parser.response(response, url)
|
54
54
|
update(attributes)
|
@@ -62,7 +62,7 @@ module ApiClient
|
|
62
62
|
# @return [Base] the object updated.
|
63
63
|
def patch(header = {})
|
64
64
|
return update({}) if ApiClient.config.mock
|
65
|
-
url = "#{ApiClient.config.path}#{self.class.resource_path}"
|
65
|
+
url = "#{ApiClient.config.path[path]}#{self.class.resource_path}"
|
66
66
|
response = ApiClient::Dispatcher.patch(url, self.to_hash, header)
|
67
67
|
attributes = ApiClient::Parser.response(response, url)
|
68
68
|
update(attributes)
|
@@ -74,7 +74,7 @@ module ApiClient
|
|
74
74
|
# @return [Base] the object updated.
|
75
75
|
def delete(header = {})
|
76
76
|
return update({}) if ApiClient.config.mock
|
77
|
-
url = "#{ApiClient.config.path}#{self.class.resource_path}/#{id}"
|
77
|
+
url = "#{ApiClient.config.path[path]}#{self.class.resource_path}/#{id}"
|
78
78
|
response = ApiClient::Dispatcher.delete(url, header)
|
79
79
|
attributes = ApiClient::Parser.response(response, url)
|
80
80
|
update(attributes)
|
data/lib/api-client/version.rb
CHANGED
@@ -116,6 +116,32 @@ describe ApiClient::Base do
|
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
|
+
describe '.path' do
|
120
|
+
it 'should return :default' do
|
121
|
+
User.path.should == :default
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe '.path=' do
|
126
|
+
before :each do
|
127
|
+
User.path = 'auth'
|
128
|
+
end
|
129
|
+
|
130
|
+
after :each do
|
131
|
+
User.path = 'default'
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'should set the name of the api to use' do
|
135
|
+
User.path.should == :auth
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe '#path' do
|
140
|
+
it 'should return :default' do
|
141
|
+
User.new.path.should == :default
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
119
145
|
describe '.associations=' do
|
120
146
|
before :each do
|
121
147
|
@group = Group.new(:members => [ :user => {:a => 'a'}], :owner => {:b => 'b'})
|
@@ -154,7 +180,7 @@ describe ApiClient::Base do
|
|
154
180
|
|
155
181
|
describe '.collection' do
|
156
182
|
before :each do
|
157
|
-
ApiClient::Collection.stub(:new).with(User, 'users').and_return(collection)
|
183
|
+
ApiClient::Collection.stub(:new).with(User, :default, 'users').and_return(collection)
|
158
184
|
collection.stub(:collection => [ user, user ])
|
159
185
|
end
|
160
186
|
|
@@ -55,19 +55,19 @@ describe ApiClient::ClassMethods do
|
|
55
55
|
|
56
56
|
context '.put' do
|
57
57
|
it 'should return an user' do
|
58
|
-
User.put(
|
58
|
+
User.put({}).should be_an_instance_of(User)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
62
|
context '.update_attributes' do
|
63
63
|
it 'should return an user' do
|
64
|
-
User.update_attributes(
|
64
|
+
User.update_attributes({}).should be_an_instance_of(User)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
context '.patch' do
|
69
69
|
it 'should return an user' do
|
70
|
-
User.patch(
|
70
|
+
User.patch({}).should be_an_instance_of(User)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -6,7 +6,7 @@ describe ApiClient::Collection do
|
|
6
6
|
before :each do
|
7
7
|
stub_request(:get, 'http://api.example.com/users').to_return(:body => [ { 'a' => 'b' }, { 'a' => 'b2' } ].to_json)
|
8
8
|
User.stub(:new => user)
|
9
|
-
@collection = ApiClient::Collection.new(User, 'users')
|
9
|
+
@collection = ApiClient::Collection.new(User, :default, 'users')
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'should include enumerable module' do
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe ApiClient::Configuration do
|
4
4
|
describe '#path' do
|
5
|
-
context 'when
|
5
|
+
context 'when badly configured' do
|
6
6
|
before :each do
|
7
7
|
ApiClient.configure do |config|
|
8
8
|
config.path = ''
|
@@ -10,7 +10,7 @@ describe ApiClient::Configuration do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'should raise an error' do
|
13
|
-
|
13
|
+
expect { ApiClient.config.path }.to raise_error(ApiClient::Exceptions::BadlyConfigured)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -34,7 +34,7 @@ describe ApiClient::Configuration do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should set it with a '/'" do
|
37
|
-
ApiClient.config.path.should == 'http://api.example.com/'
|
37
|
+
ApiClient.config.path.should == { :default => 'http://api.example.com/' }
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -44,11 +44,21 @@ describe ApiClient::Configuration do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should set it as passed" do
|
47
|
-
ApiClient.config.path.should == 'http://api.example.com/'
|
47
|
+
ApiClient.config.path.should == { :default => 'http://api.example.com/' }
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
+
describe '#paths=' do
|
53
|
+
before :each do
|
54
|
+
ApiClient.config.paths = { :auth => 'http://auth.example.com', :default => 'http://panel.example.com' }
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should set several paths in a hash' do
|
58
|
+
ApiClient.config.path.should == { :auth => 'http://auth.example.com/', :default => 'http://panel.example.com/' }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
52
62
|
describe '#header' do
|
53
63
|
context 'when not configured' do
|
54
64
|
it 'should return a hash with configs for content_type only' do
|
@@ -5,6 +5,9 @@ describe ApiClient::InstanceMethods do
|
|
5
5
|
|
6
6
|
context 'with mock equal false' do
|
7
7
|
before :each do
|
8
|
+
ApiClient.configure do |config|
|
9
|
+
config.path = 'http://api.example.com'
|
10
|
+
end
|
8
11
|
stub_request(:any, 'http://api.example.com/users').to_return(:body => {'a' => 'b'}.to_json)
|
9
12
|
stub_request(:any, 'http://api.example.com/users/1').to_return(:body => {'a' => 'b'}.to_json)
|
10
13
|
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: 2.
|
4
|
+
version: 2.4.0
|
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: 2013-
|
12
|
+
date: 2013-09-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- api-client.gemspec
|
143
143
|
- examples/config/initializers/api-client.rb
|
144
144
|
- examples/controllers/application_controller.rb
|
145
|
+
- examples/controllers/book_controller.rb
|
145
146
|
- examples/controllers/user_controller.rb
|
146
147
|
- examples/models/admin.rb
|
147
148
|
- examples/models/author.rb
|
@@ -162,11 +163,11 @@ files:
|
|
162
163
|
- lib/api-client/errors.rb
|
163
164
|
- lib/api-client/exceptions.rb
|
164
165
|
- lib/api-client/exceptions/bad_gateway.rb
|
166
|
+
- lib/api-client/exceptions/badly_configured.rb
|
165
167
|
- lib/api-client/exceptions/connection_refused.rb
|
166
168
|
- lib/api-client/exceptions/forbidden.rb
|
167
169
|
- lib/api-client/exceptions/generic.rb
|
168
170
|
- lib/api-client/exceptions/internal_server_error.rb
|
169
|
-
- lib/api-client/exceptions/not_configured.rb
|
170
171
|
- lib/api-client/exceptions/not_found.rb
|
171
172
|
- lib/api-client/exceptions/service_unavailable.rb
|
172
173
|
- lib/api-client/exceptions/unauthorized.rb
|
@@ -185,7 +186,8 @@ files:
|
|
185
186
|
- spec/api-client/parser_spec.rb
|
186
187
|
- spec/spec_helper.rb
|
187
188
|
homepage:
|
188
|
-
licenses:
|
189
|
+
licenses:
|
190
|
+
- MIT
|
189
191
|
post_install_message:
|
190
192
|
rdoc_options: []
|
191
193
|
require_paths:
|
@@ -198,7 +200,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
198
200
|
version: '0'
|
199
201
|
segments:
|
200
202
|
- 0
|
201
|
-
hash: -
|
203
|
+
hash: -3601308474644028566
|
202
204
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
203
205
|
none: false
|
204
206
|
requirements:
|
@@ -207,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
209
|
version: '0'
|
208
210
|
segments:
|
209
211
|
- 0
|
210
|
-
hash: -
|
212
|
+
hash: -3601308474644028566
|
211
213
|
requirements: []
|
212
214
|
rubyforge_project:
|
213
215
|
rubygems_version: 1.8.25
|
@@ -217,6 +219,7 @@ summary: Client to make Api calls
|
|
217
219
|
test_files:
|
218
220
|
- examples/config/initializers/api-client.rb
|
219
221
|
- examples/controllers/application_controller.rb
|
222
|
+
- examples/controllers/book_controller.rb
|
220
223
|
- examples/controllers/user_controller.rb
|
221
224
|
- examples/models/admin.rb
|
222
225
|
- examples/models/author.rb
|