api-client 2.6.0 → 2.7.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.
- checksums.yaml +7 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +8 -0
- data/README.md +22 -0
- data/examples/controllers/book_controller.rb +1 -1
- data/examples/controllers/user_controller.rb +1 -1
- data/lib/api-client/class_methods.rb +4 -4
- data/lib/api-client/instance_methods.rb +2 -2
- data/lib/api-client/version.rb +2 -2
- data/spec/api-client/class_methods_spec.rb +6 -6
- metadata +21 -43
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 44c8775d6a585af08c1ac80b3263e77f4922983d
|
4
|
+
data.tar.gz: 5be3312583e04df381e4a3c537515cf843b4a925
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 14583a5cabbfe1fa3a2eb56c9bb96c39343e19fcecaf224a15dac5f3babbfa7a584c57899db1f2b9e8241a6970a2e3adfb368a3919c11f1fa3e2d29066185904
|
7
|
+
data.tar.gz: 7f42c5147782929e1c0b4972b421fb12cbc599f0044cd2a943ca165bbb9953ecd4c816ba6bf972a9d32028d40cb860c72b63954319822ff1719bd69a94334ea2
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-
|
1
|
+
ruby-2.0.0
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -39,6 +39,8 @@ Or install it yourself as:
|
|
39
39
|
|
40
40
|
$ gem install api-client
|
41
41
|
|
42
|
+
If you will use Typhoeus (https://github.com/typhoeus/typhoeus), you must have Typhoeus version above 0.5.0.
|
43
|
+
|
42
44
|
## Basic Usage
|
43
45
|
|
44
46
|
Create an initializer:
|
@@ -136,6 +138,26 @@ end
|
|
136
138
|
|
137
139
|
This code will create a setter and a getter for houses and cars and initialize the respective class.
|
138
140
|
|
141
|
+
When you are working with collections you can use api pagination according Hal Specification (http://stateless.co/hal_specification.html) .
|
142
|
+
You just need to pass a hash as:
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
{
|
146
|
+
total: 10,
|
147
|
+
total_pages: 1,
|
148
|
+
offset: 10,
|
149
|
+
_links: {
|
150
|
+
first: { href: "/api/clients" },
|
151
|
+
previous: null,
|
152
|
+
self: { href: "/api/clients" },
|
153
|
+
next: null,
|
154
|
+
last: { href: "/api/clients?page=1" }
|
155
|
+
},
|
156
|
+
users: [ { user: { name: "example1" } }, { user: { name: "example2" } } ]
|
157
|
+
}
|
158
|
+
```
|
159
|
+
|
160
|
+
|
139
161
|
Since version 2.0.0, it is possible to make api calls from the object. The syntax is pretty much the same.
|
140
162
|
It will make the call and update the fields with the response. Look at the examples folder to see more code examples
|
141
163
|
|
@@ -27,7 +27,7 @@ class BookController < ApplicationController
|
|
27
27
|
|
28
28
|
# It will hit http://api.example.com/books with a put request
|
29
29
|
def update
|
30
|
-
@book = Book.update_attributes({ :book => params[:book] })
|
30
|
+
@book = Book.update_attributes(params[:id], { :book => params[:book] })
|
31
31
|
respond_with(@book)
|
32
32
|
end
|
33
33
|
|
@@ -27,7 +27,7 @@ class UserController < ApplicationController
|
|
27
27
|
|
28
28
|
# It will hit http://api.example.com/users with a patch request
|
29
29
|
def update
|
30
|
-
@user = User.patch({ :user => params[:user] })
|
30
|
+
@user = User.patch(params[:id], { :user => params[:user] })
|
31
31
|
respond_with(@user)
|
32
32
|
end
|
33
33
|
|
@@ -34,9 +34,9 @@ module ApiClient
|
|
34
34
|
# @param [Hash] attributes hash with the attributes to send.
|
35
35
|
# @param [Hash] header hash with the header options.
|
36
36
|
# @return [Base] the object initialized.
|
37
|
-
def put(attributes, header = {})
|
37
|
+
def put(id, attributes, header = {})
|
38
38
|
return new(attributes) if ApiClient.config.mock
|
39
|
-
url = "#{ApiClient.config.path[path]}#{self.resource_path}"
|
39
|
+
url = "#{ApiClient.config.path[path]}#{self.resource_path}/#{id}"
|
40
40
|
response = ApiClient::Dispatcher.put(url, attributes, header)
|
41
41
|
build(response, url)
|
42
42
|
end
|
@@ -48,9 +48,9 @@ module ApiClient
|
|
48
48
|
# @param [Hash] attributes hash with the attributes to send.
|
49
49
|
# @param [Hash] header hash with the header options.
|
50
50
|
# @return [Base] the object initialized.
|
51
|
-
def patch(attributes, header = {})
|
51
|
+
def patch(id, attributes, header = {})
|
52
52
|
return new(attributes) if ApiClient.config.mock
|
53
|
-
url = "#{ApiClient.config.path[path]}#{self.resource_path}"
|
53
|
+
url = "#{ApiClient.config.path[path]}#{self.resource_path}/#{id}"
|
54
54
|
response = ApiClient::Dispatcher.patch(url, attributes, header)
|
55
55
|
build(response, url)
|
56
56
|
end
|
@@ -33,7 +33,7 @@ module ApiClient
|
|
33
33
|
# @return [Base] the object updated.
|
34
34
|
def put(header = {})
|
35
35
|
return self if ApiClient.config.mock
|
36
|
-
url = "#{ApiClient.config.path[path]}#{self.class.resource_path}"
|
36
|
+
url = "#{ApiClient.config.path[path]}#{self.class.resource_path}/#{id}"
|
37
37
|
response = ApiClient::Dispatcher.put(url, self.to_hash, header)
|
38
38
|
update(response, url)
|
39
39
|
end
|
@@ -46,7 +46,7 @@ module ApiClient
|
|
46
46
|
# @return [Base] the object updated.
|
47
47
|
def patch(header = {})
|
48
48
|
return self if ApiClient.config.mock
|
49
|
-
url = "#{ApiClient.config.path[path]}#{self.class.resource_path}"
|
49
|
+
url = "#{ApiClient.config.path[path]}#{self.class.resource_path}/#{id}"
|
50
50
|
response = ApiClient::Dispatcher.patch(url, self.to_hash, header)
|
51
51
|
update(response, url)
|
52
52
|
end
|
data/lib/api-client/version.rb
CHANGED
@@ -33,19 +33,19 @@ describe ApiClient::ClassMethods do
|
|
33
33
|
|
34
34
|
context '.put' do
|
35
35
|
it 'should return an user' do
|
36
|
-
User.put({}).should be_an_instance_of(User)
|
36
|
+
User.put(1, {}).should be_an_instance_of(User)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
context '.update_attributes' do
|
41
41
|
it 'should return an user' do
|
42
|
-
User.update_attributes({}).should be_an_instance_of(User)
|
42
|
+
User.update_attributes(1, {}).should be_an_instance_of(User)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
context '.patch' do
|
47
47
|
it 'should return an user' do
|
48
|
-
User.patch({}).should be_an_instance_of(User)
|
48
|
+
User.patch(1, {}).should be_an_instance_of(User)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -101,19 +101,19 @@ describe ApiClient::ClassMethods do
|
|
101
101
|
|
102
102
|
context '.put' do
|
103
103
|
it 'should return an user' do
|
104
|
-
User.put({}).should be_an_instance_of(User)
|
104
|
+
User.put(1, {}).should be_an_instance_of(User)
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
108
|
context '.update_attributes' do
|
109
109
|
it 'should return an user' do
|
110
|
-
User.update_attributes({}).should be_an_instance_of(User)
|
110
|
+
User.update_attributes(1, {}).should be_an_instance_of(User)
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
114
|
context '.patch' do
|
115
115
|
it 'should return an user' do
|
116
|
-
User.patch({}).should be_an_instance_of(User)
|
116
|
+
User.patch(1, {}).should be_an_instance_of(User)
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
metadata
CHANGED
@@ -1,126 +1,111 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
5
|
-
prerelease:
|
4
|
+
version: 2.7.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Paulo Henrique Lopes Ribeiro
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-01-30 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: webmock
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: yard
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: coveralls
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - '>='
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - '>='
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: activemodel
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
|
-
- -
|
87
|
+
- - '>='
|
100
88
|
- !ruby/object:Gem::Version
|
101
89
|
version: '0'
|
102
90
|
type: :runtime
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
|
-
- -
|
94
|
+
- - '>='
|
108
95
|
- !ruby/object:Gem::Version
|
109
96
|
version: '0'
|
110
97
|
- !ruby/object:Gem::Dependency
|
111
98
|
name: json_pure
|
112
99
|
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
100
|
requirements:
|
115
|
-
- -
|
101
|
+
- - '>='
|
116
102
|
- !ruby/object:Gem::Version
|
117
103
|
version: '0'
|
118
104
|
type: :runtime
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
107
|
requirements:
|
123
|
-
- -
|
108
|
+
- - '>='
|
124
109
|
- !ruby/object:Gem::Version
|
125
110
|
version: '0'
|
126
111
|
description:
|
@@ -192,33 +177,26 @@ files:
|
|
192
177
|
homepage:
|
193
178
|
licenses:
|
194
179
|
- MIT
|
180
|
+
metadata: {}
|
195
181
|
post_install_message:
|
196
182
|
rdoc_options: []
|
197
183
|
require_paths:
|
198
184
|
- lib
|
199
185
|
required_ruby_version: !ruby/object:Gem::Requirement
|
200
|
-
none: false
|
201
186
|
requirements:
|
202
|
-
- -
|
187
|
+
- - '>='
|
203
188
|
- !ruby/object:Gem::Version
|
204
189
|
version: '0'
|
205
|
-
segments:
|
206
|
-
- 0
|
207
|
-
hash: 2568135155809841734
|
208
190
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
209
|
-
none: false
|
210
191
|
requirements:
|
211
|
-
- -
|
192
|
+
- - '>='
|
212
193
|
- !ruby/object:Gem::Version
|
213
194
|
version: '0'
|
214
|
-
segments:
|
215
|
-
- 0
|
216
|
-
hash: 2568135155809841734
|
217
195
|
requirements: []
|
218
196
|
rubyforge_project:
|
219
|
-
rubygems_version: 1.
|
197
|
+
rubygems_version: 2.1.11
|
220
198
|
signing_key:
|
221
|
-
specification_version:
|
199
|
+
specification_version: 4
|
222
200
|
summary: Api client easy to play with parallelism support!
|
223
201
|
test_files:
|
224
202
|
- examples/config/initializers/api-client.rb
|