contentful_bootstrap 3.9.1 → 3.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e58541eab6426bb8208b9b0c33244d1bea9d65fa
4
- data.tar.gz: d0e26fbf73b7e1c01e080eb1268dc90bab01cee0
3
+ metadata.gz: 87bf2f847f495230e20ba2d7ddaaf81f9549275a
4
+ data.tar.gz: 30ee1008a09c1297e319e82350256ad94892da13
5
5
  SHA512:
6
- metadata.gz: 03150c56609259ab73f72026b0feaf962db95cb7b75066dc8166f03568b2022ff73111021bd23220ba3cd0291993d2b65826243d7ba56df906830aaa8fea2ec2
7
- data.tar.gz: 22f9528bb02b02b60ffa529df0623c156c1816b8bb8f26e7370bdb93f83284cdeed8c5c9e684c9aae93ccf233792ee065e516c920be6c06e487e721d5009807f
6
+ metadata.gz: 4392ba1adde7708b019dd6b6fa6d50568435c2a57712f430639c54db9077479bac1183f9c58e52b75cee700cf8025aa2f4b6a90e352af5ef195cc6663348547f
7
+ data.tar.gz: dabba1d78944aecd7f117e95f85124ddf5be620c4b530576c65ac7adfa74d585838fef53d2341ee391b3627f35a6647bed15a4798c5d48d5148da2b98865e312
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## v3.10.0
6
+ ### Added
7
+ * Added `--content-type-ids` filter to `generate_json` command to allow selecting which content types to import.
8
+
5
9
  ## v3.9.1
6
10
  ### Fixed
7
11
  * Fixed an issue in which assets save as `Contentful::Management::File` objects instead of as JSON when using `--mark-processed`.
