apipie-bindings 0.0.16 → 0.0.17

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aff06fcd62b11a1cd42115eed2dc44642d5f312f
4
- data.tar.gz: 1752856687b077fb3f35af546d687364b94bc732
3
+ metadata.gz: 13d22cd6355e9bf1c07c011efb312aa712d3581e
4
+ data.tar.gz: 76ac815e986f16a031dcb3248cc0653a440888b3
5
5
  SHA512:
6
- metadata.gz: b0201bb9a4bca428e4a49d8b706daa2873e8e0d3252189b40ceaee3254e42c963b2ea52770c88dfe1b08c82eb454d9cd5713be3a052f9e4b206a979a3e799490
7
- data.tar.gz: 2d43831dea22be3f35fcb6d298fabe2c05699ccb6e5300c158926dd4cd42e17e4dcd5498da470462cf22bffaf79b3f43a5b151a9a6eacd298e89b50819edf3cb
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
@@ -1,4 +1,5 @@
1
1
  require 'apipie_bindings/version'
2
+ require 'apipie_bindings/rest_client_extensions'
2
3
  require 'apipie_bindings/utils'
3
4
  require 'apipie_bindings/credentials'
4
5
  require 'apipie_bindings/exceptions'
@@ -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
@@ -1,5 +1,5 @@
1
1
  module ApipieBindings
2
2
  def self.version
3
- @version ||= Gem::Version.new '0.0.16'
3
+ @version ||= Gem::Version.new '0.0.17'
4
4
  end
5
5
  end
@@ -173,11 +173,19 @@ describe ApipieBindings::API do
173
173
  api.follow_redirects.must_equal :never
174
174
  end
175
175
 
176
- it "should rise error on redirect when follow_redirects = :never" do
177
- api = configure_api_with(:follow_redirects => :never)
178
- block = api.send(:rest_client_call_block)
179
- response = api.send(:create_fake_response, 301, "", "GET", "/", {})
180
- proc { block.call(response) }.must_raise RestClient::MovedPermanently
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.16
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-03-08 00:00:00.000000000 Z
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/rest_client_oauth.rb
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