Class: Oca

Inherits:
Object
  • Object
show all
Defined in:
lib/oca-epak.rb

Constant Summary collapse

WSDL =
'http://webservice.oca.com.ar/oep_tracking/Oep_Track.asmx?WSDL'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOca

Returns a new instance of Oca.



8
9
10
# File 'lib/oca-epak.rb', line 8

def initialize
  @client = Savon.client(wsdl: WSDL)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



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

def client
  @client
end

Instance Method Details

#check_credentials(username, password) ⇒ Boolean

Checks if the user has input valid credentials

Parameters:

  • Username (String)

    (Email)

  • Password (String)

Returns:

  • (Boolean)

    Whether the credentials are valid or not



17
18
19
20
21
22
23
24
25
# File 'lib/oca-epak.rb', line 17

def check_credentials(username, password)
  begin
    opts = { "usr" => username, "psw" => password }
    client.call(:generar_consolidacion_de_ordenes_de_retiro, message: opts)
    false
  rescue Savon::SOAPFault => e
    true
  end
end

#check_operation(cuit, op) ⇒ Boolean

Checks whether the operation is valid

Parameters:

  • Client's (String)

    CUIT

  • Operation (String)

    Type

Returns:

  • (Boolean)


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

def check_operation(cuit, op)
  begin
    opts = { wt: "50", vol: "0.027", origin: "1414", destination: "5403",
      qty: "1", cuit: cuit, op: op }
    get_shipping_rates(opts)
    true
  rescue NoMethodError => e
    false
  end
end

#get_shipping_rates(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



54
55
56
57
58
59
60
61
62
63
# File 'lib/oca-epak.rb', line 54

def get_shipping_rates(opts = {})
  method = :tarifar_envio_corporativo
  message = { "PesoTotal" => opts[:wt], "VolumenTotal" => opts[:vol],
              "CodigoPostalOrigen" => opts[:origin],
              "CodigoPostalDestino" => opts[:destination],
              "CantidadPaquetes" => opts[:qty], "Cuit" => opts[:cuit],
              "Operativa" => opts[:op] }
  response = client.call(method, message: message)
  parse_results(method, response)
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



81
82
83
84
85
86
87
# File 'lib/oca-epak.rb', line 81

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(method, response)
end

#provincesArray?

Returns all provinces in Argentina

Returns:

  • (Array, nil)

    Provinces in Argentina with their ID and name as a Hash



92
93
94
95
96
97
# File 'lib/oca-epak.rb', line 92

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



68
69
70
71
72
# File 'lib/oca-epak.rb', line 68

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