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
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.
-
#tracking_object(opts = {}) ⇒ Hash?
Get the tracking history of an object.
Constructor Details
Instance Method Details
#check_credentials ⇒ Boolean
Checks if the user has input valid credentials
18 19 20 21 22 23 |
# File 'lib/oca-epak/epak/client.rb', line 18 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.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/oca-epak/epak/client.rb', line 35 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
98 99 100 101 102 103 |
# File 'lib/oca-epak/epak/client.rb', line 98 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
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/oca-epak/epak/client.rb', line 63 def get_shipping_rate(opts = {}) 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" => opts[:cuit], "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.
112 113 114 115 116 117 118 |
# File 'lib/oca-epak/epak/client.rb', line 112 def list_shipments(cuit, from_date, to_date) method = :list_envios opts = { "CUIT" => cuit, "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
123 124 125 126 127 128 |
# File 'lib/oca-epak/epak/client.rb', line 123 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
80 81 82 83 84 |
# File 'lib/oca-epak/epak/client.rb', line 80 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
89 90 91 92 93 |
# File 'lib/oca-epak/epak/client.rb', line 89 def taxation_centers_with_services method = :get_centros_imposicion_con_servicios response = client.call(method) parse_result(response, method) end |
#tracking_object(opts = {}) ⇒ Hash?
Get the tracking history of an object
136 137 138 139 140 141 142 143 144 |
# File 'lib/oca-epak/epak/client.rb', line 136 def tracking_object(opts = {}) = { "Cuit" => opts[:cuit], "Pieza" => opts[:pieza] } response = client.call(:tracking_pieza, message: ) parse_result(response, :tracking_pieza) end |