Skip to content

Commit

Permalink
v1.2.2 improved print templates, forcing SSL ciphers
Browse files Browse the repository at this point in the history
  • Loading branch information
foton committed Aug 19, 2020
1 parent 270b8fa commit 6e991c1
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 52 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All changes to the gem are documented here.

## [1.2.2] - 2020-08-19

- Printing templates now include @page_dimensions
- Forced secure SSL ciphers for requests
- `examples/try_api_call.rb` refactored to be more versatile (download XSDs [:do not work], pritn_selected_combinations)

## [1.2.0] - 2020-06-07

- **Breaking** Introducing new Printing templates, improved some template names and scopes
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
czech_post_b2b_client (1.2.0)
czech_post_b2b_client (1.2.2)
ox (~> 2.11)

GEM
Expand Down
73 changes: 58 additions & 15 deletions examples/try_api_calls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
class TryApiCalls # rubocop:disable Metrics/ClassLength
attr_accessor :configuration, :processing_end_time_utc, :transaction_id, :parcels

def run
def initialize
setup_configuration(config_hash)
end

@configuration = CzechPostB2bClient.configuration
def run
@processing_end_time_utc = nil
@transaction_id = nil
import_parcels = :sync # :no, :sync, :async
import_parcels = :sync # options: :no, :sync, :async

case import_parcels
when :async
Expand All @@ -43,8 +44,22 @@ def run
end

def download_xsds
setup_configuration(config_hash)
CzechPostB2bClient::Services::XsdsDownloader.call
puts('This do not work, xsds are not public or what')
return

CzechPostB2bClient::Services::XsdsDownloader.call # rubocop:disable Lint/UnreachableCode
end

def print_selected_combinations
[
['RR950397329CZ', 74],
['CS229935172CZ', 74],
['CS229890414CZ', 72],
['CS229935209CZ', 41],
['CV200650205CZ', 20],
['RR0305100012L', 58],
['RR0305100026L', 61]
].each { |p_code, t_id| print_template_for_package(t_id, p_code) }
end

private
Expand All @@ -64,7 +79,9 @@ def config_hash
def existing_parcel_codes
# If Import of parcels do not work for You yet,
# You can insert parcels in Web PodaniOnline and then use this hack to check some services
%w[BA0305100278L BA0305100264L BA0305100255L]

%w[BA0305100216L RR0305100026L RR0305100012L BB0305100012L
BA0305100114L CV200650205CZ CS229935209CZ RR950397329CZ CS229890414CZ CS229935172CZ CS229935169CZ]
end

def sending_data
Expand Down Expand Up @@ -148,6 +165,7 @@ def setup_configuration(config_hash = {})
config.send("#{k}=", v)
end
end
@configuration = CzechPostB2bClient.configuration
end

def async_import_parcels_data
Expand Down Expand Up @@ -210,10 +228,23 @@ def print_address_sheets(options, raise_on_failure = true)
end

def print_all_template_sheets_for_parcel_codes
CzechPostB2bClient::PrintingTemplates.all_classes.each do |t_klass|
puts("printing #{t_klass}")
print_address_sheets(print_options.merge(template_id: t_klass.id), false)
sleep(1)
parcel_codes.each do |parcel_code|
CzechPostB2bClient::PrintingTemplates.all_classes.each do |t_klass|
print_template_for_package(t_klass.id, parcel_code)
sleep 1
end
end
end

def print_template_for_package(t_klass_id, parcel_code)
options = print_options.merge(template_id: t_klass_id, parcel_code: parcel_code)
puts "AddressSheetGenerator [#{parcel_code} , #{t_klass_id}] : #{options}"
pdf_service = CzechPostB2bClient::Services::AddressSheetsGenerator.call(parcel_codes: [parcel_code],
options: options)
if pdf_service.failure?
save_as_txt(pdf_service.errors.to_s, options)
else
save_as_pdf(pdf_service.result.pdf_content, options)
end
end

Expand All @@ -240,13 +271,24 @@ def find_out_statistics
CzechPostB2bClient.logger.debug("[TimePeriodStatisticator] => #{statisticator.result}")
end

def save_as_pdf(pdf_content, options)
def_str = "-template_id_#{options[:template_id]}-"
def filename(options)
def_str = options[:parcel_code] || parcel_codes.collect { |pc| pc[0..1] }.join('_')
def_str += "-template_id_#{options[:template_id]}-"
def_str += "top_#{options[:margin_in_mm][:top]}-"
def_str += "left_#{options[:margin_in_mm][:left]}"
puts('saving:' + def_str)
prefixes = parcel_codes.collect { |pc| pc[0..1] }
File.write("#{prefixes.join('_')}#{def_str}.pdf", pdf_content)
def_str
end

def save_as_txt(content, options)
f_name = filename(options) + '_no_print.txt'
puts('saving:' + f_name)
File.write(f_name, content)
end

def save_as_pdf(pdf_content, options)
f_name = filename(options) + '.pdf'
puts('saving:' + f_name)
File.write(f_name, pdf_content)
end

def update_parcels_data_with(updated_parcels_hash)
Expand Down Expand Up @@ -351,3 +393,4 @@ def short_addressee_data_uk

TryApiCalls.new.run
# TryApiCalls.new.download_xsds
# TryApiCalls.new.print_selected_combinations
3 changes: 2 additions & 1 deletion lib/czech_post_b2b_client/post_services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,8 @@ class DiscountForOnlinePosting < Base

# has to be at the end, to load all subcasses before
def self.all_classes
ObjectSpace.each_object(CzechPostB2bClient::PostServices::Base.singleton_class)
base_class = CzechPostB2bClient::PostServices::Base
ObjectSpace.each_object(base_class.singleton_class).reject { |c| c == base_class }
end
end
end
Expand Down
Loading

0 comments on commit 6e991c1

Please sign in to comment.