chilexpress_rails 0.0.4 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chilexpress_rails.rb +5 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7b97f99ed148abd9cf6b8dba52c279a78569e01
|
4
|
+
data.tar.gz: b53c218582a94c30ca05301bb06dad35feba1b5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ea661da19b527c0395316a19dcd060cc93d169c335d83b0e399a2b0e13c977d0154bc6169db4341c1426cbfdeaeb80b75ded69cd3950ad6f08ffec01f2f5c45
|
7
|
+
data.tar.gz: 298d5c737162a77bb30f0a5fe8e5fa64752465e97f6c81aa38b5132d57e98456069e81416203a035b52149816b0f56a6f8708cc6186c7b26d7242a00ee378dcf
|
data/lib/chilexpress_rails.rb
CHANGED
@@ -7,16 +7,15 @@ module ChilexpressRails
|
|
7
7
|
def self.search_order(tracking_number)
|
8
8
|
url = "http://www.chilexpress.cl/Views/ChilexpressCL/Resultado-busqueda.aspx?DATA=#{tracking_number}"
|
9
9
|
doc = Nokogiri::HTML(open(url))
|
10
|
-
return
|
10
|
+
return "The order doesn't exist" if doc.css('.section-title')[0].text.include?('No hemos encontrado')
|
11
11
|
attributes = shipping_info(doc).merge!(receiver_info(doc))
|
12
12
|
Order.new(attributes)
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.shipping_info(html_doc)
|
16
|
-
puts html_doc.at_css('title').text
|
17
16
|
widget_content = html_doc.css('.wigdet-content')
|
18
17
|
li = widget_content[0].css('li')
|
19
|
-
return '
|
18
|
+
return "Website's structure has change" unless li
|
20
19
|
{
|
21
20
|
track_number: li[1].text.to_s.split(':')[1].strip.gsub(/\A\p{Space}*/, ''),
|
22
21
|
product: li[2].text.to_s.split(':')[1].strip.gsub(/\A\p{Space}*/, ''),
|
@@ -24,13 +23,13 @@ module ChilexpressRails
|
|
24
23
|
status: li[4].text.to_s.split(':')[1].strip.gsub(/\A\p{Space}*/, '')
|
25
24
|
}
|
26
25
|
rescue
|
27
|
-
'
|
26
|
+
"Website's structure has change"
|
28
27
|
end
|
29
28
|
|
30
29
|
def self.receiver_info(html_doc)
|
31
30
|
widget_content = html_doc.css('.wigdet-content')
|
32
31
|
li = widget_content[1].css('li')
|
33
|
-
return '
|
32
|
+
return "Website's structure has change" unless li
|
34
33
|
date = li[2].text.to_s.split(':')[1].strip.gsub(/\A\p{Space}*/, '')
|
35
34
|
hour = " #{li[3].text.to_s.split(':')[1].strip.gsub(/\A\p{Space}*/, '')}:#{li[3].text.to_s.split(':')[2].strip.gsub(/\A\p{Space}*/, '')}"
|
36
35
|
{
|
@@ -39,6 +38,6 @@ module ChilexpressRails
|
|
39
38
|
receiver_name: li[4].text.to_s.split(':')[1].split(' ').first(2).join(' ').gsub(/\A\p{Space}*/, '')
|
40
39
|
}
|
41
40
|
rescue
|
42
|
-
'
|
41
|
+
"Website's structure has change"
|
43
42
|
end
|
44
43
|
end
|