data/README.md CHANGED
@@ -38,7 +38,7 @@ $ contentful_bootstrap generate_token <space_id> [--name token_name] [--config C
38
38
  You can also generate JSON Templates from existing spaces by doing:
39
39
 
40
40
  ```bash
41
- $ contentful_bootstrap generate_json <space_id> <delivery_api_access_token> [--output-file OUTPUT PATH] [--content-types-only] [--use-preview] [--quiet]
41
+ $ contentful_bootstrap generate_json <space_id> <delivery_api_access_token> [--output-file OUTPUT PATH] [--content-type-ids ct_id_1,ct_id_2] [--content-types-only] [--use-preview] [--quiet]
42
42
  ```
43
43
 
44
44
  You can update existing spaces from JSON Templates by doing:
@@ -140,6 +140,7 @@ Contentful::Bootstrap::CommandRunner.new.generate_json(
140
140
  use_preview: false, # if true will fetch from the Preview API instead of Delivery API
141
141
  filename: nil, # path to file in which to store JSON
142
142
  content_types_only: false, # if true will not fetch Entries and Assets
143
+ content_type_ids: [], # if any ID is specified, JSON will only include those content types and entries that have that content type
143
144
  quiet: false, # if true will not output to STDOUT - only when filename is provided
144
145
  no_input: false # if true all input operations won't be done, exceptions thrown with alternatives through configuration file in cases in which it cannot proceed
145
146
  )
@@ -154,6 +155,7 @@ options = {
154
155
  use_preview: false, # if true will fetch from the Preview API instead of Delivery API
155
156
  filename: "template.json", # Will save the JSON to the specified file
156
157
  content_types_only: false, # if true will not fetch Entries and Assets
158
+ content_type_ids: [], # if any ID is specified, JSON will only include those content types and entries that have that content type
157
159
  quiet: false, # if true will not output to STDOUT
158
160
  no_input: false # if true all input operations won't be done, exceptions thrown with alternatives through configuration file in cases in which it cannot proceed
159
161
  }
@@ -83,6 +83,9 @@ subcommands = {
83
83
  opts.on("-p", "--use-preview", "Use Preview API") do |p|
84
84
  options[:use_preview] = p
85
85
  end
86
+ opts.on("-i", "--content-type-ids <ID_1>,<ID_2>", ::Array, "Array of content type IDs to import") do |ids|
87
+ options[:content_type_ids] = ids
88
+ end
86
89
  opts.on("-o OUTPUT_PATH", "--output-file OUTPUT_PATH", "Specify Output File") do |f|
87
90
  options[:filename] = f
88
91
  end
@@ -35,11 +35,18 @@ module Contentful
35
35
  content_types_only = options.fetch(:content_types_only, false)
36
36
  quiet = options.fetch(:quiet, false)
37
37
  use_preview = options.fetch(:use_preview, false)
38
+ content_type_ids = options.fetch(:content_type_ids, [])
38
39
 
39
40
  fail 'Access Token required' if access_token.nil?
40
41
 
41
42
  Contentful::Bootstrap::Commands::GenerateJson.new(
42
- space_id, access_token, filename, content_types_only, quiet, use_preview
43
+ space_id,
44
+ access_token,
45
+ filename,
46
+ content_types_only,
47
+ quiet,
48
+ use_preview,
49
+ content_type_ids
43
50
  ).run
44
51
  end
45
52
  end
@@ -5,14 +5,15 @@ module Contentful
5
5
  module Bootstrap
6
6
  module Commands
7
7
  class GenerateJson
8
- attr_reader :space_id, :filename, :access_token, :content_types_only, :use_preview
9
- def initialize(space_id, access_token, filename = nil, content_types_only = false, quiet = false, use_preview = false)
8
+ attr_reader :space_id, :filename, :access_token, :content_types_only, :use_preview, :content_type_ids
9
+ def initialize(space_id, access_token, filename = nil, content_types_only = false, quiet = false, use_preview = false, content_type_ids = [])
10
10
  @space_id = space_id
11
11
  @access_token = access_token
12
12
  @filename = filename
13
13
  @content_types_only = content_types_only
14
14
  @quiet = quiet
15
15
  @use_preview = use_preview
16
+ @content_type_ids = content_type_ids
16
17
  end
17
18
 
18
19
  def run
@@ -29,7 +30,8 @@ module Contentful
29
30
  space_id,
30
31
  access_token,
31
32
  content_types_only,
32
- use_preview
33
+ use_preview,
34
+ content_type_ids
33
35
  ).generate_json
34
36
 
35
37
  write(json)
@@ -10,9 +10,9 @@ module Contentful
10
10
  DELIVERY_API_URL = 'cdn.contentful.com'.freeze
11
11
  PREVIEW_API_URL = 'preview.contentful.com'.freeze
12
12
 
13
- attr_reader :content_types_only, :client
13
+ attr_reader :content_types_only, :content_type_ids, :client
14
14
 
15
- def initialize(space_id, access_token, content_types_only, use_preview)
15
+ def initialize(space_id, access_token, content_types_only, use_preview, content_type_ids)
16
16
  @client = Contentful::Client.new(
17
17
  access_token: access_token,
18
18
  space: space_id,
@@ -21,6 +21,7 @@ module Contentful
21
21
  api_url: use_preview ? PREVIEW_API_URL : DELIVERY_API_URL
22
22
  )
23
23
  @content_types_only = content_types_only
24
+ @content_type_ids = content_type_ids
24
25
  end
25
26
 
26
27
  def generate_json
@@ -35,7 +36,10 @@ module Contentful
35
36
  private
36
37
 
37
38
  def content_types
38
- proccessed_content_types = @client.content_types.map do |type|
39
+ query = {}
40
+ query['sys.id[in]'] = content_type_ids.join(',') unless content_type_ids.empty?
41
+
42
+ proccessed_content_types = @client.content_types(query).map do |type|
39
43
  result = { 'id' => type.sys[:id], 'name' => type.name }
40
44
  result['displayField'] = type.display_field unless type.display_field.nil?
41
45
 
@@ -80,7 +84,17 @@ module Contentful
80
84
  entries = {}
81
85
 
82
86
  query = { order: 'sys.createdAt', limit: 1000 }
83
- entries_count = @client.entries(limit: 1).total
87
+ count_query = { limit: 1 }
88
+
89
+ unless content_type_ids.empty?
90
+ search_key = 'sys.contentType.sys.id[in]'
91
+ ids = content_type_ids.join(',')
92
+
93
+ query[search_key] = ids
94
+ count_query[search_key] = ids
95
+ end
96
+
97
+ entries_count = @client.entries(count_query).total
84
98
  ((entries_count / 1000) + 1).times do |i|
85
99
  query[:skip] = i * 1000
86
100
 
@@ -1,6 +1,6 @@
1
1
  module Contentful
2
2
  module Bootstrap
3
- VERSION = '3.9.1'
3
+ VERSION = '3.10.0'
4
4
 
5
5
  def self.major_version
6
6
  VERSION.split('.').first.to_i
@@ -101,7 +101,7 @@ describe Contentful::Bootstrap::CommandRunner do
101
101
  allow_any_instance_of(Contentful::Bootstrap::Commands::GenerateJson).to receive(:run)
102
102
 
103
103
  expect(Contentful::Bootstrap::Commands::GenerateJson).to receive(:new).with(
104
- 'foo', 'bar', nil, false, false, false
104
+ 'foo', 'bar', nil, false, false, false, []
105
105
  ).and_call_original
106
106
 
107
107
  subject.generate_json('foo', access_token: 'bar')
@@ -111,7 +111,7 @@ describe Contentful::Bootstrap::CommandRunner do
111
111
  allow_any_instance_of(Contentful::Bootstrap::Commands::GenerateJson).to receive(:run)
112
112
 
113
113
  expect(Contentful::Bootstrap::Commands::GenerateJson).to receive(:new).with(
114
- 'foo', 'bar', 'baz', true, false, false
114
+ 'foo', 'bar', 'baz', true, false, false, []
115
115
  ).and_call_original
116
116
 
117
117
  subject.generate_json('foo', access_token: 'bar', filename: 'baz', content_types_only: true)
@@ -48,6 +48,38 @@ describe Contentful::Bootstrap::Commands::GenerateJson do
48
48
  subject.run
49
49
  }
50
50
  end
51
+
52
+ describe 'specific content types' do
53
+ it 'can select a single content type' do
54
+ vcr('generate_json_single_ct') {
55
+ subject.instance_variable_set(:@space_id, 'cfexampleapi')
56
+ subject.instance_variable_set(:@access_token, 'b4c0n73n7fu1')
57
+ subject.instance_variable_set(:@content_type_ids, ['cat'])
58
+ subject.instance_variable_set(:@quiet, true)
59
+
60
+ json_fixture('cfexampleapi_cat') { |json|
61
+ expect(subject).to receive(:write).with(JSON.pretty_generate(json))
62
+ }
63
+
64
+ subject.run
65
+ }
66
+ end
67
+
68
+ it 'can select multiple content types' do
69
+ vcr('generate_json_multi_ct') {
70
+ subject.instance_variable_set(:@space_id, 'cfexampleapi')
71
+ subject.instance_variable_set(:@access_token, 'b4c0n73n7fu1')
72
+ subject.instance_variable_set(:@content_type_ids, ['cat', 'human'])
73
+ subject.instance_variable_set(:@quiet, true)
74
+
75
+ json_fixture('cfexampleapi_cat_human') { |json|
76
+ expect(subject).to receive(:write).with(JSON.pretty_generate(json))
77
+ }
78
+
79
+ subject.run
80
+ }
81
+ end
82
+ end
51
83
  end
52
84
 
53
85
  describe '#write' do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Contentful::Bootstrap::Generator do
