class ANLExpress::ANLExpress

Attributes

code[R]
domain[R]
path[R]

Public Class Methods

new() click to toggle source
# File lib/anlexpress/carrier.rb, line 11
def initialize 
  @domain = 'www.anlexpress.com'
  @path = "/chaxun.php"
  @code = 'ANL'
end

Public Instance Methods

create_statues(*track_numbers) click to toggle source
# File lib/anlexpress/carrier.rb, line 17
def create_statues *track_numbers
  parse_status(package_status(track_numbers))
end

Private Instance Methods

package_status(*track_numbers) click to toggle source
# File lib/anlexpress/carrier.rb, line 23
def package_status *track_numbers
  Net::HTTP.new(@domain, nil, PROXY_ADDR, PROXY_PORT).start { |http|
    res = http.post(@path, "zi=#{track_numbers.join(',')}")
    return res.body
  }
end
parse_status(html) click to toggle source
# File lib/anlexpress/carrier.rb, line 30
def parse_status html
  doc = Nokogiri::HTML(html)
  trackings = []
  doc.css('td.zi14 > span.zi1452').each do |something|
    tra = TrackingStatus.new(something.text)
    something.parent.parent.parent.css('td.zi12-66').each do |more|
      dt = more.children[0].text.gsub("\u00A0", "").strip
      note = more.children[1].text.gsub("\u00A0", "").strip
      tra.add_status(DateTime.strptime(dt, '%Y-%m-%d %H:%M:%S'), note)
    end
    tra.carrier = self
    trackings.push(tra)
  end
  trackings
end