20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/contentful/bootstrap/commands.rb', line 20
def create_space(space_name, options = {})
template_name = options.fetch(:template, nil)
json_template = options.fetch(:json_template, nil)
trigger_oauth = options.fetch(:trigger_oauth, true)
get_configuration if trigger_oauth
management_client_init
puts "Creating Space '#{space_name}'"
space = nil
begin
space = Contentful::Management::Space.create(name: space_name)
rescue Contentful::Management::NotFound
puts "Your account has multiple organizations:"
puts get_organizations.join("\n")
print "Please insert the Organization ID you'd want to create the spaces for: "
organization_id = gets.chomp
space = Contentful::Management::Space.create(name: space_name, organization_id: organization_id)
end
puts "Space '#{space_name}' created!"
puts
unless template_name.nil?
if templates.has_key? template_name.to_sym
puts "Creating Template '#{template_name}'"
templates[template_name.to_sym].new(space).run
puts "Template '#{template_name}' created!"
else
puts "Template '#{template_name}' not found. Valid templates are '#{templates.keys.map(&:to_s).join('\', \'')}'"
end
puts
end
unless json_template.nil?
if File.exist?(json_template)
puts "Creating JSON Template '#{json_template}'"
Templates::JsonTemplate.new(space, json_template).run
puts "JSON Template '#{json_template}' created!"
else
puts "JSON Template '#{json_template}' does not exist. Please check that you specified the correct file name."
end
puts
end
token = generate_token(space, trigger_oauth: false)
puts
puts "Space ID: '#{space.id}'"
puts "Access Token: '#{token}'"
puts
puts "You can now insert those values into your configuration blocks"
puts "Manage your content at https://app.contentful.com/spaces/#{space.id}"
end
|