flexirest 1.8.8 → 1.8.9

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
  SHA256:
3
- metadata.gz: 034246a4c82d512ced039ae0265091d40688183c762e1094c12f0dca31439a55
4
- data.tar.gz: 65545b4903a74eae1140866589f97be1bf664b2df052bc515a243e29844ab543
3
+ metadata.gz: 8eeb42973b47925b75719642de9f2ad0ff58795453b0843ae2119ad32be87f89
4
+ data.tar.gz: fb6760cd9d4da6bbf4e3c653c7860790b3c259d7764f3ba4b2fc804461ff5d2b
5
5
  SHA512:
6
- metadata.gz: fa7bd3620f69ec7ba0ba6493d86bae8aef4c889e5f3ed536d2bd801c6b62a8f9248bd80338901eff4b0435a2aa26589672ea03ddd6e81a4c1bc99cb66387651b
7
- data.tar.gz: e73ba209c5dd7e98a370e8ac2fab285f98cb948b81f56a3cc23f63ad9f3035ba385de0292546943f1ca63d8eca30e9f0795f1ee3f60268b1b8a9bfe2c0a69deb
6
+ metadata.gz: 4ab9bd72452449e4e46332f44b100a7bace5e06334eb408f215956590b07c398e24a9a89144f6f6d99ae392730f91232ba5482e0d3075d45d7851fc67a2334aa
7
+ data.tar.gz: af37f9b843b3bdf129078907468ac77f00019a9d499eecf8412a2c44d544b3792c5d0394449ae5a391f9e43dc6d107e707070772aea4f14fba4a6a3a05fde73c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.8.9
4
+
5
+ Feature:
6
+
7
+ - Adds proc support to api_auth credentials (thanks to David Underwood for the PR).
8
+
3
9
  ## 1.8.8
4
10
 
5
11
  Fix:
@@ -69,19 +69,27 @@ module Flexirest
69
69
  end
70
70
 
71
71
  def api_auth_access_id
72
+ ret = nil
72
73
  if object_is_class?
73
- @object.api_auth_access_id
74
+ ret = @object.api_auth_access_id
75
+ ret = ret.call if ret.respond_to?(:call)
74
76
  else
75
- @object.class.api_auth_access_id
77
+ ret = @object.class.api_auth_access_id
78
+ ret = ret.call(@object) if ret.respond_to?(:call)
76
79
  end
80
+ ret
77
81
  end
78
82
 
79
83
  def api_auth_secret_key
84
+ ret = nil
80
85
  if object_is_class?
81
- @object.api_auth_secret_key
86
+ ret = @object.api_auth_secret_key
87
+ ret = ret.call if ret.respond_to?(:call)
82
88
  else
83
- @object.class.api_auth_secret_key
89
+ ret = @object.class.api_auth_secret_key
90
+ ret = ret.call(@object) if ret.respond_to?(:call)
84
91
  end
92
+ ret
85
93
  end
86
94
 
87
95
  def api_auth_options
@@ -1,3 +1,3 @@
1
1
  module Flexirest
2
- VERSION = "1.8.8"
2
+ VERSION = "1.8.9"
3
3
  end
@@ -83,6 +83,14 @@ describe Flexirest::Request do
83
83
  get :all, "/"
84
84
  end
85
85
 
86
+ class ApiAuthProcExampleClient < Flexirest::Base
87
+ base_url "http://www.example.com"
88
+ api_auth_credentials( Proc.new { |obj| obj ? "key-#{obj.id}" : "key" },
89
+ Proc.new { |obj| obj ? "secret-#{obj.id}" : "secret" }
90
+ )
91
+ get :all, "/"
92
+ end
93
+
86
94
  class ProcDefaultExampleClient < Flexirest::Base
87
95
  base_url "http://www.example.com"
88
96
  get :all, "/", defaults: (Proc.new do |params|
@@ -217,14 +225,14 @@ describe Flexirest::Request do
217
225
  AuthenticatedExampleClient.all
218
226
  end
219
227
 
220
- it "should get an HTTP connection with authentication using procs when called in a class context" do
228
+ it "should get an HTTP connection with basic authentication using procs when called in a class context" do
221
229
  connection = double(Flexirest::Connection).as_null_object
222
230
  expect(Flexirest::ConnectionManager).to receive(:get_connection).with("http://bill:jones@www.example.com").and_return(connection)
223
231
  expect(connection).to receive(:get).with("/", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
224
232
  AuthenticatedProcExampleClient.all
225
233
  end
226
234
 
227
- it "should get an HTTP connection with authentication using procs when called in an object context" do
235
+ it "should get an HTTP connection with basic authentication using procs when called in an object context" do
228
236
  connection = double(Flexirest::Connection).as_null_object
229
237
  expect(Flexirest::ConnectionManager).to receive(:get_connection).with("http://bill-1:jones-1@www.example.com").and_return(connection)
230
238
  expect(connection).to receive(:get).with("/?id=1", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
@@ -232,6 +240,19 @@ describe Flexirest::Request do
232
240
  obj.all
233
241
  end
234
242
 
243
+ it "should get an HTTP connection with API authentication using procs when called in a class context" do
244
+ header_expectation = {headers: {"Accept"=>"application/hal+json, application/json;q=0.5", "Content-Type"=>"application/x-www-form-urlencoded; charset=utf-8"}, api_auth: {api_auth_access_id: "key", api_auth_secret_key: "secret", api_auth_options: {}}}
245
+ expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/", header_expectation).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
246
+ ApiAuthProcExampleClient.all
247
+ end
248
+
249
+ it "should get an HTTP connection with API authentication using procs when called in an object context" do
250
+ header_expectation = {headers: {"Accept"=>"application/hal+json, application/json;q=0.5", "Content-Type"=>"application/x-www-form-urlencoded; charset=utf-8"}, api_auth: {api_auth_access_id: "key-1", api_auth_secret_key: "secret-1", api_auth_options: {}}}
251
+ expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/?id=1", header_expectation).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
252
+ obj = ApiAuthProcExampleClient.new(id: 1)
253
+ obj.all
254
+ end
255
+
235
256
  it "should get an HTTP connection when called and call get on it" do
236
257
  expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
237
258
  ExampleClient.all
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexirest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.8
4
+ version: 1.8.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jeffries
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-30 00:00:00.000000000 Z
11
+ date: 2020-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler