Class: Contentful::Bootstrap::Generator

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

Constant Summary collapse

DELIVERY_API_URL =
'cdn.contentful.com'.freeze
PREVIEW_API_URL =
'preview.contentful.com'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(space_id, access_token, environment, content_types_only, use_preview, content_type_ids) ⇒ Generator

Returns a new instance of Generator.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/contentful/bootstrap/generator.rb', line 15

def initialize(space_id, access_token, environment, content_types_only, use_preview, content_type_ids)
  @client = Contentful::Client.new(
    space: space_id,
    access_token: access_token,
    environment: environment,
    application_name: 'bootstrap',
    application_version: ::Contentful::Bootstrap::VERSION,
    api_url: use_preview ? PREVIEW_API_URL : DELIVERY_API_URL
  )
  @content_types_only = content_types_only
  @content_type_ids = content_type_ids
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



13
14
15
# File 'lib/contentful/bootstrap/generator.rb', line 13

def client
  @client
end

#content_type_idsObject (readonly)

Returns the value of attribute content_type_ids.



13
14
15
# File 'lib/contentful/bootstrap/generator.rb', line 13

def content_type_ids
  @content_type_ids
end

#content_types_onlyObject (readonly)

Returns the value of attribute content_types_only.



13
14
15
# File 'lib/contentful/bootstrap/generator.rb', line 13

def content_types_only
  @content_types_only
end

Instance Method Details

#generate_jsonObject



28
29
30
31
32
33
34
35
# File 'lib/contentful/bootstrap/generator.rb', line 28

def generate_json
  template = {}
  template['version'] = Contentful::Bootstrap.major_version
  template['contentTypes'] = content_types
  template['assets'] = assets
  template['entries'] = entries
  JSON.pretty_generate(template)
end