Class: Contentful::Bootstrap::Commands::GenerateJson

Inherits:
Object
  • Object
show all
Defined in:
lib/contentful/bootstrap/commands/generate_json.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(space_id, access_token, environment = 'master', filename = nil, content_types_only = false, quiet = false, use_preview = false, content_type_ids = []) ⇒ GenerateJson

Returns a new instance of GenerateJson.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 9

def initialize(
    space_id,
    access_token,
    environment = 'master',
    filename = nil,
    content_types_only = false,
    quiet = false,
    use_preview = false,
    content_type_ids = []
)
  @space_id = space_id
  @access_token = access_token
  @environment = environment
  @filename = filename
  @content_types_only = content_types_only
  @quiet = quiet
  @use_preview = use_preview
  @content_type_ids = content_type_ids
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



8
9
10
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 8

def access_token
  @access_token
end

#content_type_idsObject (readonly)

Returns the value of attribute content_type_ids.



8
9
10
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 8

def content_type_ids
  @content_type_ids
end

#content_types_onlyObject (readonly)

Returns the value of attribute content_types_only.



8
9
10
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 8

def content_types_only
  @content_types_only
end

#environmentObject (readonly)

Returns the value of attribute environment.



8
9
10
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 8

def environment
  @environment
end

#filenameObject (readonly)

Returns the value of attribute filename.



8
9
10
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 8

def filename
  @filename
end

#space_idObject (readonly)

Returns the value of attribute space_id.



8
9
10
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 8

def space_id
  @space_id
end

#use_previewObject (readonly)

Returns the value of attribute use_preview.



8
9
10
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 8

def use_preview
  @use_preview
end

Instance Method Details

#runObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 29

def run
  if access_token.nil?
    output 'Access Token not specified'
    output 'Exiting!'
    exit(1)
  end

  output "Generating JSON Template for Space: '#{space_id}'"
  output

  json = Contentful::Bootstrap::Generator.new(
    space_id,
    access_token,
    environment,
    content_types_only,
    use_preview,
    content_type_ids
  ).generate_json

  write(json)
end

#write(json) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 51

def write(json)
  if filename.nil?
    output "#{json}\n"
  else
    output "Saving JSON template to '#{filename}'"
    ::File.write(filename, json)
  end
end