oca-epak 0.2.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/oca-epak.rb +141 -89
- data/lib/oca-epak/errors/bad_request.rb +4 -0
- data/lib/oca-epak/errors/error.rb +4 -0
- data/lib/oca-epak/pickup_data.rb +29 -0
- data/lib/oca-epak/version.rb +5 -0
- metadata +6 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9c5f04a073183bc57a5503b8a5c677a01e45aa21
|
|
4
|
+
data.tar.gz: a24c7b70efa907c1b263caf863e2b7cd3e285a9e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 19683eaa6a9815526daffbd659240d5e99cd0e55b15a8d657d46f97f7e25b8ba33741468173bc5c058aaad78a397847bd9050f0ee4c645fb57f035865b6c3a43
|
|
7
|
+
data.tar.gz: c9257ce2e186a08c5ffe1e67004f73504113c56007a27ffedc6d81be57cf005b38105dfa83d82baf8e958b587c2bcb53bee576eb7607a3adfd9b6591cf5e31fb
|
data/lib/oca-epak.rb
CHANGED
|
@@ -1,108 +1,160 @@
|
|
|
1
1
|
require 'savon'
|
|
2
|
+
require 'erb'
|
|
3
|
+
require 'ostruct'
|
|
4
|
+
require 'oca-epak/pickup_data'
|
|
5
|
+
require 'oca-epak/errors/error'
|
|
6
|
+
require 'oca-epak/errors/bad_request'
|
|
2
7
|
|
|
3
|
-
|
|
4
|
-
|
|
8
|
+
module Oca
|
|
9
|
+
class Epak
|
|
10
|
+
attr_reader :client
|
|
11
|
+
attr_accessor :username, :password
|
|
5
12
|
|
|
6
|
-
|
|
13
|
+
WSDL = 'http://webservice.oca.com.ar/epak_tracking/Oep_TrackEPak.asmx?wsdl'.freeze
|
|
7
14
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
15
|
+
def initialize(username, password)
|
|
16
|
+
@client = Savon.client(wsdl: WSDL)
|
|
17
|
+
@username = username
|
|
18
|
+
@password = password
|
|
19
|
+
end
|
|
11
20
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def check_credentials(username, password)
|
|
18
|
-
begin
|
|
21
|
+
# Checks if the user has input valid credentials
|
|
22
|
+
#
|
|
23
|
+
# @return [Boolean] Whether the credentials entered are valid or not
|
|
24
|
+
def check_credentials
|
|
25
|
+
method = :get_epack_user
|
|
19
26
|
opts = { "usr" => username, "psw" => password }
|
|
20
|
-
client.call(
|
|
21
|
-
|
|
22
|
-
rescue Savon::SOAPFault => e
|
|
23
|
-
true
|
|
27
|
+
response = client.call(method, message: opts)
|
|
28
|
+
parse_results_table(response, method)[:existe] == "1"
|
|
24
29
|
end
|
|
25
|
-
end
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
# Checks whether the operation is valid
|
|
32
|
+
#
|
|
33
|
+
# @param [String] Client's CUIT
|
|
34
|
+
# @param [String] Operation Type
|
|
35
|
+
# @return [Boolean]
|
|
36
|
+
def check_operation(cuit, op)
|
|
37
|
+
begin
|
|
38
|
+
opts = { wt: "50", vol: "0.027", origin: "1414", destination: "5403",
|
|
39
|
+
qty: "1", total: "123", cuit: cuit, op: op }
|
|
40
|
+
get_shipping_rates(opts)
|
|
41
|
+
true
|
|
42
|
+
rescue Oca::Epak::Error => e
|
|
43
|
+
false
|
|
44
|
+
end
|
|
40
45
|
end
|
|
41
|
-
end
|
|
42
46
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"CodigoPostalDestino" => opts[:destination],
|
|
59
|
-
"CantidadPaquetes" => opts[:qty], "Cuit" => opts[:cuit],
|
|
60
|
-
"Operativa" => opts[:op] }
|
|
61
|
-
response = client.call(method, message: message)
|
|
62
|
-
parse_results(method, response)
|
|
63
|
-
end
|
|
47
|
+
# Creates a Pickup Order, which lets OCA know you want to make a delivery.
|
|
48
|
+
#
|
|
49
|
+
# @see [http://www.ombushop.com/oca/documentation.pdf] #TODO put it there
|
|
50
|
+
#
|
|
51
|
+
# @param [Hash] opts
|
|
52
|
+
# @option [Oca::Epak::PickupData] :pickup_data Pickup Data object
|
|
53
|
+
# @option [Boolean] :confirm_pickup Confirm Pickup? Defaults to false
|
|
54
|
+
# @option [Integer] :days_to_pickup Days OCA should wait before pickup, default: 1 (?) #TODO Confirm
|
|
55
|
+
# @option [Integer] :pickup_range Range to be used when picking it up, default: 1
|
|
56
|
+
# @return [Hash, nil]
|
|
57
|
+
def create_pickup_order(opts = {})
|
|
58
|
+
confirm_pickup = opts.fetch(:confirm_pickup, false)
|
|
59
|
+
days_to_pickup = opts.fetch(:days_to_pickup, "1")
|
|
60
|
+
pickup_range = opts.fetch(:pickup_range, "1")
|
|
61
|
+
rendered_xml = opts[:pickup_data].to_xml
|
|
64
62
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
message = { "usr" => username, "psw" => password,
|
|
64
|
+
"xml_Datos" => rendered_xml,
|
|
65
|
+
"ConfirmarRetiro" => confirm_pickup.to_s,
|
|
66
|
+
"DiasHastaRetiro" => days_to_pickup,
|
|
67
|
+
"idFranjaHoraria" => pickup_range }
|
|
68
|
+
response = client.call(:ingreso_or, message: message)
|
|
69
|
+
parse_results_table(response, :ingreso_or)
|
|
70
|
+
end
|
|
73
71
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
72
|
+
# Get rates and delivery estimate for a shipment
|
|
73
|
+
#
|
|
74
|
+
# @param [Hash] opts
|
|
75
|
+
# @option [String] :wt Total Weight e.g: 20
|
|
76
|
+
# @option [String] :vol Total Volume e.g: 0.0015 (0.1mts * 0.15mts * 0.1mts)
|
|
77
|
+
# @option [Integer] :origin Origin ZIP Code
|
|
78
|
+
# @option [Integer] :destination Destination ZIP Code
|
|
79
|
+
# @option [Integer] :qty Quantity of Packages
|
|
80
|
+
# @option [Integer] :total Declared Value
|
|
81
|
+
# @option [String] :cuit Client's CUIT e.g: 30-99999999-7
|
|
82
|
+
# @option [String] :op Operation Type
|
|
83
|
+
# @return [Hash, nil] Contains Total Price, Delivery Estimate
|
|
84
|
+
def get_shipping_rates(opts = {})
|
|
85
|
+
method = :tarifar_envio_corporativo
|
|
86
|
+
message = { "PesoTotal" => opts[:wt], "VolumenTotal" => opts[:vol],
|
|
87
|
+
"CodigoPostalOrigen" => opts[:origin],
|
|
88
|
+
"CodigoPostalDestino" => opts[:destination],
|
|
89
|
+
"ValorDeclarado" => opts[:total],
|
|
90
|
+
"CantidadPaquetes" => opts[:qty], "Cuit" => opts[:cuit],
|
|
91
|
+
"Operativa" => opts[:op] }
|
|
92
|
+
response = client.call(method, message: message)
|
|
93
|
+
parse_results_table(response, method)
|
|
94
|
+
end
|
|
88
95
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
# Returns all existing Taxation Centers
|
|
97
|
+
#
|
|
98
|
+
# @return [Array, nil] Information for all the Oca Taxation Centers
|
|
99
|
+
def taxation_centers
|
|
100
|
+
method = :get_centros_imposicion
|
|
101
|
+
response = client.call(method)
|
|
102
|
+
parse_results_table(response, method)
|
|
96
103
|
end
|
|
97
|
-
end
|
|
98
104
|
|
|
99
|
-
|
|
105
|
+
# Returns all operation codes
|
|
106
|
+
#
|
|
107
|
+
# @return [Array, nil] Returns all operation codes available for the user
|
|
108
|
+
def get_operation_codes
|
|
109
|
+
method = :get_operativas_by_usuario
|
|
110
|
+
opts = { "usr" => username, "psw" => password }
|
|
111
|
+
response = client.call(method, message: opts)
|
|
112
|
+
parse_results_table(response, method)
|
|
113
|
+
end
|
|
100
114
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
115
|
+
# Given a client's CUIT with a range of dates, returns a list with
|
|
116
|
+
# all shipments made within the given period.
|
|
117
|
+
#
|
|
118
|
+
# @param [String] Client's CUIT
|
|
119
|
+
# @param [String] "From date" in DD-MM-YYYY format
|
|
120
|
+
# @param [String] "To date" in DD-MM-YYYY format
|
|
121
|
+
# @return [Array, nil] Contains an array of hashes with NroProducto and NumeroEnvio
|
|
122
|
+
def list_shipments(cuit, from_date, to_date)
|
|
123
|
+
method = :list_envios
|
|
124
|
+
opts = { "CUIT" => cuit, "FechaDesde" => from_date,
|
|
125
|
+
"FechaHasta" => to_date }
|
|
126
|
+
response = client.call(method, message: opts)
|
|
127
|
+
parse_results_table(response, method)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Returns all provinces in Argentina
|
|
131
|
+
#
|
|
132
|
+
# @return [Array, nil] Provinces in Argentina with their ID and name as a Hash
|
|
133
|
+
def provinces
|
|
134
|
+
response = client.call(:get_provincias)
|
|
135
|
+
if body = response.body[:get_provincias_response]
|
|
136
|
+
body[:get_provincias_result][:provincias][:provincia]
|
|
106
137
|
end
|
|
107
138
|
end
|
|
139
|
+
|
|
140
|
+
private
|
|
141
|
+
|
|
142
|
+
def parse_result(response, method)
|
|
143
|
+
method_response = "#{method}_response".to_sym
|
|
144
|
+
method_result = "#{method}_result".to_sym
|
|
145
|
+
if body = response.body[method_response]
|
|
146
|
+
body[method_result]
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def parse_results_table(response, method)
|
|
151
|
+
if result = parse_result(response, method)
|
|
152
|
+
if result[:diffgram][:new_data_set]
|
|
153
|
+
result[:diffgram][:new_data_set][:table]
|
|
154
|
+
else
|
|
155
|
+
raise Oca::Epak::BadRequest.new("Oca WS responded with:\n#{response.body}")
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
108
160
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Oca
|
|
2
|
+
class Epak::PickupData
|
|
3
|
+
|
|
4
|
+
attr_accessor :account_number, :pickup, :shipments
|
|
5
|
+
|
|
6
|
+
# Creates a Pickup Data object for creating a pickup order in OCA.
|
|
7
|
+
#
|
|
8
|
+
# @param [Hash] opts
|
|
9
|
+
# @option [String] :account_number Account Number (SAP)
|
|
10
|
+
# @option [Hash] :pickup Pickup Hash
|
|
11
|
+
# @option [Array<Hash>] :shipments Shipments Hash
|
|
12
|
+
def initialize(opts = {})
|
|
13
|
+
self.account_number = opts[:account_number]
|
|
14
|
+
self.pickup = opts[:pickup]
|
|
15
|
+
self.shipments = opts[:shipments]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def to_xml
|
|
19
|
+
or_template.result(binding)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def or_template
|
|
25
|
+
path_to_xml = File.expand_path("../retiro.xml.erb", __FILE__)
|
|
26
|
+
ERB.new(File.read(path_to_xml), nil, "-")
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: oca-epak
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mauro Otonelli
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2015-
|
|
12
|
+
date: 2015-11-09 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: savon
|
|
@@ -104,6 +104,10 @@ extensions: []
|
|
|
104
104
|
extra_rdoc_files: []
|
|
105
105
|
files:
|
|
106
106
|
- lib/oca-epak.rb
|
|
107
|
+
- lib/oca-epak/errors/bad_request.rb
|
|
108
|
+
- lib/oca-epak/errors/error.rb
|
|
109
|
+
- lib/oca-epak/pickup_data.rb
|
|
110
|
+
- lib/oca-epak/version.rb
|
|
107
111
|
homepage: https://github.com/ombulabs/oca-epak
|
|
108
112
|
licenses: []
|
|
109
113
|
metadata: {}
|