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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/correios_gem.gemspec +29 -0
  3. data/lib/SRO/requests/track_shippings.rb +31 -45
  4. data/lib/{credentials.rb → auxiliars/credentials.rb} +0 -0
  5. data/lib/auxiliars/environments.rb +94 -0
  6. data/lib/auxiliars/exception.rb +5 -0
  7. data/lib/auxiliars/helper.rb +404 -0
  8. data/lib/correios_gem.rb +22 -24
  9. data/lib/pricefier/requests/calculate_deadline.rb +27 -45
  10. data/lib/pricefier/requests/calculate_price.rb +34 -53
  11. data/lib/pricefier/requests/calculate_price_deadline.rb +49 -63
  12. data/lib/pricefier/requests/calculate_price_fac.rb +21 -46
  13. data/lib/pricefier/requests/list_services.rb +26 -42
  14. data/lib/reverse_logistics/requests/calculate_ticket_number_check_digit.rb +10 -21
  15. data/lib/reverse_logistics/requests/cancel_shipping.rb +13 -23
  16. data/lib/reverse_logistics/requests/create_shippings.rb +22 -36
  17. data/lib/reverse_logistics/requests/create_shippings_with_collection.rb +17 -33
  18. data/lib/reverse_logistics/requests/request_ticket_numbers.rb +13 -35
  19. data/lib/reverse_logistics/requests/track_shipping.rb +18 -39
  20. data/lib/reverse_logistics/requests/track_shippings_by_date.rb +19 -45
  21. data/lib/sigep/auxiliars/shipping_xml.rb +100 -0
  22. data/lib/sigep/requests/calculate_label_number_check_digit.rb +13 -27
  23. data/lib/sigep/requests/cancel_shipping.rb +12 -25
  24. data/lib/sigep/requests/check_card_status.rb +11 -27
  25. data/lib/sigep/requests/check_service_availability.rb +12 -39
  26. data/lib/sigep/requests/create_shippings.rb +20 -24
  27. data/lib/sigep/requests/request_label_numbers.rb +11 -17
  28. data/lib/sigep/requests/request_shippings_xml.rb +14 -53
  29. data/lib/sigep/requests/search_available_additional_services.rb +12 -20
  30. data/lib/sigep/requests/search_customer.rb +15 -37
  31. data/lib/sigep/requests/search_zip_code.rb +11 -16
  32. data/lib/sigep/requests/track_shippings.rb +19 -51
  33. metadata +22 -19
  34. data/lib/SRO/client.rb +0 -25
  35. data/lib/SRO/helper.rb +0 -118
  36. data/lib/SRO/requests/track_shippings_list.rb +0 -144
  37. data/lib/correios_exception.rb +0 -11
  38. data/lib/pricefier/client.rb +0 -20
  39. data/lib/pricefier/helper.rb +0 -72
  40. data/lib/pricefier/requests/calculate_deadline_with_date.rb +0 -102
  41. data/lib/pricefier/requests/calculate_deadline_with_restrictions.rb +0 -102
  42. data/lib/pricefier/requests/calculate_price_deadline_with_date.rb +0 -142
  43. data/lib/pricefier/requests/calculate_price_deadline_with_restrictions.rb +0 -142
  44. data/lib/pricefier/requests/calculate_price_with_date.rb +0 -125
  45. data/lib/pricefier/requests/list_services_star.rb +0 -87
  46. data/lib/reverse_logistics/client.rb +0 -34
  47. data/lib/reverse_logistics/helper.rb +0 -95
  48. data/lib/sigep/client.rb +0 -29
  49. data/lib/sigep/helper.rb +0 -234
