Class: Oca::Epak::Client

Inherits:
BaseClient show all
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

#client, #password, #username

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
# File 'lib/oca-epak/epak/client.rb', line 9

def initialize(username, password)
  super
  @opts = { wsdl: WSDL_URL }.merge(Oca::Logger.options)
  @client = Savon.client(@opts)
end

Instance Method Details

#check_credentialsBoolean

Checks if the user has input valid credentials

Returns:

  • (Boolean)

    Whether the credentials entered are valid or not



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.

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :pickup_data (Oca::Epak::PickupData)

    Pickup Data object

  • :confirm_pickup (Boolean)

    Confirm Pickup? Defaults to false

  • :days_to_pickup (Integer)

    Days OCA should wait before pickup, default: 1

  • :pickup_range (Integer)

    Range to be used when picking it up, default: 1

Returns:

  • (Hash, nil)

See Also:



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

  message = { 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: message)
  parse_result(response, :ingreso_or)
end

#get_operation_codesArray?

Returns all operation codes

Returns:

  • (Array, nil)

    Returns all operation codes available for the user



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

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :total_weight (String)

    Total Weight e.g: 20

  • :total_volume (String)

    Total Volume e.g: 0.0015 (0.1mts * 0.15mts * 0.1mts)

  • :origin_zip_code (String)

    Origin ZIP Code

  • :destination_zip_code (String)

    Destination ZIP Code

  • :declared_value (String)

    Declared Value

  • :package_quantity (String)

    Quantity of Packages

  • :cuit (String)

    Client’s CUIT e.g: 30-99999999-7

  • :operation_code (String)

    Operation Type

Returns:

  • (Hash, nil)

    Contains Total Price, Delivery Estimate



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
  message = { "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: 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.

Parameters:

  • Client's (String)

    CUIT

  • "From (String)

    date“ in DD-MM-YYYY format

  • "To (String)

    date“ in DD-MM-YYYY format

Returns:

  • (Array, nil)

    Contains an array of hashes with NroProducto and NumeroEnvio



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

#provincesArray?

Returns all provinces in Argentina

Returns:

  • (Array, nil)

    Provinces in Argentina with their ID and name as a Hash



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_centersArray?

Returns all existing Taxation Centers

Returns:

  • (Array, nil)

    Information for all the Oca 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_servicesArray?

Returns all existing Taxation Centers with services

Returns:

  • (Array, nil)

    Information for all the Oca 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

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :cuit (String)

    Client’s CUIT e.g: 30-99999999-7

  • :pieza (String)

    Tracking number

Returns:

  • (Hash, nil)

    Contains the history of object’s movement.



136
137
138
139
140
141
142
143
144
# File 'lib/oca-epak/epak/client.rb', line 136

def tracking_object(opts = {})
  message = {
    "Cuit" => opts[:cuit],
    "Pieza" => opts[:pieza]
  }

  response = client.call(:tracking_pieza, message: message)
  parse_result(response, :tracking_pieza)
end