api-client 1.8.0 → 1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/README.md +8 -2
- data/lib/api-client/base.rb +1 -0
- data/lib/api-client/version.rb +1 -1
- data/spec/api-client/base_spec.rb +19 -7
- metadata +4 -4
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
# ApiClient
|
1
|
+
# ApiClient - Client to call Api easily.
|
2
2
|
|
3
|
-
|
3
|
+
[![Build Status](https://secure.travis-ci.org/zertico/api-client.png?branch=master)](http://travis-ci.org/zertico/api-client) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/zertico/api-client)
|
4
|
+
|
5
|
+
It supports ruby 1.8.7, 1.9.2, 1.9.3, jruby and ree out of the box.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -71,6 +73,10 @@ This code will create a setter and a getter for houses and cars and initialize t
|
|
71
73
|
* Add support for parallel requests
|
72
74
|
* Add more Response Handlers
|
73
75
|
|
76
|
+
## Mantainers
|
77
|
+
[@plribeiro3000](https://github.com/plribeiro3000)
|
78
|
+
|
79
|
+
|
74
80
|
## Contributing
|
75
81
|
|
76
82
|
1. Fork it
|
data/lib/api-client/base.rb
CHANGED
@@ -114,6 +114,7 @@ module ApiClient
|
|
114
114
|
def self.method_missing(method, *args)
|
115
115
|
@response = Parser.response(Dispatcher.send(method, *args))
|
116
116
|
case true
|
117
|
+
when @response.instance_of?(Array) then return @response.map { |a| new(a.merge(:response => @response)) }
|
117
118
|
when @response.key?(remote_object) then return new(@response[remote_object].merge(:response => @response))
|
118
119
|
when @response.key?(remote_object.pluralize) then return @response[remote_object.pluralize].map { |a| new(a.merge(:response => @response)) }
|
119
120
|
else return new(@response.merge(:response => @response))
|
data/lib/api-client/version.rb
CHANGED
@@ -102,16 +102,28 @@ describe ApiClient::Base do
|
|
102
102
|
end
|
103
103
|
|
104
104
|
describe "requests" do
|
105
|
-
|
106
|
-
|
107
|
-
|
105
|
+
context "with an object as response" do
|
106
|
+
before :each do
|
107
|
+
stub_request(:any, "http://api.example.com").to_return(:body => {"a" => "b"}.to_json)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should return a new instance" do
|
111
|
+
User.get("http://api.example.com").should be_an_instance_of(User)
|
112
|
+
end
|
108
113
|
|
109
|
-
|
110
|
-
|
114
|
+
it "should set the response on the instance" do
|
115
|
+
User.get("http://api.example.com").response.should == {"a" => "b"}
|
116
|
+
end
|
111
117
|
end
|
112
118
|
|
113
|
-
|
114
|
-
|
119
|
+
context "with an array as response" do
|
120
|
+
before :each do
|
121
|
+
stub_request(:any, "http://api.example.com").to_return(:body => [{"a" => "b"}].to_json)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should return an array of instances" do
|
125
|
+
User.get("http://api.example.com").should be_an_instance_of(Array)
|
126
|
+
end
|
115
127
|
end
|
116
128
|
end
|
117
129
|
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.8.
|
4
|
+
version: 1.8.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-
|
12
|
+
date: 2012-10-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -167,7 +167,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
167
167
|
version: '0'
|
168
168
|
segments:
|
169
169
|
- 0
|
170
|
-
hash:
|
170
|
+
hash: 1498468142604583220
|
171
171
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
172
|
none: false
|
173
173
|
requirements:
|
@@ -176,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
176
|
version: '0'
|
177
177
|
segments:
|
178
178
|
- 0
|
179
|
-
hash:
|
179
|
+
hash: 1498468142604583220
|
180
180
|
requirements: []
|
181
181
|
rubyforge_project:
|
182
182
|
rubygems_version: 1.8.24
|