class Contentful::Bootstrap::Commands::GenerateJson

Attributes

access_token[R]
content_type_ids[R]
content_types_only[R]
environment[R]
filename[R]
space_id[R]
use_preview[R]

Public Class Methods

new( space_id, access_token, environment = 'master', filename = nil, content_types_only = false, quiet = false, use_preview = false, content_type_ids = [] ) click to toggle source
# 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

Public Instance Methods

run() click to toggle source
# 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) click to toggle source
# 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

Protected Instance Methods

output(text = nil) click to toggle source
# File lib/contentful/bootstrap/commands/generate_json.rb, line 62
def output(text = nil)
  Support.output(text, @quiet)
end