Class: CzechPostB2bClient::ResponseParsers::GetResultParcelsParser
- Inherits:
-
BaseParser
show all
- Defined in:
- lib/czech_post_b2b_client/response_parsers/get_result_parcels_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
6
7
8
9
10
|
# File 'lib/czech_post_b2b_client/response_parsers/get_result_parcels_parser.rb', line 6
def build_result
super
@result[:response][:state] = state_hash_from(response_state_response)
@result[:parcels] = parcels_data_hash
end
|
#parcel_data_from(rp_hash) ⇒ Object
35
36
37
38
|
# File 'lib/czech_post_b2b_client/response_parsers/get_result_parcels_parser.rb', line 35
def parcel_data_from(rp_hash)
{ parcel_code: rp_hash['parcelCode'],
states: [state_hash_from(rp_hash.dig('doParcelStateResponse'))] }
end
|
#parcel_parcel_id_from(rp_hash) ⇒ Object
31
32
33
|
# File 'lib/czech_post_b2b_client/response_parsers/get_result_parcels_parser.rb', line 31
def parcel_parcel_id_from(rp_hash)
rp_hash['recordNumber'].to_s
end
|
#parcels_data_hash ⇒ Object
12
13
14
15
16
17
|
# File 'lib/czech_post_b2b_client/response_parsers/get_result_parcels_parser.rb', line 12
def parcels_data_hash
response_parcel_hashes.each_with_object({}) do |rp_hash, result|
parcel_id = parcel_parcel_id_from(rp_hash)
result[parcel_id] = updated_result_value_for(result[parcel_id], rp_hash)
end
end
|
#response_parcel_hashes ⇒ Object
27
28
29
|
# File 'lib/czech_post_b2b_client/response_parsers/get_result_parcels_parser.rb', line 27
def response_parcel_hashes
[response_root_node.dig('doParcelParamResult')].flatten.compact end
|
#response_root_node_name ⇒ Object
19
20
21
|
# File 'lib/czech_post_b2b_client/response_parsers/get_result_parcels_parser.rb', line 19
def response_root_node_name
'getResultParcelsResponse'
end
|
#response_state_response ⇒ Object
23
24
25
|
# File 'lib/czech_post_b2b_client/response_parsers/get_result_parcels_parser.rb', line 23
def response_state_response
response_root_node.dig('doParcelHeaderResult', 'doParcelStateResponse')
end
|
#updated_result_value_for(value, parcel_params_result_hash) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/czech_post_b2b_client/response_parsers/get_result_parcels_parser.rb', line 40
def updated_result_value_for(value, parcel_params_result_hash)
pd_hash=parcel_data_from(parcel_params_result_hash)
return pd_hash if value.nil?
old_p_code = value[:parcel_code]
new_p_code = pd_hash[:parcel_code]
value[:states] = (value[:states] + pd_hash[:states]).sort { |a, b| a[:code] <=> b[:code] }
raise "Two different parcel_codes [#{old_p_code}, #{new_p_code}] for parcel_id:'#{parcel_id}'" if old_p_code != new_p_code
value
end
|