apipie-bindings 0.0.17 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/release_notes.md +6 -0
- data/lib/apipie_bindings/api.rb +24 -11
- data/lib/apipie_bindings/resource.rb +31 -0
- data/lib/apipie_bindings/version.rb +1 -1
- data/test/unit/api_test.rb +12 -7
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4734cdf3c653d0886c206128ad15894c3d279470
|
4
|
+
data.tar.gz: 747b17990ca0a2258eee7936b2040d98f7832c80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31986fa92e0941cfd0af5560d134b75b7166f11aaf1550d4b8385adc75c7c68759f93dbfbbb0657089d064d3dff762af5321459c6240babab6e7d5687fa72fb1
|
7
|
+
data.tar.gz: e7c6e55f3d160074635dc8861a93a6965d276425ef383c881ac298a3a936aaa0971b6029a10a10fe211ce7c7337347a90d10a6adee4ede59059de3cfa0c2bbed
|
data/doc/release_notes.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
Release notes
|
2
2
|
=============
|
3
3
|
|
4
|
+
### 0.0.18 (2016-08-31)
|
5
|
+
* Recover from exception while inspecting error response ([#48](https://github.com/Apipie/apipie-bindings/issues/48))
|
6
|
+
* Add yard docs for ApipieBindings::Resource class ([#47](https://github.com/Apipie/apipie-bindings/issues/47))
|
7
|
+
* Restrict json to < 2.0.0 ([#46](https://github.com/Apipie/apipie-bindings/issues/46))
|
8
|
+
* Support rest-client 2.0.0 ([#45](https://github.com/Apipie/apipie-bindings/issues/45))
|
9
|
+
|
4
10
|
### 0.0.17 (2016-06-23)
|
5
11
|
* Restrict rest-client version to < 2.0.0 ([#42](https://github.com/Apipie/apipie-bindings/issues/42))
|
6
12
|
* Include request in response for rest-client < 1.8.0 ([#11147](http://projects.theforeman.org/issues/11147))
|
data/lib/apipie_bindings/api.rb
CHANGED
@@ -213,7 +213,7 @@ module ApipieBindings
|
|
213
213
|
if dry_run?
|
214
214
|
empty_response = ApipieBindings::Example.new('', '', '', 200, '')
|
215
215
|
ex = options[:fake_response ] || empty_response
|
216
|
-
response = create_fake_response(ex.status, ex.response, http_method, path, args)
|
216
|
+
response = create_fake_response(ex.status, ex.response, http_method, URI.join(@uri || 'http://example.com', path).to_s, args)
|
217
217
|
else
|
218
218
|
begin
|
219
219
|
apidoc_without_auth = (path =~ /\/apidoc\//) && !@apidoc_authenticated
|
@@ -223,8 +223,8 @@ module ApipieBindings
|
|
223
223
|
update_cache(response.headers[:apipie_checksum])
|
224
224
|
rescue => e
|
225
225
|
clear_credentials if e.is_a? RestClient::Unauthorized
|
226
|
-
log.
|
227
|
-
|
226
|
+
log.error e.message
|
227
|
+
log.debug inspect_data(e)
|
228
228
|
raise
|
229
229
|
end
|
230
230
|
end
|
@@ -306,7 +306,11 @@ module ApipieBindings
|
|
306
306
|
raise exception_with_response(response)
|
307
307
|
end
|
308
308
|
else
|
309
|
-
response.return!
|
309
|
+
if response.method(:return!).arity.zero? # 2.0.0+
|
310
|
+
response.return!(&block)
|
311
|
+
else
|
312
|
+
response.return!(request, result, &block)
|
313
|
+
end
|
310
314
|
end
|
311
315
|
end
|
312
316
|
end
|
@@ -381,20 +385,29 @@ module ApipieBindings
|
|
381
385
|
end
|
382
386
|
|
383
387
|
def inspect_data(obj)
|
384
|
-
ApipieBindings::Utils.inspect_data(obj)
|
388
|
+
ApipieBindings::Utils.inspect_data(obj.respond_to?(:response) ? process_data(obj.response) : obj)
|
389
|
+
rescue => e
|
390
|
+
log.debug "Error during inspecting response: #{e.message}"
|
391
|
+
''
|
385
392
|
end
|
386
393
|
|
387
|
-
def create_fake_response(status, body, method, path, args=
|
394
|
+
def create_fake_response(status, body, method, path, args=[])
|
395
|
+
request_args = {:method => args.shift || method, :url => path}
|
396
|
+
request_args[:params] = args.shift if %w[post put].include?(method.to_s)
|
397
|
+
request_args[:headers] = args.shift
|
398
|
+
|
388
399
|
net_http_resp = Net::HTTPResponse.new(1.0, status, "")
|
389
|
-
if RestClient
|
390
|
-
RestClient::Response.create(body, net_http_resp,
|
400
|
+
if RestClient.version >= '2.0.0'
|
401
|
+
RestClient::Response.create(body, net_http_resp, create_fake_request(request_args))
|
402
|
+
elsif RestClient.version >= '1.8.0'
|
403
|
+
RestClient::Response.create(body, net_http_resp, request_args, create_fake_request(request_args))
|
391
404
|
else
|
392
|
-
RestClient::Response.create(body, net_http_resp,
|
405
|
+
RestClient::Response.create(body, net_http_resp, request_args)
|
393
406
|
end
|
394
407
|
end
|
395
408
|
|
396
|
-
def create_fake_request(
|
397
|
-
RestClient::Request.new(
|
409
|
+
def create_fake_request(args)
|
410
|
+
RestClient::Request.new(args)
|
398
411
|
end
|
399
412
|
end
|
400
413
|
end
|
@@ -10,34 +10,65 @@ module ApipieBindings
|
|
10
10
|
@api = api
|
11
11
|
end
|
12
12
|
|
13
|
+
# Execute an action on a resource
|
14
|
+
#
|
15
|
+
# @param action [Symbol]
|
16
|
+
# @param params [Hash]
|
17
|
+
# @param headers [Hash]
|
18
|
+
# @param options [Hash]
|
19
|
+
# @return [Hash]
|
13
20
|
def call(action, params={}, headers={}, options={})
|
14
21
|
@api.call(@name, action, params, headers, options)
|
15
22
|
end
|
16
23
|
|
24
|
+
# Get API documentation for a resource
|
25
|
+
#
|
26
|
+
# @return [Hash]
|
17
27
|
def apidoc
|
18
28
|
@api.apidoc[:docs][:resources][@name]
|
19
29
|
end
|
20
30
|
|
31
|
+
# Get list of all actions for a resource
|
32
|
+
#
|
33
|
+
# @return [Array<ApipieBindings::Action>]
|
21
34
|
def actions
|
22
35
|
apidoc[:methods].map { |a| action(a[:name].to_sym) }
|
23
36
|
end
|
24
37
|
|
38
|
+
# Determine if resource has a particular action
|
39
|
+
#
|
40
|
+
# @param name [Symbol] name of action to check
|
41
|
+
# @return [Bool]
|
25
42
|
def has_action?(name)
|
26
43
|
apidoc[:methods].any? { |action| action[:name].to_sym == name }
|
27
44
|
end
|
28
45
|
|
46
|
+
# Get ApipieBindings::Action
|
47
|
+
#
|
48
|
+
# @param name [Symbol] action name
|
49
|
+
# @return [ApipieBindings::Action]
|
29
50
|
def action(name)
|
30
51
|
ApipieBindings::Action.new(@name, name, @api)
|
31
52
|
end
|
32
53
|
|
54
|
+
# Get simiple string representation
|
55
|
+
#
|
56
|
+
# @return [String] ApipieBindings::Resource as a string
|
33
57
|
def singular_name
|
34
58
|
ApipieBindings::Inflector.singularize(@name.to_s)
|
35
59
|
end
|
36
60
|
|
61
|
+
# Get string representation
|
62
|
+
#
|
63
|
+
# @return [String] ApipieBindings::Resource as a string
|
37
64
|
def to_s
|
38
65
|
"<Resource :#{@name}>"
|
39
66
|
end
|
40
67
|
|
68
|
+
# Get string representation
|
69
|
+
#
|
70
|
+
# @return [String] ApipieBindings::Resource as a string
|
71
|
+
# @note same as to_s method
|
41
72
|
def inspect
|
42
73
|
to_s
|
43
74
|
end
|
data/test/unit/api_test.rb
CHANGED
@@ -71,9 +71,11 @@ describe ApipieBindings::API do
|
|
71
71
|
:dry_run => true})
|
72
72
|
s = StringIO.new; s << 'foo'
|
73
73
|
headers = {:content_type => 'multipart/form-data', :multipart => true}
|
74
|
-
RestClient::Response.expects(:create).with
|
75
|
-
|
76
|
-
|
74
|
+
RestClient::Response.expects(:create).with do |*args|
|
75
|
+
# on 1.8, prefer the copy of args kept in the original request object
|
76
|
+
request_args = RestClient.version >= '1.8.0' ? args.last.args : args.last
|
77
|
+
request_args[:method] == :post && request_args[:params] == {:file => s} && request_args[:headers] == headers
|
78
|
+
end
|
77
79
|
result = api.http_call(:post, '/api/path', {:file => s}, headers, {:response => :raw})
|
78
80
|
end
|
79
81
|
|
@@ -176,7 +178,7 @@ describe ApipieBindings::API do
|
|
176
178
|
context "follow_redirects = :never" do
|
177
179
|
let(:api) { configure_api_with(:follow_redirects => :never) }
|
178
180
|
let(:block) { api.send(:rest_client_call_block) }
|
179
|
-
let(:response) { api.send(:create_fake_response, 301, "", "GET", "/", {}) }
|
181
|
+
let(:response) { api.send(:create_fake_response, 301, "", "GET", "http://example.com/", {}) }
|
180
182
|
|
181
183
|
it "should rise error on redirect" do
|
182
184
|
proc { block.call(response) }.must_raise RestClient::MovedPermanently
|
@@ -191,7 +193,7 @@ describe ApipieBindings::API do
|
|
191
193
|
it "should follow redirect when follow_redirects = :always" do
|
192
194
|
api = configure_api_with(:follow_redirects => :always)
|
193
195
|
block = api.send(:rest_client_call_block)
|
194
|
-
response = api.send(:create_fake_response, 301, "", "POST", "/", {})
|
196
|
+
response = api.send(:create_fake_response, 301, "", "POST", "http://example.com/", {})
|
195
197
|
response.expects(:follow_redirection)
|
196
198
|
block.call(response)
|
197
199
|
end
|
@@ -199,7 +201,7 @@ describe ApipieBindings::API do
|
|
199
201
|
it "should use original handling when follow_redirects = :default" do
|
200
202
|
api = configure_api_with(:follow_redirects => :default)
|
201
203
|
block = api.send(:rest_client_call_block)
|
202
|
-
response = api.send(:create_fake_response, 301, "", "GET", "/", {})
|
204
|
+
response = api.send(:create_fake_response, 301, "", "GET", "http://example.com/", {})
|
203
205
|
response.expects(:return!)
|
204
206
|
block.call(response)
|
205
207
|
end
|
@@ -210,7 +212,10 @@ describe ApipieBindings::API do
|
|
210
212
|
let(:fake_empty_response) {
|
211
213
|
data = ApipieBindings::Example.new('', '', '', 200, '[]')
|
212
214
|
net_http_resp = Net::HTTPResponse.new(1.0, data.status, "")
|
213
|
-
if RestClient
|
215
|
+
if RestClient.version >= '2.0.0'
|
216
|
+
RestClient::Response.create(data.response, net_http_resp,
|
217
|
+
RestClient::Request.new(:method=>'GET', :url=>'http://example.com'))
|
218
|
+
elsif RestClient.version >= '1.8.0'
|
214
219
|
RestClient::Response.create(data.response, net_http_resp, {},
|
215
220
|
RestClient::Request.new(:method=>'GET', :url=>'http://example.com'))
|
216
221
|
else
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apipie-bindings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Bačovský
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
version: 1.6.5
|
34
34
|
- - "<"
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version:
|
36
|
+
version: 3.0.0
|
37
37
|
type: :runtime
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: 1.6.5
|
44
44
|
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
46
|
+
version: 3.0.0
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: oauth
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|