contentful 0.3.5 → 0.4.0
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +27 -1
- data/lib/contentful/client.rb +24 -7
- data/lib/contentful/version.rb +1 -1
- data/spec/client_class_spec.rb +20 -7
- 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: ca7aa5d86409ba09e10e10ad5056804799157b03
|
4
|
+
data.tar.gz: e8a7314fea96f4053656adaa1c88b1a0264f203d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f36a0f4e0bdef6bc0740a697f6b055eb4df6846af106695daf7dc9f54f47b9cdf914ed4ea0a5037591804920a81202c616b358779ff45826edfef168ffed596
|
7
|
+
data.tar.gz: d019ae9b609ae364304b4057dabab58e736e3233c90ba2685e97ebbb39d371097d68fea725f8b485d5974519ec8ef6ff6a679ed765ac340e8d58c1e46aba95e4
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -193,6 +193,32 @@ Logger.new('logfile.log')
|
|
193
193
|
### :log_level
|
194
194
|
The default severity is set to INFO and logs only the request attributes (headers, parameters and url). Setting it to DEBUG will also log the raw JSON response.
|
195
195
|
|
196
|
+
### :proxy_host
|
197
|
+
|
198
|
+
To be able to perform a request behind a proxy, you need to specify a ```:proxy_host```. This can be a domain or IP address of the proxy server.
|
199
|
+
|
200
|
+
### :proxy_port
|
201
|
+
|
202
|
+
Specify the port number that is used by the proxy server for client connections.
|
203
|
+
|
204
|
+
### :port_password, :port_username
|
205
|
+
|
206
|
+
To use the proxy with authentication, you need to specify ```port_username``` and ```port_password```.
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
### Proxy example
|
211
|
+
|
212
|
+
```ruby
|
213
|
+
client = Contentful::Client.new(
|
214
|
+
access_token: 'b4c0n73n7fu1',
|
215
|
+
space: 'cfexampleapi',
|
216
|
+
proxy_host: '127.0.0.1',
|
217
|
+
proxy_port: 8080,
|
218
|
+
proxy_username: 'username',
|
219
|
+
proxy_password: 'secret_password',
|
220
|
+
)
|
221
|
+
```
|
196
222
|
|
197
223
|
## Advanced Usage
|
198
224
|
### Custom Resource Classes
|
@@ -289,7 +315,7 @@ first_entry = client.sync(initial: true, type: 'Entry').first_page.items.first
|
|
289
315
|
first_entry.fields('de-DE') # Returns German localizations
|
290
316
|
```
|
291
317
|
|
292
|
-
##
|
318
|
+
## Rate-limit
|
293
319
|
The library does not make assumptions on the rate limit but reacts to `HTTP 429` by returning an error object.
|
294
320
|
You should handle this within your code and either do the delay calculation naive (fixed amount of seconds) or more elaborated (exponential increase) depending by the structure of your code.
|
295
321
|
|
data/lib/contentful/client.rb
CHANGED
@@ -25,14 +25,22 @@ module Contentful
|
|
25
25
|
raw_mode: false,
|
26
26
|
gzip_encoded: false,
|
27
27
|
logger: false,
|
28
|
-
log_level: Logger::INFO
|
28
|
+
log_level: Logger::INFO,
|
29
|
+
proxy_host: nil,
|
30
|
+
proxy_username: nil,
|
31
|
+
proxy_password: nil,
|
32
|
+
proxy_port: nil
|
29
33
|
}
|
30
34
|
|
31
|
-
attr_reader :configuration, :dynamic_entry_cache, :logger
|
35
|
+
attr_reader :configuration, :dynamic_entry_cache, :logger, :proxy
|
32
36
|
|
33
|
-
# Wraps the actual HTTP request
|
34
|
-
def self.get_http(url, query, headers = {})
|
35
|
-
|
37
|
+
# Wraps the actual HTTP request via proxy
|
38
|
+
def self.get_http(url, query, headers = {}, proxy = {})
|
39
|
+
if proxy[:host]
|
40
|
+
HTTP[headers].via(proxy[:host], proxy[:port], proxy[:username], proxy[:password]).get(url, params: query)
|
41
|
+
else
|
42
|
+
HTTP[headers].get(url, params: query)
|
43
|
+
end
|
36
44
|
end
|
37
45
|
|
38
46
|
def initialize(given_configuration = {})
|
@@ -53,6 +61,15 @@ module Contentful
|
|
53
61
|
logger.level = configuration[:log_level] if logger
|
54
62
|
end
|
55
63
|
|
64
|
+
def proxy_params
|
65
|
+
{
|
66
|
+
host: configuration[:proxy_host],
|
67
|
+
port: configuration[:proxy_port],
|
68
|
+
username: configuration[:proxy_username],
|
69
|
+
password: configuration[:proxy_password]
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
56
73
|
# Returns the default configuration
|
57
74
|
def default_configuration
|
58
75
|
DEFAULT_CONFIGURATION.dup
|
@@ -126,7 +143,6 @@ module Contentful
|
|
126
143
|
if configuration[:authentication_mechanism] == :query_string
|
127
144
|
query['access_token'] = configuration[:access_token]
|
128
145
|
end
|
129
|
-
|
130
146
|
query
|
131
147
|
end
|
132
148
|
|
@@ -140,7 +156,8 @@ module Contentful
|
|
140
156
|
self.class.get_http(
|
141
157
|
url,
|
142
158
|
request_query(request.query),
|
143
|
-
request_headers
|
159
|
+
request_headers,
|
160
|
+
proxy_params
|
144
161
|
), request
|
145
162
|
)
|
146
163
|
|
data/lib/contentful/version.rb
CHANGED
data/spec/client_class_spec.rb
CHANGED
@@ -3,7 +3,10 @@ require 'spec_helper'
|
|
3
3
|
describe Contentful::Client do
|
4
4
|
describe '#get' do
|
5
5
|
let(:client) { create_client }
|
6
|
-
let(:
|
6
|
+
let(:proxy_client) { create_client(proxy_host: '183.207.232.194',
|
7
|
+
proxy_port: 8080,
|
8
|
+
secure: false) }
|
9
|
+
let(:request) do
|
7
10
|
Contentful::Request.new(nil, '/content_types', nil, 'cat')
|
8
11
|
end
|
9
12
|
|
@@ -14,11 +17,13 @@ describe Contentful::Client do
|
|
14
17
|
end
|
15
18
|
|
16
19
|
it 'uses #request_headers' do
|
17
|
-
stub(client).request_headers do
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
stub(client).request_headers do
|
21
|
+
{
|
22
|
+
'User-Agent' => 'RubyContentfulGem/0.1.0',
|
23
|
+
'Authorization' => 'Bearer b4c0n73n7fu1',
|
24
|
+
'Content-Type' => 'application/vnd.contentful.delivery.v1+json',
|
25
|
+
}
|
26
|
+
end
|
22
27
|
vcr('content_type') { client.get(request) }
|
23
28
|
expect(client).to have_received.request_headers
|
24
29
|
end
|
@@ -38,7 +43,15 @@ describe Contentful::Client do
|
|
38
43
|
it 'calls #get_http' do
|
39
44
|
stub(client.class).get_http { raw_fixture('content_type') }
|
40
45
|
client.get(request)
|
41
|
-
expect(client.class).to have_received.get_http(client.base_url + request.url, request.query, client.request_headers)
|
46
|
+
expect(client.class).to have_received.get_http(client.base_url + request.url, request.query, client.request_headers, client.proxy_params)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'calls #get_http via proxy' do
|
50
|
+
stub(proxy_client.class).get_http { raw_fixture('content_type') }
|
51
|
+
proxy_client.get(request)
|
52
|
+
expect(proxy_client.class).to have_received.get_http(proxy_client.base_url + request.url, request.query, proxy_client.request_headers, proxy_client.proxy_params)
|
53
|
+
expect(proxy_client.proxy_params[:host]).to eq '183.207.232.194'
|
54
|
+
expect(proxy_client.proxy_params[:port]).to eq 8080
|
42
55
|
end
|
43
56
|
|
44
57
|
describe 'build_resources parameter' do
|
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: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Contentful GmbH (Jan Lelis)
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-10-
|
12
|
+
date: 2014-10-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: http
|