Class: PostalTransfersPl::Client
- Inherits:
-
Object
- Object
- PostalTransfersPl::Client
- Defined in:
- lib/postal_transfers_pl.rb
Defined Under Namespace
Classes: Configuration
Class Attribute Summary collapse
-
.configuration ⇒ Object
Returns the value of attribute configuration.
-
.error_report ⇒ Object
Returns the value of attribute error_report.
-
.response ⇒ Object
Returns the value of attribute response.
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Class Method Summary collapse
- .configure {|configuration| ... } ⇒ Object
- .confirm_mass_order(id:) ⇒ Object
- .confirm_or_destroy_mass_order(id:) ⇒ Object
- .create_mass_order(service_name:, file_path:, auto_approve: false) ⇒ Object
- .destroy_mass_order(id:) ⇒ Object
- .list_documents(id:) ⇒ Object
- .payment_tracking(id:) ⇒ Object
- .read_document(id:) ⇒ Object
- .track_mass_order(id:) ⇒ Object
- .trigger_payment_tracking(id:) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/postal_transfers_pl.rb', line 43 def initialize raise 'No configuration credentials provided !' if PostalTransfersPl::Client.configuration.blank? @client = Savon.client( wsdl: PostalTransfersPl::Client.configuration.wsdl, ssl_version: PostalTransfersPl::Client.configuration.ssl_version.to_sym, log: true, pretty_print_xml: true, namespace_identifier: PostalTransfersPl::Client.configuration.namespace.to_sym, namespaces: {"xmlns:#{PostalTransfersPl::Client.configuration.namespace}" => PostalTransfersPl::Client.configuration.namespace_uri}, wsse_auth: [PostalTransfersPl::Client.configuration.user, PostalTransfersPl::Client.configuration.password], headers: {'Content-Type' => 'text/xml;charset=utf-8;'} ) end |
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
9 10 11 |
# File 'lib/postal_transfers_pl.rb', line 9 def configuration @configuration end |
.error_report ⇒ Object
Returns the value of attribute error_report.
9 10 11 |
# File 'lib/postal_transfers_pl.rb', line 9 def error_report @error_report end |
.response ⇒ Object
Returns the value of attribute response.
9 10 11 |
# File 'lib/postal_transfers_pl.rb', line 9 def response @response end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
6 7 8 |
# File 'lib/postal_transfers_pl.rb', line 6 def client @client end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
12 13 14 15 |
# File 'lib/postal_transfers_pl.rb', line 12 def self.configure self.configuration ||= Configuration.new yield(configuration) end |
.confirm_mass_order(id:) ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/postal_transfers_pl.rb', line 109 def self.confirm_mass_order(id:) self.new.client.call( PostalTransfersPl::Client.configuration.confirm.to_sym, message: { 'v1:UIP' => id } ) @response = self.track_mass_order(id: id) self.trigger_payment_tracking(id: id) end |
.confirm_or_destroy_mass_order(id:) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/postal_transfers_pl.rb', line 83 def self.confirm_or_destroy_mass_order(id:) @response = self.track_mass_order(id: id) case response.fetch(:stan) when 'OdrzuconyZPowoduBleduWeryfikacji', 'NIEOBSLUGIWANY' self.destroy_mass_order(id: id) when 'UtworzonyCzekaNaWeryfikacjeMKP' sleep 5 self.confirm_or_destroy_mass_order(id: id) when 'ZweryfikowanyOczekujacyNaZatwierdzenie' self.confirm_mass_order(id: id) else @error_report = 'File is invalid!' end error_report.blank? ? response : { error: error_report } end |
.create_mass_order(service_name:, file_path:, auto_approve: false) ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/postal_transfers_pl.rb', line 72 def self.create_mass_order(service_name:, file_path:, auto_approve: false) file_name = File.basename(URI.parse(file_path.path).path) api_file_name = Regexp.new(PostalTransfersPl::Client.configuration.file_name_regexp.to_s).match(file_name).to_s + '.csv' base = Base64.encode64(file_path.read) resp = self.new.client.call( PostalTransfersPl::Client.configuration.create.to_sym, message: { 'v1:RodzajUslugi' => service_name, 'v1:NazwaPliku' => api_file_name, 'v1:ZawartoscPliku' => base, 'v1:ZatwierdzenieAutomatyczne' => auto_approve } ).to_hash.fetch((PostalTransfersPl::Client.configuration.create.to_s + '_response').to_sym) self.confirm_or_destroy_mass_order(id: resp.fetch(:uip)) end |
.destroy_mass_order(id:) ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'lib/postal_transfers_pl.rb', line 99 def self.destroy_mass_order(id:) doc = self.list_documents(id: id)[:opis_dokumentu] doc_id = doc[:identyfikator] @error_report = doc_id.blank? ? nil : Base64.decode64(self.read_document(id: doc_id)) self.new.client.call( PostalTransfersPl::Client.configuration.delete.to_sym, message: { 'v1:UIP' => id } ) end |
.list_documents(id:) ⇒ Object
125 126 127 128 129 130 |
# File 'lib/postal_transfers_pl.rb', line 125 def self.list_documents(id:) self.new.client.call( PostalTransfersPl::Client.configuration.list_documents.to_sym, message: { 'v1:UIP' => id } ).to_hash.fetch((PostalTransfersPl::Client.configuration.list_documents.to_s + '_response').to_sym).fetch(:lista_dokumentow) end |
.payment_tracking(id:) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/postal_transfers_pl.rb', line 64 def self.payment_tracking(id:) self.trigger_payment_tracking(id: id) self.new.client.call( PostalTransfersPl::Client.configuration.payment_tracking.to_sym, message: { 'v1:UIP' => id } ).to_hash.fetch((PostalTransfersPl::Client.configuration.payment_tracking.to_s + '_response').to_sym).fetch(:stan_oplacenia_pakietu) end |
.read_document(id:) ⇒ Object
132 133 134 135 136 137 |
# File 'lib/postal_transfers_pl.rb', line 132 def self.read_document(id:) self.new.client.call( PostalTransfersPl::Client.configuration.read_document.to_sym, message: { 'v1:IdentyfikatorDokumentu' => id } ).to_hash.fetch((PostalTransfersPl::Client.configuration.read_document.to_s + '_response').to_sym).fetch(:zawartosc_dokumentu) end |
.track_mass_order(id:) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/postal_transfers_pl.rb', line 57 def self.track_mass_order(id:) self.new.client.call( PostalTransfersPl::Client.configuration.track.to_sym, message: { 'v1:UIP' => id } ).to_hash.fetch((PostalTransfersPl::Client.configuration.track.to_s + '_response').to_sym).fetch(:pakiet) end |
.trigger_payment_tracking(id:) ⇒ Object
118 119 120 121 122 123 |
# File 'lib/postal_transfers_pl.rb', line 118 def self.trigger_payment_tracking(id:) self.new.client.call( PostalTransfersPl::Client.configuration.payment_tracking_trigger.to_sym, message: { 'v1:UIP' => id } ) end |