correios_gem 1.4.2 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/correios_gem.gemspec +29 -0
- data/lib/SRO/requests/track_shippings.rb +31 -45
- data/lib/{credentials.rb → auxiliars/credentials.rb} +0 -0
- data/lib/auxiliars/environments.rb +94 -0
- data/lib/auxiliars/exception.rb +5 -0
- data/lib/auxiliars/helper.rb +404 -0
- data/lib/correios_gem.rb +22 -24
- data/lib/pricefier/requests/calculate_deadline.rb +27 -45
- data/lib/pricefier/requests/calculate_price.rb +34 -53
- data/lib/pricefier/requests/calculate_price_deadline.rb +49 -63
- data/lib/pricefier/requests/calculate_price_fac.rb +21 -46
- data/lib/pricefier/requests/list_services.rb +26 -42
- data/lib/reverse_logistics/requests/calculate_ticket_number_check_digit.rb +10 -21
- data/lib/reverse_logistics/requests/cancel_shipping.rb +13 -23
- data/lib/reverse_logistics/requests/create_shippings.rb +22 -36
- data/lib/reverse_logistics/requests/create_shippings_with_collection.rb +17 -33
- data/lib/reverse_logistics/requests/request_ticket_numbers.rb +13 -35
- data/lib/reverse_logistics/requests/track_shipping.rb +18 -39
- data/lib/reverse_logistics/requests/track_shippings_by_date.rb +19 -45
- data/lib/sigep/auxiliars/shipping_xml.rb +100 -0
- data/lib/sigep/requests/calculate_label_number_check_digit.rb +13 -27
- data/lib/sigep/requests/cancel_shipping.rb +12 -25
- data/lib/sigep/requests/check_card_status.rb +11 -27
- data/lib/sigep/requests/check_service_availability.rb +12 -39
- data/lib/sigep/requests/create_shippings.rb +20 -24
- data/lib/sigep/requests/request_label_numbers.rb +11 -17
- data/lib/sigep/requests/request_shippings_xml.rb +14 -53
- data/lib/sigep/requests/search_available_additional_services.rb +12 -20
- data/lib/sigep/requests/search_customer.rb +15 -37
- data/lib/sigep/requests/search_zip_code.rb +11 -16
- data/lib/sigep/requests/track_shippings.rb +19 -51
- metadata +22 -19
- data/lib/SRO/client.rb +0 -25
- data/lib/SRO/helper.rb +0 -118
- data/lib/SRO/requests/track_shippings_list.rb +0 -144
- data/lib/correios_exception.rb +0 -11
- data/lib/pricefier/client.rb +0 -20
- data/lib/pricefier/helper.rb +0 -72
- data/lib/pricefier/requests/calculate_deadline_with_date.rb +0 -102
- data/lib/pricefier/requests/calculate_deadline_with_restrictions.rb +0 -102
- data/lib/pricefier/requests/calculate_price_deadline_with_date.rb +0 -142
- data/lib/pricefier/requests/calculate_price_deadline_with_restrictions.rb +0 -142
- data/lib/pricefier/requests/calculate_price_with_date.rb +0 -125
- data/lib/pricefier/requests/list_services_star.rb +0 -87
- data/lib/reverse_logistics/client.rb +0 -34
- data/lib/reverse_logistics/helper.rb +0 -95
- data/lib/sigep/client.rb +0 -29
- data/lib/sigep/helper.rb +0 -234
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3effd48cfda5b95dc4651f7da866b603670821b1810715e4c9f4e45499648816
|
4
|
+
data.tar.gz: e76beb29d7c3b198fe08cf0601c89fa6f63f427b62827d2875ccde646f502925
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a461c743a47eac0aee55fd8ed23010b1e07b67ce333d98f0158c11861b30de07fe3607e1b9815c1600620e6e3d8a293a34e79b9a9b5c0c833cee651a079d0a9b
|
7
|
+
data.tar.gz: a2222afeb2b1900201dfedce91f06903ea311124ae7338d9cdbb5cc08cfca0a25b9a5583fbdfb28f68371e5ca99ad38fb22bb0969f388e417551285fcad865c7
|
@@ -0,0 +1,29 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.author = 'Arthur Soares'
|
3
|
+
s.email = 'arthurvsp97@gmail.com'
|
4
|
+
|
5
|
+
s.name = 'correios_gem'
|
6
|
+
s.version = '1.4.3'
|
7
|
+
s.date = '2019-03-09'
|
8
|
+
s.homepage = 'https://github.com/arthursoas/correios_gem'
|
9
|
+
s.summary = 'A correios-gem integra sua aplicacao com as APIs dos
|
10
|
+
Correios'
|
11
|
+
s.description = 'Integracao com as APIs Sigep, Logistica Reversa,
|
12
|
+
Precificador (frete) e SRO, utilizando objetos Ruby para
|
13
|
+
requisicoes e respostas. Integrar com os Correios nunca foi
|
14
|
+
tao simples.'
|
15
|
+
s.license = 'MIT'
|
16
|
+
s.files = Dir['lib/**/*'] + %w[correios_gem.gemspec]
|
17
|
+
|
18
|
+
s.add_dependency 'activesupport', '~> 5.2', '>= 5.2.2'
|
19
|
+
s.add_dependency 'nokogiri', '~> 1.9', '>= 1.9.1'
|
20
|
+
s.add_dependency 'savon', '~> 2.12', '>= 2.12.0'
|
21
|
+
|
22
|
+
s.add_development_dependency 'rspec', '~> 3.0'
|
23
|
+
|
24
|
+
# s.add_development_dependency 'bundler', '~> 1.11'
|
25
|
+
# s.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
# s.add_development_dependency 'simplecov', '~> 0.14.1'
|
27
|
+
# s.add_development_dependency 'coveralls', '~> 0.8.21'
|
28
|
+
# s.add_development_dependency 'rubocop', '~> 0.52.1'
|
29
|
+
end
|
@@ -1,20 +1,10 @@
|
|
1
|
-
require 'savon'
|
2
|
-
require 'nokogiri'
|
3
|
-
|
4
|
-
require_relative '../client'
|
5
|
-
require_relative '../helper'
|
6
|
-
require_relative '../../correios_exception.rb'
|
7
|
-
|
8
1
|
module Correios
|
9
2
|
module SRO
|
10
|
-
class TrackShippings <
|
11
|
-
HELPER = Helper.new
|
12
|
-
CLIENT = Client.new
|
13
|
-
|
3
|
+
class TrackShippings < Helper
|
14
4
|
def initialize(data = {})
|
15
5
|
@credentials = Correios.credentials
|
16
|
-
|
17
6
|
@show_request = data[:show_request]
|
7
|
+
|
18
8
|
@label_numbers = data[:label_numbers]
|
19
9
|
@query_type = data[:query_type]
|
20
10
|
@result_type = data[:result_type]
|
@@ -22,19 +12,21 @@ module Correios
|
|
22
12
|
super()
|
23
13
|
end
|
24
14
|
|
25
|
-
def request
|
15
|
+
def request(method)
|
16
|
+
@method = method
|
17
|
+
@method_snake = method.underscore
|
18
|
+
|
26
19
|
puts xml if @show_request == true
|
27
20
|
begin
|
28
|
-
format_response(
|
29
|
-
|
30
|
-
|
21
|
+
format_response(SRO.client.call(
|
22
|
+
@method_snake.to_sym,
|
23
|
+
soap_action: '',
|
24
|
+
xml: xml
|
25
|
+
).to_hash)
|
31
26
|
rescue Savon::SOAPFault => error
|
32
|
-
|
27
|
+
generate_soap_fault_exception(error)
|
33
28
|
rescue Savon::HTTPError => error
|
34
|
-
|
35
|
-
generate_exception("Unauthorized (#{error.http.code}).")
|
36
|
-
end
|
37
|
-
generate_exception("Unknown HTTP error (#{error.http.code}).")
|
29
|
+
generate_http_exception(error.http.code)
|
38
30
|
end
|
39
31
|
end
|
40
32
|
|
@@ -42,16 +34,22 @@ module Correios
|
|
42
34
|
|
43
35
|
def xml
|
44
36
|
Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
|
45
|
-
xml['soap'].Envelope(
|
37
|
+
xml['soap'].Envelope(SRO.namespaces) do
|
46
38
|
xml['soap'].Body do
|
47
|
-
xml['ns1'].
|
39
|
+
xml['ns1'].send(@method) do
|
48
40
|
parent_namespace = xml.parent.namespace
|
49
41
|
xml.parent.namespace = nil
|
50
42
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
43
|
+
if @method == 'buscaEventosLista'
|
44
|
+
@label_numbers.each do |label_number|
|
45
|
+
xml.objetos label_number
|
46
|
+
end
|
47
|
+
elsif @method == 'buscaEventos'
|
48
|
+
xml.objetos array_to_string(@label_numbers)
|
49
|
+
end
|
50
|
+
xml.tipo tracking_query_type(@query_type)
|
51
|
+
xml.resultado tracking_result_type(@result_type)
|
52
|
+
xml.lingua tracking_language(@language)
|
55
53
|
xml.usuario @credentials.sro_user
|
56
54
|
xml.senha @credentials.sro_password
|
57
55
|
|
@@ -63,19 +61,12 @@ module Correios
|
|
63
61
|
end
|
64
62
|
|
65
63
|
def format_response(response)
|
66
|
-
response = response[
|
67
|
-
|
64
|
+
response = response["#{@method_snake}_response".to_sym][:return]
|
68
65
|
objects = response[:objeto]
|
69
66
|
objects = [objects] if objects.is_a?(Hash)
|
70
|
-
|
71
|
-
generate_exception(objects.first[:erro]) if objects.first[:numero] == 'Erro'
|
72
|
-
|
73
|
-
formatted_objects = []
|
74
|
-
objects.each do |object|
|
75
|
-
formatted_objects << format_object(object)
|
76
|
-
end
|
67
|
+
generate_sro_exception(objects)
|
77
68
|
|
78
|
-
{ tracking:
|
69
|
+
{ tracking: objects.map {|o| format_object(o)} }
|
79
70
|
end
|
80
71
|
|
81
72
|
def format_object(object)
|
@@ -91,11 +82,6 @@ module Correios
|
|
91
82
|
events = object[:evento]
|
92
83
|
events = [events] if events.is_a?(Hash)
|
93
84
|
|
94
|
-
formatted_events = []
|
95
|
-
events.each do |event|
|
96
|
-
formatted_events << format_event(event)
|
97
|
-
end
|
98
|
-
|
99
85
|
{
|
100
86
|
label: {
|
101
87
|
number: object[:numero],
|
@@ -103,16 +89,16 @@ module Correios
|
|
103
89
|
name: object[:nome],
|
104
90
|
category: object[:categoria]
|
105
91
|
},
|
106
|
-
events:
|
92
|
+
events: events.map {|e| format_event(e)}
|
107
93
|
}
|
108
94
|
end
|
109
95
|
|
110
96
|
def format_event(event)
|
111
97
|
{
|
112
|
-
movement:
|
98
|
+
movement: inverse_tracking_event_status(event),
|
113
99
|
type: event[:tipo],
|
114
100
|
status: event[:status],
|
115
|
-
time:
|
101
|
+
time: string_to_time_no_second(event[:data], event[:hora]),
|
116
102
|
description: event[:descricao],
|
117
103
|
detail: event[:detalhe],
|
118
104
|
city: event[:cidade],
|
File without changes
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Correios
|
2
|
+
module Pricefier
|
3
|
+
def self.client
|
4
|
+
base_client(wsdl: wsdl)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.namespaces
|
8
|
+
{
|
9
|
+
'xmlns:soap' => 'http://www.w3.org/2003/05/soap-envelope',
|
10
|
+
'xmlns:ns1' => 'http://tempuri.org/'
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.wsdl
|
15
|
+
'http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx?wsdl'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module ReverseLogistics
|
20
|
+
def self.client
|
21
|
+
base_client(wsdl: wsdl,
|
22
|
+
basic_auth: [
|
23
|
+
Correios.credentials.reverse_logistics_user || 'user',
|
24
|
+
Correios.credentials.reverse_logistics_password || 'pass'
|
25
|
+
])
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.namespaces
|
29
|
+
{
|
30
|
+
'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/',
|
31
|
+
'xmlns:ns1' => 'http://service.logisticareversa.correios.com.br/'
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.wsdl
|
36
|
+
if production_env?
|
37
|
+
'https://cws.correios.com.br/logisticaReversaWS/logisticaReversaService/logisticaReversaWS?wsdl'
|
38
|
+
else
|
39
|
+
'https://apphom.correios.com.br/logisticaReversaWS/logisticaReversaService/logisticaReversaWS?wsdl'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
module Sigep
|
45
|
+
def self.client
|
46
|
+
base_client(wsdl: wsdl)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.namespaces
|
50
|
+
{
|
51
|
+
'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/',
|
52
|
+
'xmlns:ns1' => 'http://cliente.bean.master.sigep.bsb.correios.com.br/'
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.wsdl
|
57
|
+
if production_env?
|
58
|
+
'https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl'
|
59
|
+
else
|
60
|
+
'https://apphom.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
module SRO
|
66
|
+
def self.client
|
67
|
+
base_client(wsdl: wsdl)
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.namespaces
|
71
|
+
{
|
72
|
+
'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/',
|
73
|
+
'xmlns:ns1' => 'http://resource.webservice.correios.com.br/'
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.wsdl
|
78
|
+
'https://webservice.correios.com.br/service/rastro/Rastro.wsdl'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def base_client(wsdl:, ssl_verify_mode: :none, basic_auth: [])
|
84
|
+
Savon.client(wsdl: wsdl,
|
85
|
+
basic_auth: basic_auth,
|
86
|
+
ssl_verify_mode: ssl_verify_mode)
|
87
|
+
end
|
88
|
+
|
89
|
+
def production_env?
|
90
|
+
return false unless defined?(Rails)
|
91
|
+
return true if Rails.env.production?
|
92
|
+
|
93
|
+
false
|
94
|
+
end
|
@@ -0,0 +1,404 @@
|
|
1
|
+
require_relative './exception'
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
require 'time'
|
5
|
+
|
6
|
+
class Helper < CorreiosException
|
7
|
+
def generate_soap_fault_exception(message)
|
8
|
+
message = message.to_s.gsub('(soap:Server)', '')
|
9
|
+
message = message.strip
|
10
|
+
generate_exception(message.capitalize)
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate_http_exception(status)
|
14
|
+
case status
|
15
|
+
when 400
|
16
|
+
generate_exception("Bad request. Status code #{status}")
|
17
|
+
when 401
|
18
|
+
generate_exception("Access unauthorized. Status code #{status}")
|
19
|
+
when 404
|
20
|
+
generate_exception("Data or method not found. Status code #{status}")
|
21
|
+
when 500
|
22
|
+
generate_exception("Internal server error. Status code #{status}")
|
23
|
+
when 503
|
24
|
+
generate_exception("Service unavailable. Status code #{status}")
|
25
|
+
when 504
|
26
|
+
generate_exception("Gateway timeout. Status code #{status}")
|
27
|
+
else
|
28
|
+
generate_exception("Unknown HTTP error. Status code #{status}")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def generate_revese_logistics_exception(response)
|
33
|
+
unless response[:cod_erro].to_i.zero?
|
34
|
+
generate_exception(response[:msg_erro].capitalize)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def generate_sro_exception(objects)
|
39
|
+
generate_exception(objects.first[:erro]) if objects.first[:numero] == 'Erro'
|
40
|
+
end
|
41
|
+
|
42
|
+
def remove_label_digit_checker(label_number)
|
43
|
+
label_number.slice!(10)
|
44
|
+
label_number
|
45
|
+
end
|
46
|
+
|
47
|
+
def calculate_reverse_shipping_deadline(value, type)
|
48
|
+
if type == :authorization
|
49
|
+
return value if value.is_a?(Numeric)
|
50
|
+
|
51
|
+
Date.today - value
|
52
|
+
else
|
53
|
+
return (Date.today + value).strftime('%d/%m/%Y') if value.is_a?(Numeric)
|
54
|
+
|
55
|
+
value.strftime('%d/%m/%Y')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def calculate_shipping_deadline(days, saturday, date = Date.today)
|
60
|
+
if saturday
|
61
|
+
days.to_i.times do
|
62
|
+
date += 1.days
|
63
|
+
date += 1.days if date.sunday?
|
64
|
+
end
|
65
|
+
else
|
66
|
+
days.to_i.times do
|
67
|
+
date += 1.days
|
68
|
+
date += 1.days if deadline.sunday? || deadline.saturday?
|
69
|
+
end
|
70
|
+
end
|
71
|
+
date
|
72
|
+
end
|
73
|
+
|
74
|
+
# Converters
|
75
|
+
|
76
|
+
def string_to_bool(string)
|
77
|
+
string.strip == 'S'
|
78
|
+
end
|
79
|
+
|
80
|
+
def bool_to_string(bool)
|
81
|
+
bool ? 'S' : 'N'
|
82
|
+
end
|
83
|
+
|
84
|
+
def bool_to_int(bool)
|
85
|
+
bool ? 1 : 0
|
86
|
+
end
|
87
|
+
|
88
|
+
def string_to_time(date, time)
|
89
|
+
time = time.strftime('%H:%M:%S')
|
90
|
+
Time.strptime("#{date} #{time}", '%d-%m-%Y %H:%M:%S')
|
91
|
+
end
|
92
|
+
|
93
|
+
def string_to_time_no_second(date, time)
|
94
|
+
Time.strptime("#{date} #{time}", '%d/%m/%Y %H:%M')
|
95
|
+
end
|
96
|
+
|
97
|
+
def string_to_date(date)
|
98
|
+
Date.strptime(date, '%d/%m/%Y')
|
99
|
+
end
|
100
|
+
|
101
|
+
def date_to_string(date)
|
102
|
+
date.strftime('%d/%m/%Y')
|
103
|
+
end
|
104
|
+
|
105
|
+
def string_to_decimal(string)
|
106
|
+
return nil if string.nil?
|
107
|
+
|
108
|
+
string.tr(',', '.').to_f
|
109
|
+
end
|
110
|
+
|
111
|
+
def decimal_to_string(decimal)
|
112
|
+
return nil if decimal.nil?
|
113
|
+
|
114
|
+
decimal.to_s.tr('.', ',')
|
115
|
+
end
|
116
|
+
|
117
|
+
def array_to_string_comma(array)
|
118
|
+
return nil if array.nil?
|
119
|
+
|
120
|
+
array.join(',')
|
121
|
+
end
|
122
|
+
|
123
|
+
def array_to_string(array)
|
124
|
+
return nil if array.nil?
|
125
|
+
|
126
|
+
array.join('')
|
127
|
+
end
|
128
|
+
|
129
|
+
# Enumerizers
|
130
|
+
|
131
|
+
def object_type(type)
|
132
|
+
case type
|
133
|
+
when :letter_envelope
|
134
|
+
'001'
|
135
|
+
when :box
|
136
|
+
'002'
|
137
|
+
when :prism
|
138
|
+
'002'
|
139
|
+
when :cylinder
|
140
|
+
'003'
|
141
|
+
else
|
142
|
+
generate_exception('Object type not in list.')
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def pricefier_object_type(type)
|
147
|
+
case type
|
148
|
+
when :letter_envelope
|
149
|
+
3
|
150
|
+
when :box
|
151
|
+
1
|
152
|
+
when :prism
|
153
|
+
1
|
154
|
+
when :cylinder
|
155
|
+
2
|
156
|
+
else
|
157
|
+
generate_exception('Object type not in list.')
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def payment_method(method)
|
162
|
+
case method
|
163
|
+
when :postal_vouncher
|
164
|
+
1
|
165
|
+
when :postal_refound
|
166
|
+
2
|
167
|
+
when :exchange_contract
|
168
|
+
3
|
169
|
+
when :credit_card
|
170
|
+
4
|
171
|
+
when :other
|
172
|
+
5
|
173
|
+
when :to_bill
|
174
|
+
nil
|
175
|
+
else
|
176
|
+
generate_exception('Payment method not in list.')
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def reverse_shipping_type(type)
|
181
|
+
case type
|
182
|
+
when :authorization
|
183
|
+
'A'
|
184
|
+
when :pickup
|
185
|
+
'C'
|
186
|
+
when :authorization_pickup
|
187
|
+
'CA'
|
188
|
+
else
|
189
|
+
generate_exception('Shipping type not in list.')
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
def ticket_type(type)
|
194
|
+
case type
|
195
|
+
when :authorization
|
196
|
+
'AP'
|
197
|
+
when :pickup
|
198
|
+
'LR'
|
199
|
+
else
|
200
|
+
generate_exception('Tickect type not in list.')
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def reverse_shipping_service(service)
|
205
|
+
case service
|
206
|
+
when :pac
|
207
|
+
'LR'
|
208
|
+
when :sedex
|
209
|
+
'LS'
|
210
|
+
when :e_sedex
|
211
|
+
'LV'
|
212
|
+
else
|
213
|
+
service
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
def reverse_tracking_result_type(result_type)
|
218
|
+
case result_type
|
219
|
+
when :last_event
|
220
|
+
'U'
|
221
|
+
when :all_events
|
222
|
+
'H'
|
223
|
+
else
|
224
|
+
generate_exception('Tracking result type not in list.')
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def tracking_query_type(query_type)
|
229
|
+
case query_type
|
230
|
+
when :list
|
231
|
+
'L'
|
232
|
+
when :range
|
233
|
+
'F'
|
234
|
+
else
|
235
|
+
generate_exception('Query type not in list.')
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
def tracking_result_type(result_type)
|
240
|
+
case result_type
|
241
|
+
when :last_event
|
242
|
+
'U'
|
243
|
+
when :all_events
|
244
|
+
'T'
|
245
|
+
else
|
246
|
+
generate_exception('Query type not in list.')
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
def tracking_language(language)
|
251
|
+
case language
|
252
|
+
when :portuguese
|
253
|
+
'101'
|
254
|
+
when :english
|
255
|
+
'102'
|
256
|
+
else
|
257
|
+
generate_exception('Language not in list.')
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
# Inverted enumerizers
|
262
|
+
|
263
|
+
def inverse_card_status(status)
|
264
|
+
case status
|
265
|
+
when 'Normal'
|
266
|
+
:ok
|
267
|
+
when 'Cancelado'
|
268
|
+
:canceled
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
def inverse_shipping_cancellation(status)
|
273
|
+
case status
|
274
|
+
when 'Registro gravado'
|
275
|
+
:ok
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
def inverse_payment_method(method)
|
280
|
+
case method
|
281
|
+
when '1'
|
282
|
+
:postal_vouncher
|
283
|
+
when '2'
|
284
|
+
:postal_refound
|
285
|
+
when '3'
|
286
|
+
:exchange_contract
|
287
|
+
when '4'
|
288
|
+
:credit_card
|
289
|
+
when '5'
|
290
|
+
:other
|
291
|
+
when nil
|
292
|
+
:to_bill
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
def inverse_object_type(type)
|
297
|
+
case type
|
298
|
+
when '1'
|
299
|
+
:letter_envelope
|
300
|
+
when '2'
|
301
|
+
:box_prism
|
302
|
+
when '3'
|
303
|
+
:cylinder
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
def inverse_service_availability(availability)
|
308
|
+
case availability.to_i
|
309
|
+
when 0, 11
|
310
|
+
:available
|
311
|
+
when -2, -3
|
312
|
+
:invalid_zip_code
|
313
|
+
when -33
|
314
|
+
:system_down
|
315
|
+
when -34, -35, 1
|
316
|
+
:incorrect_data
|
317
|
+
when -36, -37, -38
|
318
|
+
:unauthorized
|
319
|
+
when -888, 6, 7, 8, 9, 12
|
320
|
+
:unavailable
|
321
|
+
when 10
|
322
|
+
:partially_available
|
323
|
+
when 99
|
324
|
+
:error
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
def inverse_reverse_shipping_type(type)
|
329
|
+
case type
|
330
|
+
when 'A'
|
331
|
+
:authorization
|
332
|
+
when 'C'
|
333
|
+
:pickup
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
def inverse_tracking_event_status(event)
|
338
|
+
type = event['tipo'] || event[:tipo]
|
339
|
+
status = event['status'] || event[:status]
|
340
|
+
status = status.to_i
|
341
|
+
|
342
|
+
case type
|
343
|
+
when 'BDE', 'BDI', 'BDR'
|
344
|
+
case status
|
345
|
+
when 0, 1
|
346
|
+
:delivered
|
347
|
+
when 2
|
348
|
+
:not_delivered
|
349
|
+
when 4, 5, 6, 8, 10, 21, 22, 26, 33, 36, 40, 42, 48, 49, 56
|
350
|
+
:returning
|
351
|
+
when 7, 19, 25, 32, 38, 41, 45, 46, 47, 53, 57, 66, 69
|
352
|
+
:in_transit
|
353
|
+
when 9, 50, 51, 52
|
354
|
+
:stolen_lost
|
355
|
+
when 3, 12, 24
|
356
|
+
:awaiting_pick_up
|
357
|
+
when 20, 34, 35
|
358
|
+
:not_delivered
|
359
|
+
when 23
|
360
|
+
:returned
|
361
|
+
when 28, 37
|
362
|
+
:damaged
|
363
|
+
when 43
|
364
|
+
:arrested
|
365
|
+
when 54, 55, 58, 59
|
366
|
+
:taxing
|
367
|
+
end
|
368
|
+
when 'BLQ', 'PMT', 'CD', 'CMT', 'TRI', 'CUN', 'RO', 'DO', 'EST', 'PAR'
|
369
|
+
case status
|
370
|
+
when 0, 1, 2, 3, 4, 5, 6, 9, 15, 16, 17, 18
|
371
|
+
:in_transit
|
372
|
+
end
|
373
|
+
when 'FC'
|
374
|
+
case status
|
375
|
+
when 1
|
376
|
+
:returning
|
377
|
+
when 2, 3, 5, 7
|
378
|
+
:in_transit
|
379
|
+
when 4
|
380
|
+
:not_delivered
|
381
|
+
end
|
382
|
+
when 'IDC'
|
383
|
+
case status
|
384
|
+
when 1, 2, 3, 4, 5, 6, 7
|
385
|
+
:stolen_lost
|
386
|
+
end
|
387
|
+
when 'LDI'
|
388
|
+
case status
|
389
|
+
when 0, 1, 2, 3, 14
|
390
|
+
:awaiting_pick_up
|
391
|
+
end
|
392
|
+
when 'OEC', 'LDE'
|
393
|
+
case status
|
394
|
+
when 0, 1, 9
|
395
|
+
:delivering
|
396
|
+
end
|
397
|
+
when 'PO', 'CO'
|
398
|
+
case status
|
399
|
+
when 0, 1, 9
|
400
|
+
:posted
|
401
|
+
end
|
402
|
+
end
|
403
|
+
end
|
404
|
+
end
|