Module: DJI::DHL

Defined in:
lib/dji/dhl.rb,
lib/dji/dhl/shipment.rb,
lib/dji/dhl/checkpoint.rb,
lib/dji/dhl/tracking_results.rb

Defined Under Namespace

Classes: Checkpoint, Shipment, TrackingResults

Class Method Summary collapse

Class Method Details



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/dji/dhl.rb', line 87

def print_tracking_details(data)
    now = Time.now.to_s

    puts
    puts "ORDER TRACKING AS OF #{now}"
    puts "------------------------------------------------------"
    puts "Order Number     : #{data[:order_number]}"
    puts "Total            : #{data[:total]}"
    puts "Payment Status   : #{data[:payment_status]}"
    puts "Shipping Status  : #{data[:shipping_status]}"
    puts "Shipping Company : #{data[:shipping_company]}"
    puts "Tracking Number  : #{data[:tracking_number]}"
    puts
end


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/dji/dhl.rb', line 62

def print_tracking_response(data)
  now = Time.now.to_s

  puts
  puts "DHL Tracking for Airway Bill: #{data[:waybill]}"
  puts "-------------------------------------------------------------------------------------------------------"
  puts

  data[:track_packages_response].packages.each_with_index do |package, index|
    puts "PACKAGE #{index+1}"
    puts
    puts "Origin       : #{package.origin}"
    puts "Destination  : #{package.destination}"
    puts "Tendered     : #{package.tendered_date}"
    puts "Picked Up    : #{package.pickup_date}"
    puts "Shipped      : #{package.ship_date}"
    puts "Est. Deliver : #{package.estimated_delivery_date}" if package.estimated_delivery_date.present?
    puts "Delivered    : #{package.delivery_date}" if package.delivery_date.present?
    puts "Dimensions   : #{package.dimensions}"
    puts "Total Weight : #{package.total_weight[:pounds]} lbs (#{package.total_weight[:kilograms]} kgs)"
    puts "Status       : #{package.key_status}"
    puts
  end
end

.track(waybill) ⇒ Object

Get the tracking details for a waybill



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dji/dhl.rb', line 15

def track(waybill)
  uri = URI.parse(tracking_url_json)
  params = {
    'AWB' => waybill,
    'languageCode' => 'en'
  }
  uri.query = URI.encode_www_form(params)

  headers = {
    'Origin' => 'http://www.dhl.com/',
    'Referer' => tracking_url_json
  }

  http = Net::HTTP.new(uri.host, uri.port)
  res = http.get(uri.request_uri, headers)

  case res
  when Net::HTTPSuccess, Net::HTTPRedirection
    #puts res.body

    results = JSON.parse(res.body)['results']
    tr = DJI::DHL::TrackingResults.new_from_results(results)

    # data = { country_code: country_code, postal_code: postal_code }
    # if tpr.present?
    #   data[:track_packages_response] = tpr
    #   print_track_packages_response(data)
    # else
    #   puts response
    #   puts "Nothing parsed!"
    # end
    
    # print_tracking_details(data)
  else
    puts res.inspect
    res.error!
  end

end

.tracking_url_jsonObject

OK puts res.body



58
59
60
# File 'lib/dji/dhl.rb', line 58

def tracking_url_json
  'http://www.dhl.com/shipmentTracking'
end