Class: Oca::Epak::Client

Inherits:
BaseClient show all
Defined in:
lib/oca-epak/epak/client.rb

Constant Summary

Constants inherited from BaseClient

BaseClient::BASE_WSDL_URL

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.


4
5
6
7
8
# File 'lib/oca-epak/epak/client.rb', line 4

def initialize(username, password)
  super
  wsdl_url = "#{BASE_WSDL_URL}/epak_tracking/Oep_TrackEPak.asmx?wsdl"
  @client = Savon.client(wsdl: wsdl_url)
end

Instance Method Details

#check_credentialsBoolean

Checks if the user has input valid credentials

Returns:

  • (Boolean)

    Whether the credentials entered are valid or not


13
14
15
16
17
18
# File 'lib/oca-epak/epak/client.rb', line 13

def check_credentials
  method = :get_epack_user
  opts = { "usr" => username, "psw" => password }
  response = client.call(method, message: opts)
  parse_results_table(response, method).first[:existe] == "1"
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: {})
  • [Oca::Epak::PickupData] (Hash)

    a customizable set of options

  • [Boolean] (Hash)

    a customizable set of options

  • [Integer] (Hash)

    a customizable set of options

Returns:

  • (Hash, nil)

See Also:


30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/oca-epak/epak/client.rb', line 30

def create_pickup_order(opts = {})
  confirm_pickup = opts.fetch(:confirm_pickup, false)
  days_to_pickup = opts.fetch(:days_to_pickup, "1")
  pickup_range = opts.fetch(:pickup_range, "1")
  rendered_xml = opts[:pickup_data].to_xml

  message = { "usr" => username, "psw" => 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


84
85
86
87
88
89
# File 'lib/oca-epak/epak/client.rb', line 84

def get_operation_codes
  method = :get_operativas_by_usuario
  opts = { "usr" => username, "psw" => 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: {})
  • [String] (Hash)

    a customizable set of options

Returns:

  • (Hash, nil)

    Contains Total Price, Delivery Estimate


58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/oca-epak/epak/client.rb', line 58

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


98
99
100
101
102
103
104
# File 'lib/oca-epak/epak/client.rb', line 98

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


109
110
111
112
113
114
# File 'lib/oca-epak/epak/client.rb', line 109

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


75
76
77
78
79
# File 'lib/oca-epak/epak/client.rb', line 75

def taxation_centers
  method = :get_centros_imposicion
  response = client.call(method)
  parse_results_table(response, method)
end