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
#result
Instance Method Summary
collapse
Methods inherited from BaseParser
#initialize, #steps
call, #call, #errors, #failure?, #finished?, #steps, #success?
Instance Method Details
#build_result ⇒ Object
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(['doPrintingStateResponse'])
opt_hash = options_hash
@result[:printings] = { options: opt_hash }.merge(content_hash(opt_hash[:template_id]))
end
|
#content_hash(template_id) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/czech_post_b2b_client/response_parsers/get_parcels_printing_parser.rb', line 27
def content_hash(template_id)
if zpl_template?(template_id)
{ zpl_content: response_content.force_encoding('utf-8') }
else
{ pdf_content: response_content }
end
end
|
#options_hash ⇒ Object
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 = ['doPrintingHeader']
{
customer_id: options_response['customerID'],
contract_number: options_response['contractNumber'],
template_id: options_response['idForm'].to_i,
margin_in_mm: { top: options_response['shiftVertical'].to_i,
left: options_response['shiftHorizontal'].to_i },
position_order: options_response['position'].to_i
}
end
|
50
51
52
|
# File 'lib/czech_post_b2b_client/response_parsers/get_parcels_printing_parser.rb', line 50
def
response_root_node['doPrintingHeaderResult']
end
|
#response_content ⇒ Object
39
40
41
42
43
44
|
# File 'lib/czech_post_b2b_client/response_parsers/get_parcels_printing_parser.rb', line 39
def response_content
content_encoded = response_root_node.dig('doPrintingDataResult', 'file')
return nil if content_encoded.nil?
::Base64.decode64(content_encoded)
end
|
#response_root_node_name ⇒ Object
46
47
48
|
# File 'lib/czech_post_b2b_client/response_parsers/get_parcels_printing_parser.rb', line 46
def response_root_node_name
'getParcelsPrintingResponse'
end
|
#zpl_template?(template_id) ⇒ Boolean
35
36
37
|
# File 'lib/czech_post_b2b_client/response_parsers/get_parcels_printing_parser.rb', line 35
def zpl_template?(template_id)
CzechPostB2bClient::PrintingTemplates.find(template_id).content_type == :zpl
end
|