Class: CzechPostB2bClient::ResponseParsers::GetParcelsPrintingParser

Inherits:
BaseParser show all
Defined in:
lib/czech_post_b2b_client/response_parsers/get_parcels_printing_parser.rb

Instance Attribute Summary

Attributes inherited from SteppedService::Base

#result

Instance Method Summary collapse

Methods inherited from BaseParser

#initialize, #steps

Methods inherited from SteppedService::Base

call, #call, #errors, #failure?, #finished?, #steps, #success?

Constructor Details

This class inherits a constructor from CzechPostB2bClient::ResponseParsers::BaseParser

Instance Method Details

#build_resultObject



8
9
10
11
12
13
# File 'lib/czech_post_b2b_client/response_parsers/get_parcels_printing_parser.rb', line 8

def build_result
  super
  @result[:response][:state] = state_hash_from(printing_response_header_result.dig('doPrintingStateResponse'))
  @result[:printings] = { options: options_hash,
                          pdf_content: pdf_content }
end

#options_hashObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/czech_post_b2b_client/response_parsers/get_parcels_printing_parser.rb', line 15

def options_hash
  options_response = printing_response_header_result.dig('doPrintingHeader')
  {
    customer_id: options_response.dig('customerID'),
    contract_number: options_response.dig('contractNumber'),
    template_id: options_response.dig('idForm').to_i,
    margin_in_mm: { top: options_response.dig('shiftVertical').to_i,
                    left: options_response.dig('shiftHorizontal').to_i },
    position_order: options_response.dig('position').to_i
  }
end

#pdf_contentObject



27
28
29
30
31
32
# File 'lib/czech_post_b2b_client/response_parsers/get_parcels_printing_parser.rb', line 27

def pdf_content
  pdf_content_encoded = response_root_node.dig('doPrintingDataResult', 'file')
  return nil if pdf_content_encoded.nil?

  ::Base64.decode64(pdf_content_encoded)
end

#printing_response_header_resultObject



38
39
40
# File 'lib/czech_post_b2b_client/response_parsers/get_parcels_printing_parser.rb', line 38

def printing_response_header_result
  response_root_node.dig('doPrintingHeaderResult')
end

#response_root_node_nameObject



34
35
36
# File 'lib/czech_post_b2b_client/response_parsers/get_parcels_printing_parser.rb', line 34

def response_root_node_name
  'getParcelsPrintingResponse'
end