Class: Corrails::Correios

Inherits:
Object
  • Object
show all
Defined in:
lib/corrails/correios.rb

Instance Method Summary collapse

Instance Method Details

#rastrear(id_objeto) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/corrails/correios.rb', line 6

def rastrear(id_objeto)
  uri = URI.parse("http://websro.correios.com.br/sro_bin/txect01$.QueryList");

  params = {
    'P_LINGUA' => '001',
    'P_TIPO' => '001',
    'P_COD_UNI' => id_objeto
  }

  http = Net::HTTP.new(uri.host, uri.port)
  request = Net::HTTP::Get.new(uri.path)
  request.set_form_data( params )
  request = Net::HTTP::Get.new( uri.path+ '?' + request.body )
  response = http.request(request)
  Parser::CorreiosParser.parse(response.body)
end