apipie-bindings 0.0.16 → 0.0.17
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 +5 -0
- data/lib/apipie_bindings.rb +1 -0
- data/lib/apipie_bindings/api.rb +4 -3
- data/lib/apipie_bindings/rest_client_extensions.rb +34 -0
- data/lib/apipie_bindings/version.rb +1 -1
- data/test/unit/api_test.rb +13 -5
- metadata +9 -3
- data/lib/apipie_bindings/rest_client_oauth.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13d22cd6355e9bf1c07c011efb312aa712d3581e
|
4
|
+
data.tar.gz: 76ac815e986f16a031dcb3248cc0653a440888b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a1f387ce7e38ab4e0ac66c714c07366d5d49af2778d48ece0f4538af0bd77756135860f936e01a95a316560d248a76eddf8d20d1272d1b33f817197d092b877
|
7
|
+
data.tar.gz: c2aa3d6e688560a763a54112a615e3bacb2beb5f671c56e27f39ffd587756882966125f0a5f5f53c902630b4a94626c9eb70b70c46f92d492af0c1b772a03205
|
data/doc/release_notes.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
Release notes
|
2
2
|
=============
|
3
3
|
|
4
|
+
### 0.0.17 (2016-06-23)
|
5
|
+
* Restrict rest-client version to < 2.0.0 ([#42](https://github.com/Apipie/apipie-bindings/issues/42))
|
6
|
+
* Include request in response for rest-client < 1.8.0 ([#11147](http://projects.theforeman.org/issues/11147))
|
7
|
+
* Don't try to clear credentials if nil ([#43](https://github.com/Apipie/apipie-bindings/issues/43))
|
8
|
+
|
4
9
|
### 0.0.16 (2016-03-08)
|
5
10
|
* Controll following redirection ([#37](https://github.com/Apipie/apipie-bindings/issues/37))
|
6
11
|
* Enable for mocking api calls with validations
|
data/lib/apipie_bindings.rb
CHANGED
data/lib/apipie_bindings/api.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'json'
|
2
|
-
require 'rest_client'
|
3
2
|
require 'oauth'
|
4
|
-
require 'apipie_bindings/rest_client_oauth'
|
5
3
|
require 'logger'
|
6
4
|
require 'tmpdir'
|
7
5
|
module ApipieBindings
|
@@ -115,7 +113,7 @@ module ApipieBindings
|
|
115
113
|
|
116
114
|
def clear_credentials
|
117
115
|
@client_with_auth = nil
|
118
|
-
@credentials.clear
|
116
|
+
@credentials.clear if @credentials
|
119
117
|
end
|
120
118
|
|
121
119
|
def apidoc
|
@@ -297,6 +295,9 @@ module ApipieBindings
|
|
297
295
|
|
298
296
|
def rest_client_call_block
|
299
297
|
Proc.new do |response, request, result, &block|
|
298
|
+
# include request for rest_client < 1.8.0
|
299
|
+
response.request ||= request
|
300
|
+
|
300
301
|
if [301, 302, 307].include?(response.code) && [:always, :never].include?(@follow_redirects)
|
301
302
|
if @follow_redirects == :always
|
302
303
|
log.debug "Response redirected to #{response.headers[:location]}"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
module ApipieBindings
|
3
|
+
module RestClientExtensions
|
4
|
+
|
5
|
+
module RequestAccessor
|
6
|
+
attr_accessor :request
|
7
|
+
end
|
8
|
+
|
9
|
+
RestClient::AbstractResponse.send(:include, RequestAccessor) unless RestClient::AbstractResponse.method_defined?(:request)
|
10
|
+
RestClient::Response.send(:include, RequestAccessor) unless RestClient::Response.method_defined?(:request)
|
11
|
+
|
12
|
+
unless RestClient.const_defined? :OAUTH_EXTENSION
|
13
|
+
RestClient::OAUTH_EXTENSION = lambda do |request, args|
|
14
|
+
if args[:oauth]
|
15
|
+
uri = URI.parse args[:url]
|
16
|
+
default_options = {
|
17
|
+
:site => "#{uri.scheme}://#{uri.host}:#{uri.port.to_s}",
|
18
|
+
:request_token_path => "",
|
19
|
+
:authorize_path => "",
|
20
|
+
:access_token_path => ""
|
21
|
+
}
|
22
|
+
options = default_options.merge args[:oauth][:options] || { }
|
23
|
+
consumer = OAuth::Consumer.new(args[:oauth][:consumer_key], args[:oauth][:consumer_secret], options)
|
24
|
+
|
25
|
+
consumer.sign!(request)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
unless RestClient.before_execution_procs.include? RestClient::OAUTH_EXTENSION
|
31
|
+
RestClient.add_before_execution_proc &RestClient::OAUTH_EXTENSION
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/test/unit/api_test.rb
CHANGED
@@ -173,11 +173,19 @@ describe ApipieBindings::API do
|
|
173
173
|
api.follow_redirects.must_equal :never
|
174
174
|
end
|
175
175
|
|
176
|
-
|
177
|
-
api
|
178
|
-
block
|
179
|
-
response
|
180
|
-
|
176
|
+
context "follow_redirects = :never" do
|
177
|
+
let(:api) { configure_api_with(:follow_redirects => :never) }
|
178
|
+
let(:block) { api.send(:rest_client_call_block) }
|
179
|
+
let(:response) { api.send(:create_fake_response, 301, "", "GET", "/", {}) }
|
180
|
+
|
181
|
+
it "should rise error on redirect" do
|
182
|
+
proc { block.call(response) }.must_raise RestClient::MovedPermanently
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should rise error that contains the request" do
|
186
|
+
err = proc { block.call(response) }.must_raise RestClient::MovedPermanently
|
187
|
+
err.response.respond_to?(:request).must_equal true
|
188
|
+
end
|
181
189
|
end
|
182
190
|
|
183
191
|
it "should follow redirect when follow_redirects = :always" do
|
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.17
|
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-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -31,6 +31,9 @@ dependencies:
|
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.6.5
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 2.0.0
|
34
37
|
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -38,6 +41,9 @@ dependencies:
|
|
38
41
|
- - ">="
|
39
42
|
- !ruby/object:Gem::Version
|
40
43
|
version: 1.6.5
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.0.0
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: oauth
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -179,7 +185,7 @@ files:
|
|
179
185
|
- lib/apipie_bindings/inflector.rb
|
180
186
|
- lib/apipie_bindings/param.rb
|
181
187
|
- lib/apipie_bindings/resource.rb
|
182
|
-
- lib/apipie_bindings/
|
188
|
+
- lib/apipie_bindings/rest_client_extensions.rb
|
183
189
|
- lib/apipie_bindings/route.rb
|
184
190
|
- lib/apipie_bindings/utils.rb
|
185
191
|
- lib/apipie_bindings/version.rb
|
@@ -1,19 +0,0 @@
|
|
1
|
-
unless RestClient.const_defined? :OAUTH_EXTENSION
|
2
|
-
RestClient::OAUTH_EXTENSION = lambda do |request, args|
|
3
|
-
if args[:oauth]
|
4
|
-
uri = URI.parse args[:url]
|
5
|
-
default_options = { :site => "#{uri.scheme}://#{uri.host}:#{uri.port.to_s}",
|
6
|
-
:request_token_path => "",
|
7
|
-
:authorize_path => "",
|
8
|
-
:access_token_path => "" }
|
9
|
-
options = default_options.merge args[:oauth][:options] || { }
|
10
|
-
consumer = OAuth::Consumer.new(args[:oauth][:consumer_key], args[:oauth][:consumer_secret], options)
|
11
|
-
|
12
|
-
consumer.sign!(request)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
unless RestClient.before_execution_procs.include? RestClient::OAUTH_EXTENSION
|
18
|
-
RestClient.add_before_execution_proc &RestClient::OAUTH_EXTENSION
|
19
|
-
end
|