contentful 2.11.1 → 2.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/.rubocop_todo.yml +3 -3
- data/CHANGELOG.md +4 -0
- data/README.md +15 -0
- data/lib/contentful/base_resource.rb +7 -2
- data/lib/contentful/client.rb +23 -4
- data/lib/contentful/fields_resource.rb +2 -0
- data/lib/contentful/support.rb +2 -0
- data/lib/contentful/version.rb +1 -1
- data/spec/client_class_spec.rb +24 -3
- data/spec/client_configuration_spec.rb +27 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee3c004cc764ee56ec8a0f8a9cf739f5e5ab10e8fda5c327e1708829b8585145
|
4
|
+
data.tar.gz: 57d48057485ff6260801e2090bd3dd37e71c1fb6afb53628f1f1e93bc5eabb3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88eb373835acf4f0cf9d90a48c407fa082efb9e73052c33b0c89c4ed1f685cf37d6ea6f90306a683e2b4f49c972e4aa0f3c5784fe4c2e44a4da0124373d5ec85
|
7
|
+
data.tar.gz: 5d7f33c79174fb1867a6509af1c59a76afec8b04d5a3cc557117d0e90cbd394bdd3243522404bba18e210d50aa941c773614a2815f868e1358f28dae0e665898
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -12,7 +12,7 @@ Metrics/AbcSize:
|
|
12
12
|
|
13
13
|
# Offense count: 5
|
14
14
|
Metrics/CyclomaticComplexity:
|
15
|
-
Max:
|
15
|
+
Max: 10
|
16
16
|
|
17
17
|
# Offense count: 1
|
18
18
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
|
@@ -28,8 +28,8 @@ Metrics/MethodLength:
|
|
28
28
|
# Offense count: 2
|
29
29
|
# Configuration parameters: CountComments.
|
30
30
|
Metrics/ModuleLength:
|
31
|
-
Max:
|
31
|
+
Max: 500
|
32
32
|
|
33
33
|
# Offense count: 4
|
34
34
|
Metrics/PerceivedComplexity:
|
35
|
-
Max:
|
35
|
+
Max: 10
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## 2.12.0
|
6
|
+
### Added
|
7
|
+
* Add HTTP timeout configuration. [#196](https://github.com/contentful/contentful.rb/pull/196)
|
8
|
+
|
5
9
|
## 2.11.1
|
6
10
|
### Fixed
|
7
11
|
* Fixed coercion error when same entry was included more than once in the same RichText field. [#194](https://github.com/contentful/contentful.rb/pull/194)
|
data/README.md
CHANGED
@@ -337,6 +337,21 @@ client = Contentful::Client.new(
|
|
337
337
|
<td><code>nil</code></td>
|
338
338
|
<td>Password for proxy authentication.</td>
|
339
339
|
</tr>
|
340
|
+
<tr>
|
341
|
+
<td><code>timeout_read</code></td>
|
342
|
+
<td><code>nil</code></td>
|
343
|
+
<td>Number of seconds the request waits to read from the server before timing out.</td>
|
344
|
+
</tr>
|
345
|
+
<tr>
|
346
|
+
<td><code>timeout_write</code></td>
|
347
|
+
<td><code>nil</code></td>
|
348
|
+
<td>Number of seconds the request waits when writing to the server before timing out.</td>
|
349
|
+
</tr>
|
350
|
+
<tr>
|
351
|
+
<td><code>timeout_connect</code></td>
|
352
|
+
<td><code>nil</code></td>
|
353
|
+
<td>Number of seconds the request waits to connect to the server before timing out.</td>
|
354
|
+
</tr>
|
340
355
|
<tr>
|
341
356
|
<td><code>logger</code></td>
|
342
357
|
<td><code>nil</code></td>
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'support'
|
2
4
|
|
3
5
|
module Contentful
|
@@ -63,12 +65,15 @@ module Contentful
|
|
63
65
|
end
|
64
66
|
end
|
65
67
|
|
68
|
+
LINKS = %w[space contentType environment].freeze
|
69
|
+
TIMESTAMPS = %w[createdAt updatedAt deletedAt].freeze
|
70
|
+
|
66
71
|
def hydrate_sys
|
67
72
|
result = {}
|
68
73
|
raw.fetch('sys', {}).each do |k, v|
|
69
|
-
if
|
74
|
+
if LINKS.include?(k)
|
70
75
|
v = build_link(v)
|
71
|
-
elsif
|
76
|
+
elsif TIMESTAMPS.include?(k)
|
72
77
|
v = DateTime.parse(v)
|
73
78
|
end
|
74
79
|
result[Support.snakify(k, @configuration[:use_camel_case]).to_sym] = v
|
data/lib/contentful/client.rb
CHANGED
@@ -35,6 +35,9 @@ module Contentful
|
|
35
35
|
proxy_username: nil,
|
36
36
|
proxy_password: nil,
|
37
37
|
proxy_port: nil,
|
38
|
+
timeout_connect: nil,
|
39
|
+
timeout_read: nil,
|
40
|
+
timeout_write: nil,
|
38
41
|
max_rate_limit_retries: 1,
|
39
42
|
max_rate_limit_wait: 60,
|
40
43
|
max_include_resolution_depth: 20,
|
@@ -49,11 +52,13 @@ module Contentful
|
|
49
52
|
|
50
53
|
# Wraps the actual HTTP request via proxy
|
51
54
|
# @private
|
52
|
-
def self.get_http(url, query, headers = {}, proxy = {})
|
55
|
+
def self.get_http(url, query, headers = {}, proxy = {}, timeout = {})
|
56
|
+
http = HTTP[headers]
|
57
|
+
http = http.timeout(timeout) if timeout.any?
|
53
58
|
if proxy[:host]
|
54
|
-
|
59
|
+
http.via(proxy[:host], proxy[:port], proxy[:username], proxy[:password]).get(url, params: query)
|
55
60
|
else
|
56
|
-
|
61
|
+
http.get(url, params: query)
|
57
62
|
end
|
58
63
|
end
|
59
64
|
|
@@ -68,6 +73,9 @@ module Contentful
|
|
68
73
|
# @option given_configuration [String] :proxy_username
|
69
74
|
# @option given_configuration [String] :proxy_password
|
70
75
|
# @option given_configuration [Number] :proxy_port
|
76
|
+
# @option given_configuration [Number] :timeout_read
|
77
|
+
# @option given_configuration [Number] :timeout_write
|
78
|
+
# @option given_configuration [Number] :timeout_connect
|
71
79
|
# @option given_configuration [Number] :max_rate_limit_retries
|
72
80
|
# @option given_configuration [Number] :max_rate_limit_wait
|
73
81
|
# @option given_configuration [Number] :max_include_resolution_depth
|
@@ -110,6 +118,15 @@ module Contentful
|
|
110
118
|
}
|
111
119
|
end
|
112
120
|
|
121
|
+
# @private
|
122
|
+
def timeout_params
|
123
|
+
{
|
124
|
+
connect: configuration[:timeout_connect],
|
125
|
+
read: configuration[:timeout_read],
|
126
|
+
write: configuration[:timeout_write]
|
127
|
+
}.reject { |_, value| value.nil? }
|
128
|
+
end
|
129
|
+
|
113
130
|
# Returns the default configuration
|
114
131
|
# @private
|
115
132
|
def default_configuration
|
@@ -355,7 +372,8 @@ module Contentful
|
|
355
372
|
url,
|
356
373
|
request_query(request.query),
|
357
374
|
request_headers,
|
358
|
-
proxy_params
|
375
|
+
proxy_params,
|
376
|
+
timeout_params
|
359
377
|
), request
|
360
378
|
)
|
361
379
|
end
|
@@ -431,6 +449,7 @@ module Contentful
|
|
431
449
|
fail ArgumentError, 'The :dynamic_entries mode must be :auto or :manual' unless %i[auto manual].include?(
|
432
450
|
configuration[:dynamic_entries]
|
433
451
|
)
|
452
|
+
fail ArgumentError, 'Timeout parameters must be all omitted or all present' unless timeout_params.empty? || timeout_params.length == 3
|
434
453
|
end
|
435
454
|
end
|
436
455
|
end
|
data/lib/contentful/support.rb
CHANGED
data/lib/contentful/version.rb
CHANGED
data/spec/client_class_spec.rb
CHANGED
@@ -2,10 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Contentful::Client do
|
4
4
|
describe '#get' do
|
5
|
-
let(:client) { create_client }
|
5
|
+
let(:client) { create_client() }
|
6
6
|
let(:proxy_client) { create_client(proxy_host: '183.207.232.194',
|
7
7
|
proxy_port: 8080,
|
8
8
|
secure: false) }
|
9
|
+
let(:timeout_client) { create_client(timeout_connect: 1, timeout_read: 2, timeout_write: 3) }
|
9
10
|
let(:request) { Contentful::Request.new(nil, client.environment_url('/content_types'), nil, 'cat') }
|
10
11
|
|
11
12
|
it 'uses #base_url' do
|
@@ -32,17 +33,37 @@ describe Contentful::Client do
|
|
32
33
|
end
|
33
34
|
|
34
35
|
it 'calls #get_http' do
|
35
|
-
expect(client.class).to receive(:get_http).with(client.base_url + request.url, request.query, client.request_headers, client.proxy_params) { raw_fixture('content_type') }
|
36
|
+
expect(client.class).to receive(:get_http).with(client.base_url + request.url, request.query, client.request_headers, client.proxy_params, client.timeout_params) { raw_fixture('content_type') }
|
36
37
|
client.get(request)
|
37
38
|
end
|
38
39
|
|
39
40
|
it 'calls #get_http via proxy' do
|
40
|
-
expect(proxy_client.class).to receive(:get_http).with(proxy_client.base_url + request.url, request.query, proxy_client.request_headers, proxy_client.proxy_params) { raw_fixture('content_type') }
|
41
|
+
expect(proxy_client.class).to receive(:get_http).with(proxy_client.base_url + request.url, request.query, proxy_client.request_headers, proxy_client.proxy_params, client.timeout_params) { raw_fixture('content_type') }
|
41
42
|
proxy_client.get(request)
|
42
43
|
expect(proxy_client.proxy_params[:host]).to eq '183.207.232.194'
|
43
44
|
expect(proxy_client.proxy_params[:port]).to eq 8080
|
44
45
|
end
|
45
46
|
|
47
|
+
describe 'timeout params' do
|
48
|
+
context 'with timeouts configured' do
|
49
|
+
it 'calls #get_http with timeouts' do
|
50
|
+
expect(timeout_client.class).to receive(:get_http).with(timeout_client.base_url + request.url, request.query, timeout_client.request_headers, timeout_client.proxy_params, timeout_client.timeout_params) { raw_fixture('content_type') }
|
51
|
+
timeout_client.get(request)
|
52
|
+
expect(timeout_client.timeout_params[:connect]).to eq 1
|
53
|
+
expect(timeout_client.timeout_params[:read]).to eq 2
|
54
|
+
expect(timeout_client.timeout_params[:write]).to eq 3
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'without timeouts' do
|
59
|
+
it 'calls #get_http with timeouts' do
|
60
|
+
expect(client.class).to receive(:get_http).with(client.base_url + request.url, request.query, client.request_headers, client.proxy_params, client.timeout_params) { raw_fixture('content_type') }
|
61
|
+
client.get(request)
|
62
|
+
expect(client.timeout_params).to eq({})
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
46
67
|
describe 'build_resources parameter' do
|
47
68
|
it 'returns Contentful::Resource object if second parameter is true [default]' do
|
48
69
|
res = vcr('content_type') { client.get(request) }
|
@@ -347,4 +347,31 @@ describe 'Client Configuration Options' do
|
|
347
347
|
expect(client.request_headers['X-Contentful-User-Agent']).to eq client.contentful_user_agent
|
348
348
|
end
|
349
349
|
end
|
350
|
+
|
351
|
+
describe 'timeout options' do
|
352
|
+
let(:full_options) { { timeout_connect: 1, timeout_read: 2, timeout_write: 3 } }
|
353
|
+
|
354
|
+
it 'allows the three options to be present together' do
|
355
|
+
expect do
|
356
|
+
create_client(full_options)
|
357
|
+
end.not_to raise_error
|
358
|
+
end
|
359
|
+
|
360
|
+
it 'allows the three options to be omitted' do
|
361
|
+
expect do
|
362
|
+
create_client()
|
363
|
+
end.not_to raise_error
|
364
|
+
end
|
365
|
+
|
366
|
+
it 'does not allow only some options to be set' do
|
367
|
+
# Test that any combination of 1 or 2 keys is rejected
|
368
|
+
1.upto(2) do |options_count|
|
369
|
+
full_options.keys.combination(options_count).each do |option_keys|
|
370
|
+
expect do
|
371
|
+
create_client(full_options.select { |key, _| option_keys.include?(key) })
|
372
|
+
end.to raise_error(ArgumentError)
|
373
|
+
end
|
374
|
+
end
|
375
|
+
end
|
376
|
+
end
|
350
377
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contentful
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Contentful GmbH (Jan Lelis)
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2019-
|
13
|
+
date: 2019-04-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: http
|
@@ -532,7 +532,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
532
532
|
version: '0'
|
533
533
|
requirements: []
|
534
534
|
rubyforge_project:
|
535
|
-
rubygems_version: 2.7.
|
535
|
+
rubygems_version: 2.7.8
|
536
536
|
signing_key:
|
537
537
|
specification_version: 4
|
538
538
|
summary: contentful
|