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