ship 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/lib/correios.rb +29 -0
  2. data/lib/ship.rb +1 -0
  3. data/lib/shipping.rb +1 -1
  4. metadata +2 -2
data/lib/correios.rb CHANGED
@@ -70,6 +70,35 @@ module Ship
70
70
  return rtn
71
71
  end
72
72
 
73
+ def where(shipping)
74
+ raise Exception.new("No shipping info") if shipping.nil? || shipping.id.nil?
75
+ parms = {
76
+ "p_itemcode" => "",
77
+ "p_lingua" => "001",
78
+ "p_teste=" => "",
79
+ "p_tipo" => "003",
80
+ "z_action" => "",
81
+ "p_cod_lis" => shipping.id
82
+ }
83
+ url = "http://websro.correios.com.br/sro_bin/txect01$.inexistente?"+parms.map {|k,v| "#{k}=#{v}"}.join("&")
84
+ data = Net::HTTP.get(URI.parse(url))
85
+ raise Exception.new("Could not get an answer from URL") if data.size<1
86
+ rst = []
87
+ rows = data.gsub("\n","").split(/<[\/]?tr>/).select {|r| r =~ /^<td/}
88
+ rows.shift # discard
89
+ ldate, ldesc, lstatus = nil, nil, nil
90
+ rows.each do |row|
91
+ date, desc, status = row.scan(/(>)([^<]+)(<)/).flatten.reject {|i| i =~ />|</}
92
+ if !desc.nil?
93
+ ldate, ldesc, lstatus = date, desc, status
94
+ else
95
+ desc, date, status = date, ldate, lstatus
96
+ end
97
+ rst << {:date=>date.strip,:desc=>desc.strip,:status=>status.strip}
98
+ end
99
+ rst.reverse
100
+ end
101
+
73
102
  def self.countries
74
103
  [Country.new("Brasil","BRA")]
75
104
  end
data/lib/ship.rb CHANGED
@@ -18,6 +18,7 @@ module Ship
18
18
  end
19
19
 
20
20
  def self.where(provider,shipping)
21
+ provider.where(shipping)
21
22
  end
22
23
  end
23
24
  end
data/lib/shipping.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Ship
2
2
  class Shipping
3
3
  attr_accessor :from, :to, :weight, :width, :height, :length, :diameter, :user,
4
- :password, :service, :format, :in_hands, :value, :return_receipt, :date
4
+ :password, :service, :format, :in_hands, :value, :return_receipt, :date, :id
5
5
  def method_missing(name,*args)
6
6
  ""
7
7
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Eustaquio Rangel