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, filename = nil, content_types_only = false) ⇒ GenerateJson

Returns a new instance of GenerateJson.



9
10
11
12
13
14
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 9

def initialize(space_id, access_token, filename = nil, content_types_only = false)
  @space_id = space_id
  @access_token = access_token
  @filename = filename
  @content_types_only = content_types_only
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_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

#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

Instance Method Details

#runObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 16

def run
  if access_token.nil?
    puts 'Access Token not specified'
    puts 'Exiting!'
    exit
  end

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

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

  puts
  write(json)
end

#write(json) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 31

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