flexirest 1.3.14 → 1.3.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +8 -0
- data/lib/flexirest/configuration.rb +13 -1
- data/lib/flexirest/connection.rb +9 -0
- data/lib/flexirest/connection_manager.rb +1 -1
- data/lib/flexirest/request.rb +10 -1
- data/lib/flexirest/version.rb +1 -1
- data/spec/lib/configuration_spec.rb +17 -2
- data/spec/lib/connection_manager_spec.rb +10 -2
- data/spec/lib/connection_spec.rb +34 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0704471f0511508955b73ff6c1a9f4490d6d2953
|
4
|
+
data.tar.gz: 2edada3ba600208f0df0f13aa06d2d91a4eb1a38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cd56fe8131e1dd4e835a6ca77c90896283f0441cadaaf7f4e844d51907dc8ddcbcdd39d260c12e9d95d18a12adcd3688bdf1e880c3f719b81068ecc4a4f52f7
|
7
|
+
data.tar.gz: e0901b4f1796580a9eb229609e8f43c5f6500bdef5819857a22d1a3279fc19669cbd49d6069fbd65627d3352c420026e98b272aa980d9f22b209561e71d833cf
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -538,6 +538,14 @@ end
|
|
538
538
|
|
539
539
|
For more information on how to generate an access id and secret key please read the [Api-Auth](https://github.com/mgomes/api_auth) documentation.
|
540
540
|
|
541
|
+
If you want to specify either the `:digest` or `:override_http_method` to ApiAuth, you can pass these in as options after the access ID and secret key, for example:
|
542
|
+
|
543
|
+
```ruby
|
544
|
+
class Person < Flexirest::Base
|
545
|
+
api_auth_credentials('123456', 'abcdef', digest: "sha256")
|
546
|
+
end
|
547
|
+
```
|
548
|
+
|
541
549
|
### Body Types
|
542
550
|
|
543
551
|
By default Flexirest puts the body in to normal CGI parameters in K=V&K2=V2 format. However, if you want to use JSON for your PUT/POST requests, you can use either (the other option, the default, is `:form_encoded`):
|
@@ -10,6 +10,7 @@ module Flexirest
|
|
10
10
|
@lazy_load = false
|
11
11
|
@api_auth_access_id = nil
|
12
12
|
@api_auth_secret_key = nil
|
13
|
+
@api_auth_options = {}
|
13
14
|
|
14
15
|
def base_url(value = nil)
|
15
16
|
@base_url ||= nil
|
@@ -136,7 +137,7 @@ module Flexirest
|
|
136
137
|
value ? @whiny_missing = value : @whiny_missing
|
137
138
|
end
|
138
139
|
|
139
|
-
def api_auth_credentials(access_id, secret_key)
|
140
|
+
def api_auth_credentials(access_id, secret_key, options = {})
|
140
141
|
begin
|
141
142
|
require 'api-auth'
|
142
143
|
rescue LoadError
|
@@ -145,6 +146,7 @@ module Flexirest
|
|
145
146
|
|
146
147
|
@api_auth_access_id = access_id
|
147
148
|
@api_auth_secret_key = secret_key
|
149
|
+
@api_auth_options = options
|
148
150
|
end
|
149
151
|
|
150
152
|
def using_api_auth?
|
@@ -172,6 +174,16 @@ module Flexirest
|
|
172
174
|
return nil
|
173
175
|
end
|
174
176
|
|
177
|
+
def api_auth_options
|
178
|
+
if !@api_auth_options.nil?
|
179
|
+
return @api_auth_options
|
180
|
+
elsif self.superclass.respond_to?(:api_auth_options)
|
181
|
+
return self.superclass.api_auth_options
|
182
|
+
end
|
183
|
+
|
184
|
+
return {}
|
185
|
+
end
|
186
|
+
|
175
187
|
def verbose!
|
176
188
|
@verbose = true
|
177
189
|
end
|
data/lib/flexirest/connection.rb
CHANGED
@@ -116,6 +116,15 @@ module Flexirest
|
|
116
116
|
|
117
117
|
def sign_request(request, api_auth)
|
118
118
|
return if api_auth[:api_auth_access_id].nil? || api_auth[:api_auth_secret_key].nil?
|
119
|
+
ApiAuth.sign!(
|
120
|
+
request,
|
121
|
+
api_auth[:api_auth_access_id],
|
122
|
+
api_auth[:api_auth_secret_key],
|
123
|
+
api_auth[:api_auth_options])
|
124
|
+
rescue ArgumentError
|
125
|
+
if api_auth[:api_auth_options] && api_auth[:api_auth_options].keys.size > 0
|
126
|
+
Flexirest::Logger.warn("Specifying Api-Auth options isn't supported with your version of ApiAuth")
|
127
|
+
end
|
119
128
|
ApiAuth.sign!(
|
120
129
|
request,
|
121
130
|
api_auth[:api_auth_access_id],
|
data/lib/flexirest/request.rb
CHANGED
@@ -75,6 +75,14 @@ module Flexirest
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
+
def api_auth_options
|
79
|
+
if object_is_class?
|
80
|
+
@object.api_auth_options
|
81
|
+
else
|
82
|
+
@object.class.api_auth_options
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
78
86
|
def username
|
79
87
|
if object_is_class?
|
80
88
|
@object.username
|
@@ -338,7 +346,8 @@ module Flexirest
|
|
338
346
|
if using_api_auth?
|
339
347
|
request_options[:api_auth] = {
|
340
348
|
:api_auth_access_id => api_auth_access_id,
|
341
|
-
:api_auth_secret_key => api_auth_secret_key
|
349
|
+
:api_auth_secret_key => api_auth_secret_key,
|
350
|
+
:api_auth_options => api_auth_options
|
342
351
|
}
|
343
352
|
end
|
344
353
|
if @method[:options][:timeout]
|
data/lib/flexirest/version.rb
CHANGED
@@ -157,11 +157,18 @@ describe Flexirest::Configuration do
|
|
157
157
|
it "should be false using_api_auth?" do
|
158
158
|
expect(Flexirest::Base.using_api_auth?).to be_falsey
|
159
159
|
end
|
160
|
+
|
161
|
+
it "should raise Flexirest::MissingOptionalLibraryError if api-auth isn't installed" do
|
162
|
+
expect(ConfigurationExample).to receive(:require).with("api-auth").and_raise(LoadError)
|
163
|
+
expect {
|
164
|
+
ConfigurationExample.api_auth_credentials('id123', 'secret123', digest: "sha256")
|
165
|
+
}.to raise_error(Flexirest::MissingOptionalLibraryError)
|
166
|
+
end
|
160
167
|
end
|
161
168
|
|
162
169
|
context 'setting api auth credentials' do
|
163
170
|
before(:each) do
|
164
|
-
ConfigurationExample.api_auth_credentials('id123', 'secret123')
|
171
|
+
ConfigurationExample.api_auth_credentials('id123', 'secret123', digest: "sha256")
|
165
172
|
end
|
166
173
|
|
167
174
|
it "should remember setting using_api_auth?" do
|
@@ -176,6 +183,15 @@ describe Flexirest::Configuration do
|
|
176
183
|
expect(ConfigurationExample.api_auth_secret_key).to eq('secret123')
|
177
184
|
end
|
178
185
|
|
186
|
+
it "should remember setting api_auth_options" do
|
187
|
+
expect(ConfigurationExample.api_auth_options).to eq({digest: "sha256"})
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should return an empty hash for api_auth_options if it got reset to nil" do
|
191
|
+
ConfigurationExample.instance_variable_set(:@api_auth_options, nil)
|
192
|
+
expect(ConfigurationExample.api_auth_options).to eq({})
|
193
|
+
end
|
194
|
+
|
179
195
|
it "should inherit api_auth_credentials when not set" do
|
180
196
|
class ConfigurationExtension < ConfigurationExample
|
181
197
|
end
|
@@ -248,7 +264,6 @@ describe Flexirest::Configuration do
|
|
248
264
|
|
249
265
|
ConfigurationExample.faraday_config.call(faraday_double)
|
250
266
|
end
|
251
|
-
|
252
267
|
end
|
253
268
|
|
254
269
|
end
|
@@ -34,10 +34,18 @@ describe Flexirest::ConnectionManager do
|
|
34
34
|
expect(found_connection).to eq(connection)
|
35
35
|
end
|
36
36
|
|
37
|
-
it "should call '
|
37
|
+
it "should call 'in_parallel' for a session and yield procedure inside that block" do
|
38
38
|
Flexirest::Base.adapter = :typhoeus
|
39
|
-
|
39
|
+
Flexirest::ConnectionManager.get_connection("http://www.example.com").session
|
40
40
|
expect { |b| Flexirest::ConnectionManager.in_parallel("http://www.example.com", &b)}.to yield_control
|
41
41
|
Flexirest::Base._reset_configuration!
|
42
42
|
end
|
43
|
+
|
44
|
+
it "should raise Flexirest::MissingOptionalLibraryError if Typhous isn't available" do
|
45
|
+
Flexirest::Base.adapter = :typhoeus
|
46
|
+
Flexirest::ConnectionManager.get_connection("http://www.example.com").session
|
47
|
+
expect(Flexirest::ConnectionManager).to receive(:require).and_raise(LoadError)
|
48
|
+
expect { Flexirest::ConnectionManager.in_parallel("http://www.example.com")}.to raise_error(Flexirest::MissingOptionalLibraryError)
|
49
|
+
Flexirest::Base._reset_configuration!
|
50
|
+
end
|
43
51
|
end
|
data/spec/lib/connection_spec.rb
CHANGED
@@ -111,7 +111,7 @@ describe Flexirest::Connection do
|
|
111
111
|
it 'should set a custom timeout' do
|
112
112
|
stub_request(:get, "www.example.com/foo")
|
113
113
|
.to_return(body: "{result:true}")
|
114
|
-
expect_any_instance_of(Flexirest::Connection).to receive(:set_per_request_timeout)
|
114
|
+
expect_any_instance_of(Flexirest::Connection).to receive(:set_per_request_timeout).and_call_original
|
115
115
|
@connection.get("/foo", {:timeout => "5"})
|
116
116
|
end
|
117
117
|
end
|
@@ -124,7 +124,8 @@ describe Flexirest::Connection do
|
|
124
124
|
@options = {
|
125
125
|
:api_auth => {
|
126
126
|
:api_auth_access_id => 'id123',
|
127
|
-
:api_auth_secret_key => 'secret123'
|
127
|
+
:api_auth_secret_key => 'secret123',
|
128
|
+
:api_auth_options => {}
|
128
129
|
}
|
129
130
|
}
|
130
131
|
|
@@ -142,7 +143,37 @@ describe Flexirest::Connection do
|
|
142
143
|
.with(:headers => @default_headers)
|
143
144
|
.to_return(body: "{result:true}")
|
144
145
|
result = @connection.get("/foo", @options)
|
145
|
-
|
146
|
+
auth_header = result.env.request_headers['Authorization']
|
147
|
+
expect(auth_header == "APIAuth id123:TQiQIW6vVaDC5jvh99uTNkxIg6Q=" || auth_header == "APIAuth id123:PMWBThkB8vKbvUccHvoqu9G3eVk=").to be_truthy
|
148
|
+
end
|
149
|
+
|
150
|
+
if Gem.loaded_specs["api-auth"].version.to_s >= "2.0.0"
|
151
|
+
it 'should have an Authorization header with a custom digest method' do
|
152
|
+
puts Gem.loaded_specs["api-auth"].version
|
153
|
+
@options[:api_auth][:api_auth_options] = {
|
154
|
+
digest: "sha256"
|
155
|
+
}
|
156
|
+
stub_request(:get, "www.example.com/foo")
|
157
|
+
.with(:headers => @default_headers)
|
158
|
+
.to_return(body: "{result:true}")
|
159
|
+
result = @connection.get("/foo", @options)
|
160
|
+
expect(result.env.request_headers['Authorization']).to eq("APIAuth-HMAC-SHA256 id123:fDrJfQ1fOoPFHtzhqqdHby+v6bbn2K8b2HR5AKo3vmg=")
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should warn about using custom digest methods with an Authorization header if ApiAuth doesn't support it" do
|
165
|
+
@options[:api_auth][:api_auth_options] = {
|
166
|
+
digest: "sha256"
|
167
|
+
}
|
168
|
+
stub_request(:get, "www.example.com/foo")
|
169
|
+
.with(:headers => @default_headers)
|
170
|
+
.to_return(body: "{result:true}")
|
171
|
+
expect(ApiAuth).to receive(:sign!).once.with(anything, anything, anything, {digest: "sha256"}).and_raise(ArgumentError)
|
172
|
+
expect(ApiAuth).to receive(:sign!).once.with(anything, anything, anything).and_call_original
|
173
|
+
expect(Flexirest::Logger).to receive(:warn)
|
174
|
+
result = @connection.get("/foo", @options)
|
175
|
+
auth_header = result.env.request_headers['Authorization']
|
176
|
+
expect(auth_header == "APIAuth id123:TQiQIW6vVaDC5jvh99uTNkxIg6Q=" || auth_header == "APIAuth id123:PMWBThkB8vKbvUccHvoqu9G3eVk=").to be_truthy
|
146
177
|
end
|
147
178
|
|
148
179
|
it 'should have an Content-MD5 header' do
|
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.3.
|
4
|
+
version: 1.3.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Jeffries
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|