Skip to content
This repository was archived by the owner on May 8, 2024. It is now read-only.

Commit faa2823

Browse files
authored
Add environment as top-level option and fetching from env vars (#62)
1 parent 02a70bf commit faa2823

File tree

6 files changed

+18
-9
lines changed

6 files changed

+18
-9
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
rvm:
2-
- 2.2.3
32
- 2.3.1
43
- 2.4.0
4+
- 2.5.1
55

66
script: "bundle exec rake test"
77

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Change Log
22

33
## Unreleased
4+
### Added
5+
* Added top-level environment assignment, with support for `ENV_` access [#61](https://github.com/contentful/jekyll-contentful-data-import/issues/61)
46

5-
## 1.6.0
6-
7+
## v1.6.0
78
### Added
89
* Independent file per entry [#45](https://github.com/contentful/jekyll-contentful-data-import/pull/45) [#10](https://github.com/contentful/jekyll-contentful-data-import/issues/10) [#23](https://github.com/contentful/jekyll-contentful-data-import/pull/23) [#25](https://github.com/contentful/jekyll-contentful-data-import/issues/25)
910
* Added User Agent Integration Headers

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ contentful:
4646
- example: # Jekyll _data folder identifier - Required
4747
space: cfexampleapi # Required
4848
access_token: b4c0n73n7fu1 # Required
49+
environment: master # Optional
4950
cda_query: # Optional
5051
include: 2
5152
limit: 100
@@ -65,6 +66,7 @@ Parameter | Description
6566
---------- | ------------
6667
space | Contentful Space ID
6768
access_token | Contentful Delivery API access token
69+
environment | Space environment, defaults to `master`
6870
cda_query | Hash describing query configuration. See [contentful.rb](https://github.com/contentful/contentful.rb) for more info (look for filter options there). Note that by default only 100 entries will be fetched, this can be configured to up to 1000 entries using the `limit` option.
6971
all_entries | Boolean, if true will run multiple queries to the API until it fetches all entries for the space
7072
all_entries_page_size | Integer, the amount of maximum entries per CDA Request when fetching :all_entries
@@ -138,23 +140,25 @@ therefore you can do the following:
138140
- example:
139141
space: ENV_CONTENTFUL_SPACE_ID
140142
access_token: ENV_CONTENTFUL_ACCESS_TOKEN
143+
environment: ENV_CONTENTFUL_ENVIRONMENT
141144
```
142145

143-
(Your Space ID will be looked upon on `ENV['CONTENTFUL_SPACE_ID']` and your Access Token on `ENV['CONTENTFUL_ACCESS_TOKEN']`.)
146+
(Your Space ID will be looked upon on `ENV['CONTENTFUL_SPACE_ID']`, your Access Token on `ENV['CONTENTFUL_ACCESS_TOKEN']` and your environment on `ENV['CONTENTFUL_ENVIRONMENT']`.)
144147

145148
3. Either add the following variables to your shell's configuration file (.bashrc or .bash_profile, for example):
146149

147150
```bash
148151
export CONTENTFUL_ACCESS_TOKEN=abc123
149152
export CONTENTFUL_SPACE_ID=abc123
153+
export CONTENTFUL_ENVIRONMENT=master
150154
```
151155

152156
(And run `source ~/.bashrc` or open new terminal to enable changes.)
153157

154158
Or specify them on the command line:
155159

156160
```bash
157-
CONTENTFUL_ACCESS_TOKEN=abc123 CONTENTFUL_SPACE_ID=abc123 jekyll contentful
161+
CONTENTFUL_ACCESS_TOKEN=abc123 CONTENTFUL_SPACE_ID=abc123 CONTENTFUL_ENVIRONMENT=master jekyll contentful
158162
```
159163

160164
4. Party.

lib/jekyll-contentful-data-import.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require 'jekyll-contentful-data-import/version'
22

3-
%w(contentful).each do |file|
3+
%w[contentful].each do |file|
44
require File.expand_path("jekyll/commands/#{file}.rb", File.dirname(__FILE__))
55
end

lib/jekyll-contentful-data-import/importer.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def run
1919
space_client = client(
2020
value_for(options, 'space'),
2121
value_for(options, 'access_token'),
22+
value_for(options, 'environment'),
2223
client_options(options.fetch('client_options', {}))
2324
)
2425

@@ -62,7 +63,7 @@ def export_data_multiple_files(name, entries, options)
6263

6364
def value_for(options, key)
6465
potential_value = options[key]
65-
return ENV[potential_value.gsub('ENV_', '')] if potential_value.start_with?('ENV_')
66+
return ENV[potential_value.gsub('ENV_', '')] if !potential_value.nil? && potential_value.start_with?('ENV_')
6667
potential_value
6768
end
6869

@@ -90,10 +91,11 @@ def get_entries(space_client, options)
9091
all
9192
end
9293

93-
def client(space, access_token, options = {})
94+
def client(space, access_token, environment = nil, options = {})
9495
options = {
9596
space: space,
9697
access_token: access_token,
98+
environment: environment || 'master',
9799
dynamic_entries: :auto,
98100
raise_errors: true,
99101
integration_name: 'jekyll',

spec/jekyll-contentful/importer_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def run; end
4545
expect(::Contentful::Client).to receive(:new).with(
4646
space: 'foo',
4747
access_token: 'foobar',
48+
environment: 'master',
4849
dynamic_entries: :auto,
4950
raise_errors: true,
5051
integration_name: 'jekyll',
@@ -58,13 +59,14 @@ def run; end
5859
expect(::Contentful::Client).to receive(:new).with(
5960
space: 'foo',
6061
access_token: 'foobar',
62+
environment: 'master',
6163
dynamic_entries: :auto,
6264
raise_errors: false,
6365
integration_name: 'jekyll',
6466
integration_version: Jekyll::Contentful::VERSION
6567
)
6668

67-
subject.client('foo', 'foobar', raise_errors: false)
69+
subject.client('foo', 'foobar', 'master', raise_errors: false)
6870
end
6971
end
7072

0 commit comments

Comments
 (0)