@@ -1,102 +0,0 @@
1
- require 'savon'
2
- require 'nokogiri'
3
-
4
- require_relative '../client'
5
- require_relative '../helper'
6
- require_relative '../../correios_exception.rb'
7
-
8
- module Correios
9
- module Pricefier
10
- class CalculateDeadlineWithRestrictions < CorreiosException
11
- HELPER = Helper.new
12
- CLIENT = Client.new
13
-
14
- def initialize(data = {})
15
- @show_request = data[:show_request]
16
- @service_codes = data[:service_codes]
17
- @source_zip_code = data[:source_zip_code]
18
- @target_zip_code = data[:target_zip_code]
19
- @reference_date = data[:reference_date]
20
- super()
21
- end
22
-
23
- def request
24
- puts xml if @show_request == true
25
- begin
26
- format_response(CLIENT.client.call(:calc_prazo_restricao,
27
- soap_action: 'http://tempuri.org/CalcPrazoRestricao',
28
- xml: xml).to_hash)
29
- rescue Savon::SOAPFault => error
30
- generate_exception(error)
31
- rescue Savon::HTTPError => error
32
- if error.http.code == 401
33
- generate_exception("Unauthorized (#{error.http.code}).")
34
- end
35
- generate_exception("Unknown HTTP error (#{error.http.code}).")
36
- end
37
- end
38
-
39
- private
40
-
41
- def xml
42
- Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
43
- xml['soap'].Envelope(HELPER.namespaces) do
44
- xml['soap'].Body do
45
- xml['ns1'].CalcPrazoRestricao do
46
- xml.nCdServico HELPER.format_service_codes(@service_codes)
47
- xml.sCepOrigem @source_zip_code
48
- xml.sCepDestino @target_zip_code
49
- xml.sDtCalculo HELPER.convert_date_to_string(@reference_date)
50
- end
51
- end
52
- end
53
- end.doc.root.to_xml
54
- end
55
-
56
- def format_response(response)
57
- response = response[:calc_prazo_restricao_response][:calc_prazo_restricao_result]
58
-
59
- services = response[:servicos][:c_servico]
60
- services = [services] if services.is_a?(Hash)
61
-
62
- formatted_services = []
63
- services.each do |service|
64
- formatted_services << format_service(service)
65
- end
66
-
67
- {
68
- services: formatted_services
69
- }
70
- end
71
-
72
- def format_service(service)
73
- if [0, 10, 11].include?(service[:erro].to_i)
74
- {
75
- code: service[:codigo],
76
- delivery_at_home: HELPER.convert_string_to_bool(
77
- service[:entrega_domiciliar]
78
- ),
79
- delivery_on_saturdays: HELPER.convert_string_to_bool(
80
- service[:entrega_sabado]
81
- ),
82
- note: service[:obs_fim],
83
- deadline: {
84
- days: service[:prazo_entrega].to_i,
85
- date: HELPER.convert_string_to_date(
86
- service[:data_max_entrega]
87
- ),
88
- }
89
- }
90
- else
91
- {
92
- code: service[:codigo],
93
- error: {
94
- code: service[:erro],
95
- description: service[:msg_erro]
96
- }
97
- }
98
- end
99
- end
100
- end
101
- end
102
- end
@@ -1,142 +0,0 @@
1
- require 'savon'
2
- require 'nokogiri'
3
-
4
- require_relative '../client'
5
- require_relative '../helper'
6
- require_relative '../../correios_exception.rb'
7
-
8
- module Correios
9
- module Pricefier
10
- class CalculatePriceDeadlineWithDate < CorreiosException
11
- HELPER = Helper.new
12
- CLIENT = Client.new
13
-
14
- def initialize(data = {})
15
- @credentials = Correios.credentials
16
-
17
- @show_request = data[:show_request]
18
- @service_codes = data[:service_codes]
19
- @source_zip_code = data[:source_zip_code]
20
- @target_zip_code = data[:target_zip_code]
21
- @object = data[:object]
22
- @own_hands = data[:own_hands]
23
- @receipt_notification = data[:receipt_notification]
24
- @declared_value = data[:declared_value]
25
- @reference_date = data[:reference_date]
26
- super()
27
- end
28
-
29
- def request
30
- puts xml if @show_request == true
31
- begin
32
- format_response(CLIENT.client.call(:calc_preco,
33
- soap_action: 'http://tempuri.org/CalcPrecoPrazoData',
34
- xml: xml).to_hash)
35
- rescue Savon::SOAPFault => error
36
- generate_exception(error)
37
- rescue Savon::HTTPError => error
38
- if error.http.code == 401
39
- generate_exception("Unauthorized (#{error.http.code}).")
40
- end
41
- generate_exception("Unknown HTTP error (#{error.http.code}).")
42
- end
43
- end
44
-
45
- private
46
-
47
- def xml
48
- Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
49
- xml['soap'].Envelope(HELPER.namespaces) do
50
- xml['soap'].Body do
51
- xml['ns1'].CalcPrecoPrazoData do
52
- xml.nCdEmpresa @credentials.administrative_code
53
- xml.sDsSenha @credentials.sigep_password
54
- xml.nCdServico HELPER.format_service_codes(@service_codes)
55
- xml.sCepOrigem @source_zip_code
56
- xml.sCepDestino @target_zip_code
57
- xml.nCdFormato HELPER.object_type(@object[:type])
58
- xml.nVlPeso @object[:weight].to_f/1000
59
- xml.nVlComprimento @object[:length] || 0
60
- xml.nVlAltura @object[:height] || 0
61
- xml.nVlLargura @object[:width] || 0
62
- xml.nVlDiametro @object[:diameter] || 0
63
- xml.sCdMaoPropria HELPER.convert_bool_to_string(@own_hands)
64
- xml.sCdAvisoRecebimento HELPER.convert_bool_to_string(
65
- @receipt_notification
66
- )
67
- xml.nVlValorDeclarado @declared_value || 0
68
- xml.sDtCalculo HELPER.convert_date_to_string(@reference_date)
69
- end
70
- end
71
- end
72
- end.doc.root.to_xml
73
- end
74
-
75
- def format_response(response)
76
- response = response[:calc_preco_prazo_data_response][:calc_preco_prazo_data_result]
77
-
78
- services = response[:servicos][:c_servico]
79
- services = [services] if services.is_a?(Hash)
80
-
81
- formatted_services = []
82
- services.each do |service|
83
- formatted_services << format_service(service)
84
- end
85
-
86
- {
87
- services: formatted_services
88
- }
89
- end
90
-
91
- def format_service(service)
92
- if [0, 10, 11].include?(service[:erro].to_i)
93
- delivery_on_saturdays = HELPER.convert_string_to_bool(
94
- service[:entrega_sabado]
95
- )
96
-
97
- {
98
- code: service[:codigo],
99
- prices: {
100
- additional_serivces: {
101
- own_hands: HELPER.convert_string_to_float(
102
- service[:valor_mao_propria]
103
- ),
104
- receipt_notification: HELPER.convert_string_to_float(
105
- service[:valor_aviso_recebimento]
106
- ),
107
- declared_value: HELPER.convert_string_to_float(
108
- service[:valor_valor_declarado]
109
- )
110
- },
111
- only_shipping: HELPER.convert_string_to_float(
112
- service[:valor_sem_adicionais]
113
- ),
114
- total: HELPER.convert_string_to_float(service[:valor])
115
- },
116
- delivery_at_home: HELPER.convert_string_to_bool(
117
- service[:entrega_domiciliar]
118
- ),
119
- delivery_on_saturdays: delivery_on_saturdays,
120
- deadline: {
121
- days: service[:prazo_entrega].to_i,
122
- date: HELPER.calculate_deadline_date(
123
- service[:prazo_entrega].to_i,
124
- delivery_on_saturdays,
125
- @reference_date
126
- )
127
- },
128
- note: service[:obs_fim]
129
- }
130
- else
131
- {
132
- code: service[:codigo],
133
- error: {
134
- code: service[:erro],
135
- description: service[:msg_erro]
136
- }
137
- }
138
- end
139
- end
140
- end
141
- end
142
- end
@@ -1,142 +0,0 @@
1
- require 'savon'
2
- require 'nokogiri'
3
-
4
- require_relative '../client'
5
- require_relative '../helper'
6
- require_relative '../../correios_exception.rb'
7
-
8
- module Correios
9
- module Pricefier
10
- class CalculatePriceDeadlineWithRestrictions < CorreiosException
11
- HELPER = Helper.new
12
- CLIENT = Client.new
13
-
14
- def initialize(data = {})
15
- @credentials = Correios.credentials
16
-
17
- @show_request = data[:show_request]
18
- @service_codes = data[:service_codes]
19
- @source_zip_code = data[:source_zip_code]
20
- @target_zip_code = data[:target_zip_code]
21
- @object = data[:object]
22
- @own_hands = data[:own_hands]
23
- @receipt_notification = data[:receipt_notification]
24
- @declared_value = data[:declared_value]
25
- @reference_date = data[:reference_date]
26
- super()
27
- end
28
-
29
- def request
30
- puts xml if @show_request == true
31
- begin
32
- format_response(CLIENT.client.call(:calc_preco,
33
- soap_action: 'http://tempuri.org/CalcPrecoPrazoRestricao',
34
- xml: xml).to_hash)
35
- rescue Savon::SOAPFault => error
36
- generate_exception(error)
37
- rescue Savon::HTTPError => error
38
- if error.http.code == 401
39
- generate_exception("Unauthorized (#{error.http.code}).")
40
- end
41
- generate_exception("Unknown HTTP error (#{error.http.code}).")
42
- end
43
- end
44
-
45
- private
46
-
47
- def xml
48
- Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
49
- xml['soap'].Envelope(HELPER.namespaces) do
50
- xml['soap'].Body do
51
- xml['ns1'].CalcPrecoPrazoRestricao do
52
- xml.nCdEmpresa @credentials.administrative_code
53
- xml.sDsSenha @credentials.sigep_password
54
- xml.nCdServico HELPER.format_service_codes(@service_codes)
55
- xml.sCepOrigem @source_zip_code
56
- xml.sCepDestino @target_zip_code
57
- xml.nCdFormato HELPER.object_type(@object[:type])
58
- xml.nVlPeso @object[:weight].to_f/1000
59
- xml.nVlComprimento @object[:length] || 0
60
- xml.nVlAltura @object[:height] || 0
61
- xml.nVlLargura @object[:width] || 0
62
- xml.nVlDiametro @object[:diameter] || 0
63
- xml.sCdMaoPropria HELPER.convert_bool_to_string(@own_hands)
64
- xml.sCdAvisoRecebimento HELPER.convert_bool_to_string(
65
- @receipt_notification
66
- )
67
- xml.nVlValorDeclarado @declared_value || 0
68
- xml.sDtCalculo HELPER.convert_date_to_string(@reference_date)
69
- end
70
- end
71
- end
72
- end.doc.root.to_xml
73
- end
74
-
75
- def format_response(response)
76
- response = response[:calc_preco_prazo_restricao_response][:calc_preco_prazo_restricao_result]
77
-
78
- services = response[:servicos][:c_servico]
79
- services = [services] if services.is_a?(Hash)
80
-
81
- formatted_services = []
82
- services.each do |service|
83
- formatted_services << format_service(service)
84
- end
85
-
86
- {
87
- services: formatted_services
88
- }
89
- end
90
-
91
- def format_service(service)
92
- if [0, 10, 11].include?(service[:erro].to_i)
93
- delivery_on_saturdays = HELPER.convert_string_to_bool(
94
- service[:entrega_sabado]
95
- )
96
-
97
- {
98
- code: service[:codigo],
99
- prices: {
100
- additional_serivces: {
101
- own_hands: HELPER.convert_string_to_float(
102
- service[:valor_mao_propria]
103
- ),
104
- receipt_notification: HELPER.convert_string_to_float(
105
- service[:valor_aviso_recebimento]
106
- ),
107
- declared_value: HELPER.convert_string_to_float(
108
- service[:valor_valor_declarado]
109
- )
110
- },
111
- only_shipping: HELPER.convert_string_to_float(
112
- service[:valor_sem_adicionais]
113
- ),
114
- total: HELPER.convert_string_to_float(service[:valor])
115
- },
116
- delivery_at_home: HELPER.convert_string_to_bool(
117
- service[:entrega_domiciliar]
118
- ),
119
- delivery_on_saturdays: delivery_on_saturdays,
120
- deadline: {
121
- days: service[:prazo_entrega].to_i,
122
- date: HELPER.calculate_deadline_date(
123
- service[:prazo_entrega].to_i,
124
- delivery_on_saturdays,
125
- @reference_date
126
- )
127
- },
128
- note: service[:obs_fim]
129
- }
130
- else
131
- {
132
- code: service[:codigo],
133
- error: {
134
- code: service[:erro],
135
- description: service[:msg_erro]
136
- }
137
- }
138
- end
139
- end
140
- end
141
- end
142
- end
@@ -1,125 +0,0 @@
1
- require 'savon'
2
- require 'nokogiri'
3
-
4
- require_relative '../client'
5
- require_relative '../helper'
6
- require_relative '../../correios_exception.rb'
7
-
8
- module Correios
9
- module Pricefier
10
- class CalculatePriceWithDate < CorreiosException
11
- HELPER = Helper.new
12
- CLIENT = Client.new
13
-
14
- def initialize(data = {})
15
- @credentials = Correios.credentials
16
-
17
- @show_request = data[:show_request]
18
- @service_codes = data[:service_codes]
19
- @source_zip_code = data[:source_zip_code]
20
- @target_zip_code = data[:target_zip_code]
21
- @object = data[:object]
22
- @own_hands = data[:own_hands]
23
- @receipt_notification = data[:receipt_notification]
24
- @declared_value = data[:declared_value]
25
- @reference_date = data[:reference_date]
26
- super()
27
- end
28
-
29
- def request
30
- puts xml if @show_request == true
31
- begin
32
- format_response(CLIENT.client.call(:calc_preco_data,
33
- soap_action: 'http://tempuri.org/CalcPrecoData',
34
- xml: xml).to_hash)
35
- rescue Savon::SOAPFault => error
36
- generate_exception(error)
37
- rescue Savon::HTTPError => error
38
- if error.http.code == 401
39
- generate_exception("Unauthorized (#{error.http.code}).")
40
- end
41
- generate_exception("Unknown HTTP error (#{error.http.code}).")
42
- end
43
- end
44
-
45
- private
46
-
47
- def xml
48
- Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
49
- xml['soap'].Envelope(HELPER.namespaces) do
50
- xml['soap'].Body do
51
- xml['ns1'].CalcPrecoData do
52
- xml.nCdEmpresa @credentials.administrative_code
53
- xml.sDsSenha @credentials.sigep_password
54
- xml.nCdServico HELPER.format_service_codes(@service_codes)
55
- xml.sCepOrigem @source_zip_code
56
- xml.sCepDestino @target_zip_code
57
- xml.nCdFormato HELPER.object_type(@object[:type])
58
- xml.nVlPeso @object[:weight].to_f/1000
59
- xml.nVlComprimento @object[:length] || 0
60
- xml.nVlAltura @object[:height] || 0
61
- xml.nVlLargura @object[:width] || 0
62
- xml.nVlDiametro @object[:diameter] || 0
63
- xml.sCdMaoPropria HELPER.convert_bool_to_string(@own_hands)
64
- xml.sCdAvisoRecebimento HELPER.convert_bool_to_string(
65
- @receipt_notification
66
- )
67
- xml.nVlValorDeclarado @declared_value || 0
68
- xml.sDtCalculo HELPER.convert_date_to_string(@reference_date)
69
- end
70
- end
71
- end
72
- end.doc.root.to_xml
73
- end
74
-
75
- def format_response(response)
76
- response = response[:calc_preco_data_response][:calc_preco_data_result]
77
-
78
- services = response[:servicos][:c_servico]
79
- services = [services] if services.is_a?(Hash)
80
-
81
- formatted_services = []
82
- services.each do |service|
83
- formatted_services << format_service(service)
84
- end
85
-
86
- {
87
- services: formatted_services
88
- }
89
- end
90
-
91
- def format_service(service)
92
- if [0, 10, 11].include?(service[:erro].to_i)
93
- {
94
- code: service[:codigo],
95
- prices: {
96
- additional_serivces: {
97
- own_hands: HELPER.convert_string_to_float(
98
- service[:valor_mao_propria]
99
- ),
100
- receipt_notification: HELPER.convert_string_to_float(
101
- service[:valor_aviso_recebimento]
102
- ),
103
- declared_value: HELPER.convert_string_to_float(
104
- service[:valor_valor_declarado]
105
- ),
106
- },
107
- only_shipping: HELPER.convert_string_to_float(
108
- service[:valor_sem_adicionais]
109
- ),
110
- total: HELPER.convert_string_to_float(service[:valor])
111
- }
112
- }
113
- else
114
- {
115
- code: service[:codigo],
116
- error: {
117
- code: service[:erro],
118
- description: service[:msg_erro]
119
- }
120
- }
121
- end
122
- end
123
- end
124
- end
125
- end