Class: Correios::Sigep::Helper
- Inherits:
-
Object
- Object
- Correios::Sigep::Helper
- Defined in:
- lib/sigep/helper.rb
Instance Method Summary collapse
- #convert_string_to_bool(string) ⇒ Object
- #convert_string_to_date(date, time) ⇒ Object
- #convert_string_to_decimal(string) ⇒ Object
- #label_without_digit_checker(label_number) ⇒ Object
- #namespaces ⇒ Object
- #shippings_xml(data) ⇒ Object
- #tracking_event_status(event) ⇒ Object
Instance Method Details
#convert_string_to_bool(string) ⇒ Object
114 115 116 |
# File 'lib/sigep/helper.rb', line 114 def convert_string_to_bool(string) string.strip == 'S' end |
#convert_string_to_date(date, time) ⇒ Object
118 119 120 |
# File 'lib/sigep/helper.rb', line 118 def convert_string_to_date(date, time) DateTime.strptime("#{date} #{time}", '%d/%m/%Y %H:%M') end |
#convert_string_to_decimal(string) ⇒ Object
122 123 124 125 126 |
# File 'lib/sigep/helper.rb', line 122 def convert_string_to_decimal(string) return nil if string.nil? string.tr(',', '.').to_f end |
#label_without_digit_checker(label_number) ⇒ Object
109 110 111 112 |
# File 'lib/sigep/helper.rb', line 109 def label_without_digit_checker(label_number) label_number.slice!(10) label_number end |
#namespaces ⇒ Object
6 7 8 9 10 11 |
# File 'lib/sigep/helper.rb', line 6 def namespaces { 'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/', 'xmlns:ns1' => 'http://cliente.bean.master.sigep.bsb.correios.com.br/' } end |
#shippings_xml(data) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/sigep/helper.rb', line 13 def shippings_xml(data) credentials = Correios.credentials sender = data[:sender] sender_address = sender[:address] shippings = data[:shippings] Nokogiri::XML::Builder.new(encoding: 'ISO-8859-1') do |xml| xml.correioslog do xml.tipo_arquivo 'Postagem' xml.versao_arquivo '2.3' xml.plp do xml.id_plp xml.valor_global xml.mcu_unidade_postagem xml.nome_unidade_postagem xml.cartao_postagem credentials.card end xml.remetente do xml.numero_contrato credentials.contract xml.numero_diretoria sender[:board_id] xml.codigo_administrativo credentials.administrative_code xml.nome_remetente sender[:name] xml.logradouro_remetente sender_address[:street] xml.numero_remetente sender_address[:number] xml.complemento_remetente sender_address[:additional] xml.bairro_remetente sender_address[:neighborhood] xml.cep_remetente sender_address[:zip_code] xml.cidade_remetente sender_address[:city] xml.uf_remetente sender_address[:state] xml.telefone_remetente sender[:phone] xml.fax_remetente sender[:fax] xml.email_remetente sender[:email] end xml.forma_pagamento payment_method(data[:payment_method]) shippings.each do |shipping| receiver = shipping[:receiver] receiver_address = receiver[:address] object = shipping[:object] invoice = shipping[:invoice] || {} additional_services = shipping[:additional_services] || [] notes = shipping[:notes] || [] xml.objeto_postal do xml.numero_etiqueta shipping[:label_number] xml.codigo_objeto_cliente shipping[:code] xml.codigo_servico_postagem shipping[:service_code] xml.cubagem 0 xml.peso object[:weight] xml.rt1 notes[0] xml.rt2 notes[1] xml.destinatario do xml.nome_destinatario receiver[:name] xml.telefone_destinatario receiver[:phone] xml.celular_destinatario receiver[:cellphone] xml.email_destinatario receiver[:email] xml.logradouro_destinatario receiver_address[:street] xml.complemento_destinatario receiver_address[:additional] xml.numero_end_destinatario receiver_address[:number] end xml.nacional do xml.bairro_destinatario receiver_address[:neighborhood] xml.cidade_destinatario receiver_address[:city] xml.uf_destinatario receiver_address[:state] xml.cep_destinatario receiver_address[:zip_code] xml.codigo_usuario_postal xml.centro_custo_cliente shipping[:cost_center] xml.numero_nota_fiscal invoice[:number] xml.serie_nota_fiscal invoice[:serie] xml.valor_nota_fiscal invoice[:value] xml.natureza_nota_fiscal invoice[:kind] xml.descricao_objeto shipping[:description] xml.valor_a_cobrar shipping[:additional_value] end xml.servico_adicional do additional_services.each do |additional_service| xml.codigo_servico_adicional additional_service end xml.valor_declarado shipping[:declared_value] end xml.dimensao_objeto do xml.tipo_objeto object_type(object[:type]) xml.dimensao_altura object[:height] || 0 xml.dimensao_largura object[:width] || 0 xml.dimensao_comprimento object[:length] || 0 xml.dimensao_diametro object[:diameter] || 0 end xml.data_postagem_sara xml.status_processamento 0 xml.numero_comprovante_postagem xml.valor_cobrado end end end end.to_xml.encode(Encoding::UTF_8) end |
#tracking_event_status(event) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/sigep/helper.rb', line 128 def tracking_event_status(event) type = event['tipo'] status = event['status'].to_i case type when 'BDE', 'BDI', 'BDR' case status when 0, 1 return :delivered when 2 return :not_delivered when 4, 5, 6, 8, 10, 21, 22, 26, 33, 36, 40, 42, 48, 49, 56 return :returning when 7, 19, 25, 32, 38, 41, 45, 46, 47, 53, 57, 66, 69 return :in_transit when 9, 50, 51, 52 return :stolen_lost when 3, 12, 24 return :awaiting_pick_up when 20, 34, 35 return :not_delivered when 23 return :returned when 28, 37 return :damaged when 43 return :arrested when 54, 55, 58, 59 return :taxing end when 'BLQ', 'PMT', 'CD', 'CMT', 'TRI', 'CUN', 'RO', 'DO', 'EST', 'PAR' case status when 0, 1, 2, 3, 4, 5, 6, 9, 15, 16, 17, 18 return :in_transit end when 'FC' case status when 1 return :returning when 2, 3, 5, 7 return :in_transit when 4 return :not_delivered end when 'IDC' case status when 1, 2, 3, 4, 5, 6, 7 return :stolen_lost end when 'LDI' case status when 0, 1, 2, 3, 14 return :awaiting_pick_up end when 'OEC', 'LDE' case status when 0, 1, 9 return :delivering end when 'PO', 'CO' case status when 0, 1, 9 return :posted end end end |