4
- subject { Contentful::Bootstrap::Generator.new('wl1z0pal05vy', '48d7db7d4cd9d09df573c251d456f4acc72141b92f36e57f8684b36cf5cfff6e', false, false) }
4
+ subject { Contentful::Bootstrap::Generator.new('wl1z0pal05vy', '48d7db7d4cd9d09df573c251d456f4acc72141b92f36e57f8684b36cf5cfff6e', false, false, []) }
5
5
 
6
6
  describe 'user agent headers' do
7
7
  it 'client has proper integration data' do
@@ -19,7 +19,7 @@ describe Contentful::Bootstrap::Generator do
19
19
  end
20
20
 
21
21
  context 'with content_types_only set to true' do
22
- subject { Contentful::Bootstrap::Generator.new('wl1z0pal05vy', '48d7db7d4cd9d09df573c251d456f4acc72141b92f36e57f8684b36cf5cfff6e', true, false) }
22
+ subject { Contentful::Bootstrap::Generator.new('wl1z0pal05vy', '48d7db7d4cd9d09df573c251d456f4acc72141b92f36e57f8684b36cf5cfff6e', true, false, []) }
23
23
 
24
24
  it 'can generate a JSON template for a given space with only Content Types' do
25
25
  vcr('generate_json_content_types_only') {
@@ -0,0 +1,154 @@
1
+ {
2
+ "version": 3,
3
+ "contentTypes": [
4
+ {
5
+ "id": "cat",
6
+ "name": "Cat",
7
+ "displayField": "name",
8
+ "fields": [
9
+ {
10
+ "id": "name",
11
+ "name": "Name",
12
+ "type": "Text"
13
+ },
14
+ {
15
+ "id": "likes",
16
+ "name": "Likes",
17
+ "type": "Array",
18
+ "items": {
19
+ "type": "Symbol"
20
+ }
21
+ },
22
+ {
23
+ "id": "color",
24
+ "name": "Color",
25
+ "type": "Symbol"
26
+ },
27
+ {
28
+ "id": "bestFriend",
29
+ "name": "Best Friend",
30
+ "type": "Link",
31
+ "linkType": "Entry"
32
+ },
33
+ {
34
+ "id": "birthday",
35
+ "name": "Birthday",
36
+ "type": "Date"
37
+ },
38
+ {
39
+ "id": "lifes",
40
+ "name": "Lifes left",
41
+ "type": "Integer"
42
+ },
43
+ {
44
+ "id": "lives",
45
+ "name": "Lives left",
46
+ "type": "Integer"
47
+ },
48
+ {
49
+ "id": "image",
50
+ "name": "Image",
51
+ "type": "Link",
52
+ "linkType": "Asset"
53
+ }
54
+ ]
55
+ }
56
+ ],
57
+ "assets": [
58
+ {
59
+ "id": "1x0xpXu4pSGS4OukSyWGUK",
60
+ "title": "Doge",
61
+ "file": {
62
+ "filename": "doge",
63
+ "url": "https://images.contentful.com/cfexampleapi/1x0xpXu4pSGS4OukSyWGUK/cc1239c6385428ef26f4180190532818/doge.jpg"
64
+ }
65
+ },
66
+ {
67
+ "id": "happycat",
68
+ "title": "Happy Cat",
69
+ "file": {
70
+ "filename": "happycatw",
71
+ "url": "https://images.contentful.com/cfexampleapi/3MZPnjZTIskAIIkuuosCss/382a48dfa2cb16c47aa2c72f7b23bf09/happycatw.jpg"
72
+ }
73
+ },
74
+ {
75
+ "id": "jake",
76
+ "title": "Jake",
77
+ "file": {
78
+ "filename": "jake",
79
+ "url": "https://images.contentful.com/cfexampleapi/4hlteQAXS8iS0YCMU6QMWg/2a4d826144f014109364ccf5c891d2dd/jake.png"
80
+ }
81
+ },
82
+ {
83
+ "id": "nyancat",
84
+ "title": "Nyan Cat",
85
+ "file": {
86
+ "filename": "Nyan_cat_250px_frame",
87
+ "url": "https://images.contentful.com/cfexampleapi/4gp6taAwW4CmSgumq2ekUm/9da0cd1936871b8d72343e895a00d611/Nyan_cat_250px_frame.png"
88
+ }
89
+ }
90
+ ],
91
+ "entries": {
92
+ "cat": [
93
+ {
94
+ "sys": {
95
+ "id": "nyancat"
96
+ },
97
+ "fields": {
98
+ "name": "Nyan Cat",
99
+ "likes": [
100
+ "rainbows",
101
+ "fish"
102
+ ],
103
+ "color": "rainbow",
104
+ "bestFriend": {
105
+ "linkType": "Entry",
106
+ "id": "happycat"
107
+ },
108
+ "birthday": "2011-04-04T22:00:00+00:00",
109
+ "lives": 1337,
110
+ "image": {
111
+ "linkType": "Asset",
112
+ "id": "nyancat"
113
+ }
114
+ }
115
+ },
116
+ {
117
+ "sys": {
118
+ "id": "happycat"
119
+ },
120
+ "fields": {
121
+ "name": "Happy Cat",
122
+ "likes": [
123
+ "cheezburger"
124
+ ],
125
+ "color": "gray",
126
+ "bestFriend": {
127
+ "linkType": "Entry",
128
+ "id": "nyancat"
129
+ },
130
+ "birthday": "2003-10-28T23:00:00+00:00",
131
+ "lives": 1,
132
+ "image": {
133
+ "linkType": "Asset",
134
+ "id": "happycat"
135
+ }
136
+ }
137
+ },
138
+ {
139
+ "sys": {
140
+ "id": "garfield"
141
+ },
142
+ "fields": {
143
+ "name": "Garfield",
144
+ "likes": [
145
+ "lasagna"
146
+ ],
147
+ "color": "orange",
148
+ "birthday": "1979-06-18T23:00:00+00:00",
149
+ "lives": 9
150
+ }
151
+ }
152
+ ]
153
+ }
154
+ }
@@ -0,0 +1,202 @@
1
+ {
2
+ "version": 3,
3
+ "contentTypes": [
4
+ {
5
+ "id": "cat",
6
+ "name": "Cat",
7
+ "displayField": "name",
8
+ "fields": [
9
+ {
10
+ "id": "name",
11
+ "name": "Name",
12
+ "type": "Text"
13
+ },
14
+ {
15
+ "id": "likes",
16
+ "name": "Likes",
17
+ "type": "Array",
18
+ "items": {
19
+ "type": "Symbol"
20
+ }
21
+ },
22
+ {
23
+ "id": "color",
24
+ "name": "Color",
25
+ "type": "Symbol"
26
+ },
27
+ {
28
+ "id": "bestFriend",
29
+ "name": "Best Friend",
30
+ "type": "Link",
31
+ "linkType": "Entry"
32
+ },
33
+ {
34
+ "id": "birthday",
35
+ "name": "Birthday",
36
+ "type": "Date"
37
+ },
38
+ {
39
+ "id": "lifes",
40
+ "name": "Lifes left",
41
+ "type": "Integer"
42
+ },
43
+ {
44
+ "id": "lives",
45
+ "name": "Lives left",
46
+ "type": "Integer"
47
+ },
48
+ {
49
+ "id": "image",
50
+ "name": "Image",
51
+ "type": "Link",
52
+ "linkType": "Asset"
53
+ }
54
+ ]
55
+ },
56
+ {
57
+ "id": "human",
58
+ "name": "Human",
59
+ "displayField": "name",
60
+ "fields": [
61
+ {
62
+ "id": "name",
63
+ "name": "Name",
64
+ "type": "Text"
65
+ },
66
+ {
67
+ "id": "description",
68
+ "name": "Description",
69
+ "type": "Text"
70
+ },
71
+ {
72
+ "id": "likes",
73
+ "name": "Likes",
74
+ "type": "Array",
75
+ "items": {
76
+ "type": "Symbol"
77
+ }
78
+ },
79
+ {
80
+ "id": "image",
81
+ "name": "Image",
82
+ "type": "Array",
83
+ "items": {
84
+ "type": "Link",
85
+ "linkType": "Asset"
86
+ }
87
+ }
88
+ ]
89
+ }
90
+ ],
91
+ "assets": [
92
+ {
93
+ "id": "1x0xpXu4pSGS4OukSyWGUK",
94
+ "title": "Doge",
95
+ "file": {
96
+ "filename": "doge",
97
+ "url": "https://images.contentful.com/cfexampleapi/1x0xpXu4pSGS4OukSyWGUK/cc1239c6385428ef26f4180190532818/doge.jpg"
98
+ }
99
+ },
100
+ {
101
+ "id": "happycat",
102
+ "title": "Happy Cat",
103
+ "file": {
104
+ "filename": "happycatw",
105
+ "url": "https://images.contentful.com/cfexampleapi/3MZPnjZTIskAIIkuuosCss/382a48dfa2cb16c47aa2c72f7b23bf09/happycatw.jpg"
106
+ }
107
+ },
108
+ {
109
+ "id": "jake",
110
+ "title": "Jake",
111
+ "file": {
112
+ "filename": "jake",
113
+ "url": "https://images.contentful.com/cfexampleapi/4hlteQAXS8iS0YCMU6QMWg/2a4d826144f014109364ccf5c891d2dd/jake.png"
114
+ }
115
+ },
116
+ {
117
+ "id": "nyancat",
118
+ "title": "Nyan Cat",
119
+ "file": {
120
+ "filename": "Nyan_cat_250px_frame",
121
+ "url": "https://images.contentful.com/cfexampleapi/4gp6taAwW4CmSgumq2ekUm/9da0cd1936871b8d72343e895a00d611/Nyan_cat_250px_frame.png"
122
+ }
123
+ }
124
+ ],
125
+ "entries": {
126
+ "cat": [
127
+ {
128
+ "sys": {
129
+ "id": "nyancat"
130
+ },
131
+ "fields": {
132
+ "name": "Nyan Cat",
133
+ "likes": [
134
+ "rainbows",
135
+ "fish"
136
+ ],
137
+ "color": "rainbow",
138
+ "bestFriend": {
139
+ "linkType": "Entry",
140
+ "id": "happycat"
141
+ },
142
+ "birthday": "2011-04-04T22:00:00+00:00",
143
+ "lives": 1337,
144
+ "image": {
145
+ "linkType": "Asset",
146
+ "id": "nyancat"
147
+ }
148
+ }
149
+ },
150
+ {
151
+ "sys": {
152
+ "id": "happycat"
153
+ },
154
+ "fields": {
155
+ "name": "Happy Cat",
156
+ "likes": [
157
+ "cheezburger"
158
+ ],
159
+ "color": "gray",
160
+ "bestFriend": {
161
+ "linkType": "Entry",
162
+ "id": "nyancat"
163
+ },
164
+ "birthday": "2003-10-28T23:00:00+00:00",
165
+ "lives": 1,
166
+ "image": {
167
+ "linkType": "Asset",
168
+ "id": "happycat"
169
+ }
170
+ }
171
+ },
172
+ {
173
+ "sys": {
174
+ "id": "garfield"
175
+ },
176
+ "fields": {
177
+ "name": "Garfield",
178
+ "likes": [
179
+ "lasagna"
180
+ ],
181
+ "color": "orange",
182
+ "birthday": "1979-06-18T23:00:00+00:00",
183
+ "lives": 9
184
+ }
185
+ }
186
+ ],
187
+ "human": [
188
+ {
189
+ "sys": {
190
+ "id": "finn"
191
+ },
192
+ "fields": {
193
+ "name": "Finn",
194
+ "description": "Fearless adventurer! Defender of pancakes.",
195
+ "likes": [
196
+ "adventure"
197
+ ]
198
+ }
199
+ }
200
+ ]
201
+ }
202
+ }