Skip to content

Commit

Permalink
added ParcelServiceSyncBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
foton committed May 27, 2020
1 parent 5375dce commit e3c9361
Show file tree
Hide file tree
Showing 10 changed files with 656 additions and 12 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
Accessing B2B API of Czech Post for bulk processing of parcels ("B2B - WS PodáníOnline").

There are these supported operations of API:
- *parcelServiceSync* - stores data of one parcel and return package_code and optional PDF adress sheet [HTTP POST - sync response]
Seems to me, that there are is no place extensive Cash On Delivery data, just `amount` and `currency`
- *sendParcels* - stores data of parcels for async processing [HTTP POST - async response]
- *getResultParcels* - return results of such processing [HTTP GET - sync response]
- *getStats* - returns statistics of parcels sent in time period [HTTP GET - sync response]
- *getParcelState* - returns all known states for listed parcels [HTTP GET - sync response]
- *getParcelsPrinting* - returns PDF with address labels/stickers for listed parcels [HTTP GET - sync response]


## Installation
### 1) Registration at Czech Post (CP)
The longterm and hardest part.
Expand Down
2 changes: 1 addition & 1 deletion examples/try_api_calls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def async_import_parcels_data
def sync_import_parcels_data
# post informations about parcels to Czech Post and get the tracking codes
sender_service = CzechPostB2bClient::Services::ParcelsSyncSender.call(sending_data: sending_data,
parcels: parcels)
parcels: parcels)
raise "ParcelImmediateSender failed with errors: #{sender_service.errors}" unless sender_service.success?

update_parcels_data_with(sender_service.result.parcels_hash)
Expand Down
1 change: 1 addition & 0 deletions lib/czech_post_b2b_client/request_builders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
require 'czech_post_b2b_client/request_builders/get_parcel_state_builder'
require 'czech_post_b2b_client/request_builders/get_result_parcels_builder'
require 'czech_post_b2b_client/request_builders/send_parcels_builder'
require 'czech_post_b2b_client/request_builders/parcel_service_sync_builder'

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion test/integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def test_it_have_successfull_workflow

def it_imports_parcels_data
# post informations about parcels to Czech Post
sender_service = CzechPostB2bClient::Services::ParcelsAsyncSender.call(sending_data: sending_data, parcels: parcels)
sender_service = CzechPostB2bClient::Services::ParcelsAsyncSender.call(sending_data: sending_data,
parcels: parcels)

assert sender_service.success?, "ParcelSender failed with errors: #{sender_service.errors}"

Expand Down
329 changes: 329 additions & 0 deletions test/request_builders/parcel_service_sync_builder_test.rb

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions test/request_builders/send_parcels_builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,10 @@ def expected_not_closing_xml
<ns2:returnNumDays>s2</ns2:returnNumDays>
</ns2:doParcelParams>
<ns2:doParcelServices>
<ns2:service>43</ns2:service>
<ns2:service>4</ns2:service>
</ns2:doParcelServices>
<ns2:doParcelServices>
<ns2:service>44</ns2:service>
</ns2:doParcelServices>
<ns2:doParcelServices>
<ns2:service>s3</ns2:service>
<ns2:service>L</ns2:service>
</ns2:doParcelServices>
<ns2:doParcelAddress>
<ns2:recordID>string20</ns2:recordID>
Expand Down
4 changes: 2 additions & 2 deletions test/response_parsers/get_parcel_state_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_it_handle_empty_parcels
assert_equal no_parcels_struct, parser.result
end

# rubocop:disable Metrics/LineLength
# rubocop:disable Layout/LineLength
def expected_ok_struct # rubocop:disable Metrics/MethodLength
{
request: { created_at: Time.parse('2016-03-12T10:00:34.573Z'), contract_id: '25195667001', request_id: '64' },
Expand Down Expand Up @@ -240,7 +240,7 @@ def expected_real_parcels_struct # rubocop:disable Metrics/MethodLength, Metrics
}
}
end
# rubocop:enable Metrics/LineLength
# rubocop:enable Layout/LineLength

def b2b_ok_response
fixture_response_xml('getParcelState_ok.xml')
Expand Down
4 changes: 2 additions & 2 deletions test/services/delivering_inspector_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def expected_parser_parcels_hash # rubocop:disable Metrics/MethodLength
end

def expected_states_array_4075
# rubocop:disable Metrics/LineLength
# rubocop:disable Layout/LineLength

# order is exactly as in XML, there is no ordering key
[
Expand All @@ -109,7 +109,7 @@ def expected_states_array_9139
{ id: '43', date: Date.parse('2015-08-20'), text: 'E-mail odesílateli - dodání zásilky.', post_code: nil, post_name: nil },
{ id: '91', date: Date.parse('2015-08-20'), text: 'Dodání zásilky.', post_code: '25756', post_name: 'Neveklov' }
]
# rubocop:enable Metrics/LineLength
# rubocop:enable Layout/LineLength
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion test/support/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def full_parcel_data
{
params: full_parcel_data_params, # required
cash_on_delivery: { amount: 12_345.678, currency_iso_code: 'CZK' },
services: %w[43 44 s3],
services: %w[4 L],
addressee: full_addressee_data,
document_addressee: full_addressee_data, # 0-X
custom_declaration: full_parcel_data_custom_delaration # 0-1
Expand Down Expand Up @@ -195,6 +195,7 @@ def full_parcel_data_custom_delaration
# "991" -jine;
# "11" - obchodni zbozi
note: 'string30',
importer_reference_number: 'CD12345',
value_currency_iso_code: 'CZK', # REQUIRED, ISO kod meny celni hodnoty
content_descriptions: [ # 1- 20x; popis obsahu zasilky
{
Expand Down

0 comments on commit e3c9361

Please sign in to comment.