ship 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/correios.rb +29 -0
- data/lib/ship.rb +1 -0
- data/lib/shipping.rb +1 -1
- 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
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
|