Class: DynamicPDFApi::DlexLayout
- Defined in:
- lib/ruby_client/DlexLayout.rb
Instance Attribute Summary collapse
-
#dlex_path ⇒ Object
Gets or sets the DLEX file path present in the resource manager.
-
#resource ⇒ Object
Returns the value of attribute resource.
-
#resources ⇒ Object
Returns the value of attribute resources.
Attributes inherited from Endpoint
#_endpoint_name, #api_key, #base_url
Instance Method Summary collapse
-
#add_additional_resource(resourcePath, resourceName = nil) ⇒ Object
Adds additional resource to the endpoint.
- #add_additional_resource_with_resourcedata(resourceData, additionalResourceType, resourceName) ⇒ Object
-
#initialize(dlex, layout) ⇒ DlexLayout
constructor
Initializes a new instance of the DlexLayout class using the DLEX file path present in the cloud environment and the JSON data for the PDF report.
-
#process ⇒ Object
Process the DLEX and layout data to create PDF report.
Methods inherited from Endpoint
Constructor Details
#initialize(dlex, layout) ⇒ DlexLayout
Initializes a new instance of the DlexLayout class using the DLEX file path present in the cloud environment and the JSON data for the PDF report.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ruby_client/DlexLayout.rb', line 13 def initialize(dlex, layout) @_endpoint_name = 'dlex-layout' @resources= [] super() if(dlex.is_a?(String)) == true && layout.is_a?(Object) @dlex_path = dlex @resource = layout elsif (dlex.is_a?(Object)) == true && layout.is_a?(Object) @resources << dlex @resource = layout end end |
Instance Attribute Details
#dlex_path ⇒ Object
Gets or sets the DLEX file path present in the resource manager.
71 72 73 |
# File 'lib/ruby_client/DlexLayout.rb', line 71 def dlex_path @dlex_path end |
#resource ⇒ Object
Returns the value of attribute resource.
66 67 68 |
# File 'lib/ruby_client/DlexLayout.rb', line 66 def resource @resource end |
#resources ⇒ Object
Returns the value of attribute resources.
64 65 66 |
# File 'lib/ruby_client/DlexLayout.rb', line 64 def resources @resources end |
Instance Method Details
#add_additional_resource(resourcePath, resourceName = nil) ⇒ Object
Adds additional resource to the endpoint.
<param name=“resourcePath”>The resource file path. <param name=“resourceName”>The name of the resource.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ruby_client/DlexLayout.rb', line 31 def add_additional_resource(resourcePath, resourceName = nil) resourceName = File.basename(resourcePath) if !resourceName.nil? additional_resource = AdditionalResource.new(resourcePath, resourceName) if additional_resource.type == ResourceType::LAYOUT_DATA raise 'Layout data resources cannot be added to a DlexLayout object.' elsif additional_resource.type == ResourceType::DLEX raise 'Dlex resources cannot be added to a DlexLayout object.' else @resources << additional_resource end end |
#add_additional_resource_with_resourcedata(resourceData, additionalResourceType, resourceName) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ruby_client/DlexLayout.rb', line 47 def add_additional_resource_with_resourcedata(resourceData, additionalResourceType, resourceName) type = ResourceType::PDF case (additionalResourceType) when AdditionalResourceType::FONT type = ResourceType::FONT when AdditionalResourceType::IMAGE type = ResourceType::IMAGE when AdditionalResourceType::PDF type = ResourceType::PDF else raise 'This type of resource not allowed' end additional_resource = AdditionalResource.new(resourceData, resourceName, type) @resources << additional_resource end |
#process ⇒ Object
Process the DLEX and layout data to create PDF report.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/ruby_client/DlexLayout.rb', line 78 def process header = { 'Authorization': "Bearer #{@api_key}", 'Expect': '100-continue' } uri = URI.parse("#{@base_url}/v1.0/#{@_endpoint_name}") resource_array = [] resource_array << ['LayoutData', @resource.data, { content_type: @resource._mime_type, filename: @resource.layout_data_resource_name }] if !@resource.nil? resource_array << ['DlexPath', @dlex_path, { content_type: 'application/octet-stream', filename: '' }] if !@dlex_path.nil? @resources.each { |field| data = if !field._file_path.nil? File.binread(field._file_path) else field.data end resource_array << ["Resource", data, { content_type: "application/octet-stream", filename: field.resource_name }] } request = Net::HTTP::Post.new(uri.request_uri, header) = { use_ssl: uri.scheme == 'https', verify_mode: OpenSSL::SSL::VERIFY_NONE } request.set_form(resource_array, 'multipart/form-data') response = Net::HTTP.start(uri.hostname, uri.port, ) do |http| http.request(request) end ret_object = PdfResponse.new ret_object.is_successful = false ret_object.status_code = response.code out_data = response.body if !ret_object.nil? && ret_object.status_code == '200' && out_data[0, 4].eql?('%PDF') == true ret_object = PdfResponse.new(out_data) ret_object.is_successful = true else out_data_json = JSON.parse(out_data) ret_object.error_json = out_data ret_object. = if !out_data_json['message'].nil? out_data_json['message'] else "status_code : #{Net::HTTPResponse::CODE_TO_OBJ[ret_object.status_code]}" end ret_object.error_id = out_data_json['id'] end ret_object end |