Class: DynamicPDFApi::LayoutDataResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/ruby_client/LayoutDataResource.rb

Overview

Represents the Layout data resource used to create the PDF reports.

Instance Attribute Summary collapse

Attributes inherited from Resource

#_file_path, #_mime_type, #data, #resource_name

Instance Method Summary collapse

Methods inherited from Resource

_get_file_data

Constructor Details

#initialize(layout = nil, layout_data_resource_name = nil) ⇒ LayoutDataResource

Initializes a new instance of the LayoutDataResource class using the layout data object and a resource name.

Parameters:

  • layout (Object) (defaults to: nil)

    |[String] Serializable object data to create PDF report or the layout data JSON file path.

  • layout_data_resource_name (String) (defaults to: nil)

    The name for layout data resource.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ruby_client/LayoutDataResource.rb', line 17

def initialize(layout = nil, layout_data_resource_name = nil)
  super()
  @data = if layout.is_a?(String)
            Resource._get_file_data(layout)
          else
            layout.to_json
          end
  @layout_data_resource_name = if layout_data_resource_name.nil?
                                 "#{SecureRandom.uuid}.json"
                               else
                                 layout_data_resource_name
                               end

  @_mime_type = 'application/json'
  @_type = ResourceType::LAYOUT_DATA
  @resource_name = @layout_data_resource_name
end

Instance Attribute Details

#layout_data_resource_nameObject

Gets or sets name of the layout data resource.



42
43
44
# File 'lib/ruby_client/LayoutDataResource.rb', line 42

def layout_data_resource_name
  @layout_data_resource_name
end

Instance Method Details

#_file_extensionObject



35
36
37
# File 'lib/ruby_client/LayoutDataResource.rb', line 35

def _file_extension
  '.json'
end

#to_json(_options = {}) ⇒ Object



44
45
46
# File 'lib/ruby_client/LayoutDataResource.rb', line 44

def to_json(_options = {})
  JSON.pretty_generate({})
end