api-client 1.5.4 → 1.6.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/.travis.yml +5 -1
- data/CHANGELOG.md +2 -10
- data/README.md +0 -1
- data/api-client.gemspec +2 -2
- data/gemfiles/Gemfile.net_http +3 -0
- data/gemfiles/Gemfile.typhoeus +5 -0
- data/lib/api-client/dispatcher.rb +9 -68
- data/lib/api-client/dispatcher/net-http.rb +73 -0
- data/lib/api-client/dispatcher/typhoeus.rb +52 -0
- data/lib/api-client/net/http.rb +29 -0
- data/lib/api-client/parser.rb +9 -9
- data/lib/api-client/version.rb +1 -1
- data/spec/api-client/dispatcher_spec.rb +10 -76
- data/spec/api-client/parser_spec.rb +9 -15
- data/spec/spec_helper.rb +1 -1
- metadata +14 -3
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,16 +1,8 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
-
## v1.5.
|
3
|
+
## v1.5.1 to v1.5.4
|
4
4
|
|
5
|
-
*
|
6
|
-
|
7
|
-
## v1.5.2
|
8
|
-
|
9
|
-
* Fixed return from #add_errors.
|
10
|
-
|
11
|
-
## v1.5.1
|
12
|
-
|
13
|
-
* Fixed Error Setter for erros from an external API.
|
5
|
+
* Fixed Bug with errors from external API and self.
|
14
6
|
|
15
7
|
## v1.5.0
|
16
8
|
|
data/README.md
CHANGED
data/api-client.gemspec
CHANGED
@@ -10,12 +10,12 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.summary = %q{Client to make Api calls}
|
11
11
|
|
12
12
|
gem.files = `git ls-files`.split("\n")
|
13
|
-
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features, gemfiles}/*`.split("\n")
|
14
14
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
15
15
|
gem.require_paths = %w(lib)
|
16
16
|
|
17
17
|
gem.add_development_dependency "rake"
|
18
|
-
gem.add_development_dependency "
|
18
|
+
gem.add_development_dependency "webmock"
|
19
19
|
gem.add_development_dependency "rspec"
|
20
20
|
gem.add_development_dependency "yard"
|
21
21
|
|
@@ -1,72 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# ApiClient::Dispatcher provides methods to make requests using the native ruby library 'net/http'
|
1
|
+
# ApiClient::Dispatcher provides methods to make requests
|
4
2
|
module ApiClient::Dispatcher
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
# Make a post request and returns it.
|
16
|
-
#
|
17
|
-
# @param [String] url of the api request.
|
18
|
-
# @param [Hash] args attributes of object.
|
19
|
-
# @param [Hash] header attributes of the request.
|
20
|
-
# @return [HTTP] the response object.
|
21
|
-
def self.post(url, args, header = {})
|
22
|
-
initialize_connection(url)
|
23
|
-
call { @http.post(@uri.path, args.to_json, { 'Content-Type' => 'application/json' }.merge(header)) }
|
24
|
-
end
|
25
|
-
|
26
|
-
# Make a put request and returns it.
|
27
|
-
#
|
28
|
-
# @param [String] url of the api request.
|
29
|
-
# @param [Hash] args attributes of object.
|
30
|
-
# @param [Hash] header attributes of the request.
|
31
|
-
# @return [HTTP] the response object.
|
32
|
-
def self.put(url, args, header = {})
|
33
|
-
initialize_connection(url)
|
34
|
-
call { @http.put(@uri.path, args.to_json, { 'Content-Type' => 'application/json' }.merge(header)) }
|
35
|
-
end
|
36
|
-
|
37
|
-
# Make a patch request and returns it.
|
38
|
-
#
|
39
|
-
# @param [String] url of the api request.
|
40
|
-
# @param [Hash] args attributes of object.
|
41
|
-
# @param [Hash] header attributes of the request.
|
42
|
-
# @return [HTTP] the response object.
|
43
|
-
def self.patch(url, args, header = {})
|
44
|
-
initialize_connection(url)
|
45
|
-
call { @http.patch(@uri.path, args.to_json, { 'Content-Type' => 'application/json' }.merge(header)) }
|
46
|
-
end
|
47
|
-
|
48
|
-
# Make a delete request and returns it.
|
49
|
-
#
|
50
|
-
# @param [String] url of the api request.
|
51
|
-
# @param [Hash] header attributes of the request.
|
52
|
-
# @return [HTTP] the response object.
|
53
|
-
def self.delete(url, header = {})
|
54
|
-
initialize_connection(url)
|
55
|
-
call { @http.delete(@uri.path, header) }
|
56
|
-
end
|
57
|
-
|
58
|
-
protected
|
59
|
-
|
60
|
-
def self.initialize_connection(url = '')
|
61
|
-
@uri = URI(url)
|
62
|
-
@http = Net::HTTP.new(@uri.host, @uri.port)
|
63
|
-
end
|
64
|
-
|
65
|
-
def self.call
|
66
|
-
begin
|
67
|
-
yield
|
68
|
-
rescue Errno::ECONNREFUSED
|
69
|
-
raise ApiClient::Exceptions::ConnectionRefused
|
3
|
+
autoload :Typhoeus, 'api-client/dispatcher/typhoeus'
|
4
|
+
autoload :NetHttp, 'api-client/dispatcher/net-http'
|
5
|
+
|
6
|
+
def self.method_missing(method, *args)
|
7
|
+
if defined?(::Typhoeus)
|
8
|
+
Typhoeus.send(method, *args)
|
9
|
+
else
|
10
|
+
NetHttp.send(method, *args)
|
70
11
|
end
|
71
12
|
end
|
72
13
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "api-client/net/http" unless Net::HTTP.new("").respond_to?(:patch)
|
3
|
+
|
4
|
+
# ApiClient::Dispatcher provides methods to make requests using the native ruby library 'net/http'
|
5
|
+
module ApiClient::Dispatcher::NetHttp
|
6
|
+
# Make a get request and returns it.
|
7
|
+
#
|
8
|
+
# @param [String] url of the api request.
|
9
|
+
# @param [Hash] header attributes of the request.
|
10
|
+
# @return [HTTP] the response object.
|
11
|
+
def self.get(url, header = {})
|
12
|
+
initialize_connection(url)
|
13
|
+
call { @http.get(@uri.path, { 'Content-Type' => 'application/json' }.merge(header)) }
|
14
|
+
end
|
15
|
+
|
16
|
+
# Make a post request and returns it.
|
17
|
+
#
|
18
|
+
# @param [String] url of the api request.
|
19
|
+
# @param [Hash] args attributes of object.
|
20
|
+
# @param [Hash] header attributes of the request.
|
21
|
+
# @return [HTTP] the response object.
|
22
|
+
def self.post(url, args, header = {})
|
23
|
+
initialize_connection(url)
|
24
|
+
call { @http.post(@uri.path, args.to_json, { 'Content-Type' => 'application/json' }.merge(header)) }
|
25
|
+
end
|
26
|
+
|
27
|
+
# Make a put request and returns it.
|
28
|
+
#
|
29
|
+
# @param [String] url of the api request.
|
30
|
+
# @param [Hash] args attributes of object.
|
31
|
+
# @param [Hash] header attributes of the request.
|
32
|
+
# @return [HTTP] the response object.
|
33
|
+
def self.put(url, args, header = {})
|
34
|
+
initialize_connection(url)
|
35
|
+
call { @http.put(@uri.path, args.to_json, { 'Content-Type' => 'application/json' }.merge(header)) }
|
36
|
+
end
|
37
|
+
|
38
|
+
# Make a patch request and returns it.
|
39
|
+
#
|
40
|
+
# @param [String] url of the api request.
|
41
|
+
# @param [Hash] args attributes of object.
|
42
|
+
# @param [Hash] header attributes of the request.
|
43
|
+
# @return [HTTP] the response object.
|
44
|
+
def self.patch(url, args, header = {})
|
45
|
+
initialize_connection(url)
|
46
|
+
call { @http.patch(@uri.path, args.to_json, { 'Content-Type' => 'application/json' }.merge(header)) }
|
47
|
+
end
|
48
|
+
|
49
|
+
# Make a delete request and returns it.
|
50
|
+
#
|
51
|
+
# @param [String] url of the api request.
|
52
|
+
# @param [Hash] header attributes of the request.
|
53
|
+
# @return [HTTP] the response object.
|
54
|
+
def self.delete(url, header = {})
|
55
|
+
initialize_connection(url)
|
56
|
+
call { @http.delete(@uri.path, header) }
|
57
|
+
end
|
58
|
+
|
59
|
+
protected
|
60
|
+
|
61
|
+
def self.initialize_connection(url = '')
|
62
|
+
@uri = URI(url)
|
63
|
+
@http = Net::HTTP.new(@uri.host, @uri.port)
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.call
|
67
|
+
begin
|
68
|
+
yield
|
69
|
+
rescue Errno::ECONNREFUSED
|
70
|
+
raise ApiClient::Exceptions::ConnectionRefused
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'typhoeus'
|
2
|
+
|
3
|
+
# ApiClient::Dispatcher provides methods to make requests using typhoeus
|
4
|
+
module ApiClient::Dispatcher::Typhoeus
|
5
|
+
# Make a get request and returns it.
|
6
|
+
#
|
7
|
+
# @param [String] url of the api request.
|
8
|
+
# @param [Hash] header attributes of the request.
|
9
|
+
# @return [Typhoeus::Request] the response object.
|
10
|
+
def self.get(url, header = {})
|
11
|
+
::Typhoeus::Request.get(url, :headers => header)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Make a post request and returns it.
|
15
|
+
#
|
16
|
+
# @param [String] url of the api request.
|
17
|
+
# @param [Hash] args attributes of object.
|
18
|
+
# @param [Hash] header attributes of the request.
|
19
|
+
# @return [Typhoeus::Request] the response object.
|
20
|
+
def self.post(url, args, header = {})
|
21
|
+
::Typhoeus::Request.post(url, :params => args, :headers => header)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Make a put request and returns it.
|
25
|
+
#
|
26
|
+
# @param [String] url of the api request.
|
27
|
+
# @param [Hash] args attributes of object.
|
28
|
+
# @param [Hash] header attributes of the request.
|
29
|
+
# @return [Typhoeus::Request] the response object.
|
30
|
+
def self.put(url, args, header = {})
|
31
|
+
::Typhoeus::Request.put(url, :params => args, :headers => header)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Make a patch request and returns it.
|
35
|
+
#
|
36
|
+
# @param [String] url of the api request.
|
37
|
+
# @param [Hash] args attributes of object.
|
38
|
+
# @param [Hash] header attributes of the request.
|
39
|
+
# @return [Typhoeus::Request] the response object.
|
40
|
+
def self.patch(url, args, header = {})
|
41
|
+
::Typhoeus::Request.patch(url, :params => args, :headers => header)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Make a delete request and returns it.
|
45
|
+
#
|
46
|
+
# @param [String] url of the api request.
|
47
|
+
# @param [Hash] header attributes of the request.
|
48
|
+
# @return [Typhoeus::Request] the response object.
|
49
|
+
def self.delete(url, header = {})
|
50
|
+
::Typhoeus::Request.delete(url, :headers => header)
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Net
|
2
|
+
class HTTP
|
3
|
+
# Sends a PATCH request to the +path+ and gets a response,
|
4
|
+
# as an HTTPResponse object.
|
5
|
+
def patch(path, data, initheader = nil, dest = nil, &block) # :yield: +body_segment+
|
6
|
+
res = nil
|
7
|
+
request(Patch.new(path, initheader), data) {|r|
|
8
|
+
r.read_body dest, &block
|
9
|
+
res = r
|
10
|
+
}
|
11
|
+
unless @newimpl
|
12
|
+
res.value
|
13
|
+
return res, res.body
|
14
|
+
end
|
15
|
+
res
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
19
|
+
# PATCH method --- RFC5789
|
20
|
+
#
|
21
|
+
|
22
|
+
# See Net::HTTPGenericRequest for attributes and methods.
|
23
|
+
class Patch < HTTPRequest
|
24
|
+
METHOD = 'PATCH'
|
25
|
+
REQUEST_HAS_BODY = true
|
26
|
+
RESPONSE_HAS_BODY = true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/api-client/parser.rb
CHANGED
@@ -5,27 +5,27 @@ module ApiClient::Parser
|
|
5
5
|
# @param [HTTP] response HTTP object for the request.
|
6
6
|
# @return [Array] the code and the body parsed.
|
7
7
|
def self.response(response, remote_object)
|
8
|
+
raise_exception(response.code)
|
8
9
|
begin
|
9
10
|
object = JSON.parse(response.body)
|
10
11
|
object = object[remote_object] if object.key?(remote_object)
|
11
12
|
object = object[remote_object.pluralize] if object.key?(remote_object.pluralize)
|
12
|
-
rescue JSON::ParserError
|
13
|
+
rescue JSON::ParserError, TypeError
|
13
14
|
object = {}
|
14
15
|
end
|
15
|
-
raise_exception(response.code)
|
16
16
|
object
|
17
17
|
end
|
18
18
|
|
19
19
|
protected
|
20
20
|
|
21
21
|
def self.raise_exception(code)
|
22
|
-
case code
|
23
|
-
when
|
24
|
-
when
|
25
|
-
when
|
26
|
-
when
|
27
|
-
when
|
28
|
-
when
|
22
|
+
case code.to_i
|
23
|
+
when 401 then raise ApiClient::Exceptions::Unauthorized
|
24
|
+
when 403 then raise ApiClient::Exceptions::Forbidden
|
25
|
+
when 404 then raise ApiClient::Exceptions::NotFound
|
26
|
+
when 500 then raise ApiClient::Exceptions::InternalServerError
|
27
|
+
when 502 then raise ApiClient::Exceptions::BadGateway
|
28
|
+
when 503 then raise ApiClient::Exceptions::ServiceUnavailable
|
29
29
|
else return
|
30
30
|
end
|
31
31
|
end
|
data/lib/api-client/version.rb
CHANGED
@@ -1,103 +1,37 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ApiClient::Dispatcher do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
4
|
+
before :each do
|
5
|
+
stub_request(:any, "http://api.example.com/user/5").to_return(:body => "asd")
|
6
|
+
end
|
8
7
|
|
8
|
+
describe "#get" do
|
9
9
|
it "should return the request" do
|
10
|
-
ApiClient::Dispatcher.get("http://api.example.com/user/5", {}).should
|
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
|
10
|
+
ApiClient::Dispatcher.get("http://api.example.com/user/5", {}).body.should == ("asd")
|
21
11
|
end
|
22
12
|
end
|
23
13
|
|
24
14
|
describe "#post" do
|
25
|
-
before :each do
|
26
|
-
FakeWeb.register_uri(:post, "http://api.example.com/user/5", :status => "201")
|
27
|
-
end
|
28
|
-
|
29
15
|
it "should return the request" do
|
30
|
-
ApiClient::Dispatcher.post("http://api.example.com/user/5", {}, {}).should
|
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
|
16
|
+
ApiClient::Dispatcher.post("http://api.example.com/user/5", {}, {}).body.should == ("asd")
|
41
17
|
end
|
42
18
|
end
|
43
19
|
|
44
20
|
describe "#put" do
|
45
|
-
before :each do
|
46
|
-
FakeWeb.register_uri(:put, "http://api.example.com/user/5", :status => "200")
|
47
|
-
end
|
48
|
-
|
49
21
|
it "should return the request" do
|
50
|
-
ApiClient::Dispatcher.put("http://api.example.com/user/5", {}, {}).should
|
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
|
22
|
+
ApiClient::Dispatcher.put("http://api.example.com/user/5", {}, {}).body.should == ("asd")
|
61
23
|
end
|
62
24
|
end
|
63
25
|
|
64
26
|
describe "#patch" do
|
65
|
-
before :each do
|
66
|
-
FakeWeb.register_uri(:patch, "http://api.example.com/user/5", :status => "200")
|
67
|
-
end
|
68
|
-
|
69
27
|
it "should return the request" do
|
70
|
-
ApiClient::Dispatcher.patch("http://api.example.com/user/5", {}, {}).should
|
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
|
28
|
+
ApiClient::Dispatcher.patch("http://api.example.com/user/5", {}, {}).body.should == ("asd")
|
81
29
|
end
|
82
|
-
end
|
30
|
+
end if ApiClient::Dispatcher.respond_to?(:patch)
|
83
31
|
|
84
32
|
describe "#delete" do
|
85
|
-
before :each do
|
86
|
-
FakeWeb.register_uri(:delete, "http://api.example.com/user/5", :status => "200")
|
87
|
-
end
|
88
|
-
|
89
33
|
it "should return the request" do
|
90
|
-
ApiClient::Dispatcher.delete("http://api.example.com/user/5", {}).should
|
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
|
34
|
+
ApiClient::Dispatcher.delete("http://api.example.com/user/5", {}).body.should == ("asd")
|
101
35
|
end
|
102
36
|
end
|
103
37
|
end
|
@@ -9,9 +9,7 @@ describe ApiClient::Parser do
|
|
9
9
|
context "with a valid json response" do
|
10
10
|
context "without a root node" do
|
11
11
|
before :each do
|
12
|
-
|
13
|
-
:body => { :a => :b }.to_json,
|
14
|
-
:status => "201")
|
12
|
+
stub_request(:post, "http://api.example.com/user/5").to_return(:body => { :a => :b }.to_json, :status => "201")
|
15
13
|
@response = ApiClient::Dispatcher.post('http://api.example.com/user/5', {}, {})
|
16
14
|
end
|
17
15
|
|
@@ -22,9 +20,7 @@ describe ApiClient::Parser do
|
|
22
20
|
|
23
21
|
context "with a root node" do
|
24
22
|
before :each do
|
25
|
-
|
26
|
-
:body => { :base => { :a => :b } }.to_json,
|
27
|
-
:status => "201")
|
23
|
+
stub_request(:post, "http://api.example.com/user/5").to_return(:body => {:base => { :a => :b } }.to_json, :status => "201")
|
28
24
|
@response = ApiClient::Dispatcher.post('http://api.example.com/user/5', {}, {})
|
29
25
|
end
|
30
26
|
|
@@ -36,9 +32,7 @@ describe ApiClient::Parser do
|
|
36
32
|
|
37
33
|
context "with a invalid json response" do
|
38
34
|
before :each do
|
39
|
-
|
40
|
-
:body => "wrong",
|
41
|
-
:status => "201")
|
35
|
+
stub_request(:post, "http://api.example.com/user/5").to_return(:body => "wrong", :status => "201")
|
42
36
|
@response = ApiClient::Dispatcher.post('http://api.example.com/user/5', {}, {})
|
43
37
|
end
|
44
38
|
|
@@ -50,7 +44,7 @@ describe ApiClient::Parser do
|
|
50
44
|
context "with a response code of" do
|
51
45
|
context "401" do
|
52
46
|
before :each do
|
53
|
-
|
47
|
+
stub_request(:get, "http://api.example.com/user/5").to_return(:status => 401)
|
54
48
|
@response = ApiClient::Dispatcher.get('http://api.example.com/user/5')
|
55
49
|
end
|
56
50
|
|
@@ -61,7 +55,7 @@ describe ApiClient::Parser do
|
|
61
55
|
|
62
56
|
context "403" do
|
63
57
|
before :each do
|
64
|
-
|
58
|
+
stub_request(:get, "http://api.example.com/user/5").to_return(:status => 403)
|
65
59
|
@response = ApiClient::Dispatcher.get('http://api.example.com/user/5')
|
66
60
|
end
|
67
61
|
|
@@ -72,7 +66,7 @@ describe ApiClient::Parser do
|
|
72
66
|
|
73
67
|
context "404" do
|
74
68
|
before :each do
|
75
|
-
|
69
|
+
stub_request(:get, "http://api.example.com/user/5").to_return(:status => 404)
|
76
70
|
@response = ApiClient::Dispatcher.get('http://api.example.com/user/5')
|
77
71
|
end
|
78
72
|
|
@@ -83,7 +77,7 @@ describe ApiClient::Parser do
|
|
83
77
|
|
84
78
|
context "500" do
|
85
79
|
before :each do
|
86
|
-
|
80
|
+
stub_request(:get, "http://api.example.com/user/5").to_return(:status => 500)
|
87
81
|
@response = ApiClient::Dispatcher.get('http://api.example.com/user/5')
|
88
82
|
end
|
89
83
|
|
@@ -94,7 +88,7 @@ describe ApiClient::Parser do
|
|
94
88
|
|
95
89
|
context "502" do
|
96
90
|
before :each do
|
97
|
-
|
91
|
+
stub_request(:get, "http://api.example.com/user/5").to_return(:status => 502)
|
98
92
|
@response = ApiClient::Dispatcher.get('http://api.example.com/user/5')
|
99
93
|
end
|
100
94
|
|
@@ -105,7 +99,7 @@ describe ApiClient::Parser do
|
|
105
99
|
|
106
100
|
context "503" do
|
107
101
|
before :each do
|
108
|
-
|
102
|
+
stub_request(:get, "http://api.example.com/user/5").to_return(:status => 503)
|
109
103
|
@response = ApiClient::Dispatcher.get('http://api.example.com/user/5')
|
110
104
|
end
|
111
105
|
|
data/spec/spec_helper.rb
CHANGED
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.
|
4
|
+
version: 1.6.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: 2012-09-
|
12
|
+
date: 2012-09-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -28,7 +28,7 @@ dependencies:
|
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
31
|
+
name: webmock
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
@@ -126,9 +126,13 @@ files:
|
|
126
126
|
- examples/controllers/application_controller.rb
|
127
127
|
- examples/controllers/user_controller.rb
|
128
128
|
- examples/models/user.rb
|
129
|
+
- gemfiles/Gemfile.net_http
|
130
|
+
- gemfiles/Gemfile.typhoeus
|
129
131
|
- lib/api-client.rb
|
130
132
|
- lib/api-client/base.rb
|
131
133
|
- lib/api-client/dispatcher.rb
|
134
|
+
- lib/api-client/dispatcher/net-http.rb
|
135
|
+
- lib/api-client/dispatcher/typhoeus.rb
|
132
136
|
- lib/api-client/errors.rb
|
133
137
|
- lib/api-client/exceptions.rb
|
134
138
|
- lib/api-client/exceptions/bad_gateway.rb
|
@@ -139,6 +143,7 @@ files:
|
|
139
143
|
- lib/api-client/exceptions/not_found.rb
|
140
144
|
- lib/api-client/exceptions/service_unavailable.rb
|
141
145
|
- lib/api-client/exceptions/unauthorized.rb
|
146
|
+
- lib/api-client/net/http.rb
|
142
147
|
- lib/api-client/parser.rb
|
143
148
|
- lib/api-client/version.rb
|
144
149
|
- spec/api-client/base_spec.rb
|
@@ -158,12 +163,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
158
163
|
- - ! '>='
|
159
164
|
- !ruby/object:Gem::Version
|
160
165
|
version: '0'
|
166
|
+
segments:
|
167
|
+
- 0
|
168
|
+
hash: -3045857671343172453
|
161
169
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
170
|
none: false
|
163
171
|
requirements:
|
164
172
|
- - ! '>='
|
165
173
|
- !ruby/object:Gem::Version
|
166
174
|
version: '0'
|
175
|
+
segments:
|
176
|
+
- 0
|
177
|
+
hash: -3045857671343172453
|
167
178
|
requirements: []
|
168
179
|
rubyforge_project:
|
169
180
|
rubygems_version: 1.8.24
|