Class: Oca::Epak::Client
- Inherits:
-
BaseClient
- Object
- BaseClient
- Oca::Epak::Client
- Defined in:
- lib/oca-epak/epak/client.rb
Constant Summary collapse
- ONE_STRING =
"1".freeze
- USER_STRING =
"usr".freeze
- PASSWORD_STRING =
"psw".freeze
- WSDL_URL =
"#{BASE_WSDL_URL}/epak_tracking/Oep_TrackEPak.asmx?wsdl".freeze
- CUIT_PATTERN =
/[0-9]{2}-[0-9]{8}-[0-9]/
Constants inherited from BaseClient
BaseClient::BASE_WSDL_URL, BaseClient::FALSE_STRING
Instance Attribute Summary
Attributes inherited from BaseClient
Instance Method Summary collapse
-
#check_credentials ⇒ Boolean
Checks if the user has input valid credentials.
-
#create_pickup_order(opts = {}) ⇒ Hash?
Creates a Pickup Order, which lets OCA know you want to make a delivery.
-
#get_operation_codes ⇒ Array?
Returns all operation codes.
-
#get_shipping_rate(opts = {}) ⇒ Hash?
Get rates and delivery estimate for a shipment.
-
#initialize(username, password) ⇒ Client
constructor
A new instance of Client.
-
#list_shipments(cuit, from_date, to_date) ⇒ Array?
Given a client’s CUIT with a range of dates, returns a list with all shipments made within the given period.
-
#provinces ⇒ Array?
Returns all provinces in Argentina.
-
#taxation_centers ⇒ Array?
Returns all existing Taxation Centers.
-
#taxation_centers_with_services ⇒ Array?
Returns all existing Taxation Centers with services.
-
#taxation_centers_with_services_by_zipcode(opts = {}) ⇒ Array?
Returns all existing Taxation Centers with services.
-
#tracking_object(opts = {}) ⇒ Hash?
Get the tracking history of an object.
-
#tracking_object_with_ids(opts = {}) ⇒ Hash?
Get the tracking history of an object with the ids.
Constructor Details
Instance Method Details
#check_credentials ⇒ Boolean
Checks if the user has input valid credentials
19 20 21 22 23 24 |
# File 'lib/oca-epak/epak/client.rb', line 19 def check_credentials method = :get_epack_user opts = { USER_STRING => username, PASSWORD_STRING => password } response = client.call(method, message: opts) parse_results_table(response, method).first[:existe] == ONE_STRING end |
#create_pickup_order(opts = {}) ⇒ Hash?
Creates a Pickup Order, which lets OCA know you want to make a delivery.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/oca-epak/epak/client.rb', line 36 def create_pickup_order(opts = {}) confirm_pickup = opts.fetch(:confirm_pickup, FALSE_STRING) days_to_pickup = opts.fetch(:days_to_pickup, ONE_STRING) pickup_range = opts.fetch(:pickup_range, ONE_STRING) rendered_xml = opts[:pickup_data].to_xml = { USER_STRING => username, PASSWORD_STRING => password, "xml_Datos" => rendered_xml, "ConfirmarRetiro" => confirm_pickup.to_s, "DiasHastaRetiro" => days_to_pickup, "idFranjaHoraria" => pickup_range } response = client.call(:ingreso_or, message: ) parse_result(response, :ingreso_or) end |
#get_operation_codes ⇒ Array?
Returns all operation codes
101 102 103 104 105 106 |
# File 'lib/oca-epak/epak/client.rb', line 101 def get_operation_codes method = :get_operativas_by_usuario opts = { USER_STRING => username, PASSWORD_STRING => password } response = client.call(method, message: opts) parse_results_table(response, method) end |
#get_shipping_rate(opts = {}) ⇒ Hash?
Get rates and delivery estimate for a shipment
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/oca-epak/epak/client.rb', line 64 def get_shipping_rate(opts = {}) cuit_number = normalize_cuit(opts[:cuit]) method = :tarifar_envio_corporativo = { "PesoTotal" => opts[:total_weight], "VolumenTotal" => opts[:total_volume], "CodigoPostalOrigen" => opts[:origin_zip_code], "CodigoPostalDestino" => opts[:destination_zip_code], "ValorDeclarado" => opts[:declared_value], "CantidadPaquetes" => opts[:package_quantity], "Cuit" => cuit_number, "Operativa" => opts[:operation_code] } response = client.call(method, message: ) parse_results_table(response, method).first end |
#list_shipments(cuit, from_date, to_date) ⇒ Array?
Given a client’s CUIT with a range of dates, returns a list with all shipments made within the given period.
115 116 117 118 119 120 121 122 123 |
# File 'lib/oca-epak/epak/client.rb', line 115 def list_shipments(cuit, from_date, to_date) cuit_number = normalize_cuit(cuit) method = :list_envios opts = { "CUIT" => cuit_number, "FechaDesde" => from_date, "FechaHasta" => to_date } response = client.call(method, message: opts) parse_results_table(response, method) end |
#provinces ⇒ Array?
Returns all provinces in Argentina
128 129 130 131 132 133 |
# File 'lib/oca-epak/epak/client.rb', line 128 def provinces response = client.call(:get_provincias) if body = response.body[:get_provincias_response] body[:get_provincias_result][:provincias][:provincia] end end |
#taxation_centers ⇒ Array?
Returns all existing Taxation Centers
83 84 85 86 87 |
# File 'lib/oca-epak/epak/client.rb', line 83 def taxation_centers method = :get_centros_imposicion response = client.call(method) parse_results_table(response, method) end |
#taxation_centers_with_services ⇒ Array?
Returns all existing Taxation Centers with services
92 93 94 95 96 |
# File 'lib/oca-epak/epak/client.rb', line 92 def taxation_centers_with_services method = :get_centros_imposicion_con_servicios response = client.call(method) parse_result(response, method) end |
#taxation_centers_with_services_by_zipcode(opts = {}) ⇒ Array?
Returns all existing Taxation Centers with services
171 172 173 174 175 176 177 178 |
# File 'lib/oca-epak/epak/client.rb', line 171 def taxation_centers_with_services_by_zipcode(opts = {}) = { "CodigoPostal" => opts[:codigo_postal] } method = :get_centros_imposicion_con_servicios_by_cp response = client.call(method, message: ) parse_result(response, method) end |
#tracking_object(opts = {}) ⇒ Hash?
Get the tracking history of an object
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/oca-epak/epak/client.rb', line 141 def tracking_object(opts = {}) = { "Cuit" => normalize_cuit(opts[:cuit]), "Pieza" => opts[:pieza] } response = client.call(:tracking_pieza, message: ) parse_result(response, :tracking_pieza) end |
#tracking_object_with_ids(opts = {}) ⇒ Hash?
Get the tracking history of an object with the ids
157 158 159 160 161 162 163 164 |
# File 'lib/oca-epak/epak/client.rb', line 157 def tracking_object_with_ids(opts = {}) = { "NumeroEnvio" => opts[:pieza] } response = client.call(:tracking_pieza_con_id_estado, message: ) parse_result(response, :tracking_pieza_con_id_estado) end |