dji 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ea334a81926d812f389b361107c36a3f8410ef4
4
- data.tar.gz: 3f4ea4d8e6cec8807105a69d16c55f7924f88e1e
3
+ metadata.gz: 89bee1947fd5fb1fd18d6ff55bc7df1a3ab40221
4
+ data.tar.gz: a764b6f12a17fea87e8cab0f55ec3bbf8479d3a5
5
5
  SHA512:
6
- metadata.gz: 36a63f2eeb4e53feb7e48172461d586e3c480c84f7bf6eeb1d240c0cec2af57b2061f819777f071b11b8d5258b880d7732e6df4ceacd7edbede434796b12e32a
7
- data.tar.gz: f4d2a5cf9da4ea195f2f71d6117f8dac6d8fed829509158f8a10807a829719eb76e03831690945f99043a17c488caea8492cc81965396e76102dc492095acd93
6
+ metadata.gz: 9b7ebbf6aa341c2c271609ec34bb547f144a3b1a192e9fd6f0e768974f2bccd7c3891a3d0277e2870c211300760e237907dd21465cda69d8edeecd3b68bd90ed
7
+ data.tar.gz: c573eda472a8b359c21321685eb57a2fe4e5c2d35875de4047d079af28c5cb2336d2c8d02dbd91e20bd8438bc28ddf36b8001f48e77757b23870917b3886cc25
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # DJI
2
2
 
3
+ CLI and Ruby tools for drone-maker DJI's store, account, order status and more.
3
4
 
4
5
 
5
6
  ## Installation
data/lib/dji.rb CHANGED
@@ -11,6 +11,7 @@ require 'dji/version'
11
11
  module DJI
12
12
  extend ActiveSupport::Autoload
13
13
 
14
+ autoload :DHL
14
15
  autoload :Fedex
15
16
  autoload :OrderTracking
16
17
  end
File without changes
data/lib/dji/dhl.rb ADDED
@@ -0,0 +1,108 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'uri'
4
+
5
+ require 'nokogiri'
6
+
7
+ require 'dji/dhl/tracking_results'
8
+
9
+ module DJI
10
+ module DHL
11
+
12
+ class << self
13
+
14
+ # Get the tracking details for a waybill
15
+ def track(waybill)
16
+ uri = URI.parse(tracking_url_json)
17
+ params = {
18
+ 'AWB' => waybill,
19
+ 'languageCode' => 'en'
20
+ }
21
+ uri.query = URI.encode_www_form(params)
22
+
23
+ headers = {
24
+ 'Origin' => 'http://www.dhl.com/',
25
+ 'Referer' => tracking_url_json
26
+ }
27
+
28
+ http = Net::HTTP.new(uri.host, uri.port)
29
+ res = http.get(uri.request_uri, headers)
30
+
31
+ case res
32
+ when Net::HTTPSuccess, Net::HTTPRedirection
33
+ puts res.body
34
+
35
+ results = JSON.parse(res.body)['results']
36
+ tr = DJI::DHL::TrackingResults.new_from_results(results)
37
+
38
+ # data = { country_code: country_code, postal_code: postal_code }
39
+ # if tpr.present?
40
+ # data[:track_packages_response] = tpr
41
+ # print_track_packages_response(data)
42
+ # else
43
+ # puts response
44
+ # puts "Nothing parsed!"
45
+ # end
46
+
47
+ # print_tracking_details(data)
48
+ else
49
+ puts res.inspect
50
+ res.error!
51
+ end
52
+
53
+ end
54
+
55
+ # OK
56
+ # puts res.body
57
+
58
+ def tracking_url_json
59
+ 'http://www.dhl.com/shipmentTracking'
60
+ end
61
+
62
+ def print_tracking_response(data)
63
+ now = Time.now.to_s
64
+
65
+ puts
66
+ puts "DHL Tracking for Airway Bill: #{data[:waybill]}"
67
+ puts "-------------------------------------------------------------------------------------------------------"
68
+ puts
69
+
70
+ data[:track_packages_response].packages.each_with_index do |package, index|
71
+ puts "PACKAGE #{index+1}"
72
+ puts
73
+ puts "Origin : #{package.origin}"
74
+ puts "Destination : #{package.destination}"
75
+ puts "Tendered : #{package.tendered_date}"
76
+ puts "Picked Up : #{package.pickup_date}"
77
+ puts "Shipped : #{package.ship_date}"
78
+ puts "Est. Deliver : #{package.estimated_delivery_date}" if package.estimated_delivery_date.present?
79
+ puts "Delivered : #{package.delivery_date}" if package.delivery_date.present?
80
+ puts "Dimensions : #{package.dimensions}"
81
+ puts "Total Weight : #{package.total_weight[:pounds]} lbs (#{package.total_weight[:kilograms]} kgs)"
82
+ puts "Status : #{package.key_status}"
83
+ puts
84
+ end
85
+ end
86
+
87
+ def print_tracking_details(data)
88
+ now = Time.now.to_s
89
+
90
+ puts
91
+ puts "ORDER TRACKING AS OF #{now}"
92
+ puts "------------------------------------------------------"
93
+ puts "Order Number : #{data[:order_number]}"
94
+ puts "Total : #{data[:total]}"
95
+ puts "Payment Status : #{data[:payment_status]}"
96
+ puts "Shipping Status : #{data[:shipping_status]}"
97
+ puts "Shipping Company : #{data[:shipping_company]}"
98
+ puts "Tracking Number : #{data[:tracking_number]}"
99
+ puts
100
+ end
101
+
102
+ end
103
+
104
+ end
105
+ end
106
+
107
+ # http://www.dhl.com/shipmentTracking?AWB=5902444026&languageCode=en
108
+
@@ -0,0 +1,29 @@
1
+ require 'time'
2
+
3
+ module DJI
4
+ module DHL
5
+
6
+ class Checkpoint
7
+ attr_accessor :counter
8
+ attr_accessor :description
9
+ attr_accessor :time_value, :date_value
10
+ attr_accessor :datetime
11
+
12
+ class << self
13
+
14
+ def new_from_item(item)
15
+ c = Checkpoint.new
16
+ c.counter = item['counter']
17
+ c.description = item['description']
18
+ c.time_value = item['time']
19
+ c.date_value = item['date']
20
+ c.datetime = Time.parse("#{c.date_value}#{c.time_value}")
21
+ c
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,57 @@
1
+ require 'date'
2
+ require 'time'
3
+
4
+ require 'dji/dhl/checkpoint'
5
+
6
+ module DJI
7
+ module DHL
8
+
9
+ class Shipment
10
+ attr_accessor :waybill
11
+ attr_accessor :delivery_code, :delivery_status
12
+ attr_accessor :origin, :destination
13
+ attr_accessor :origin_country, :origin_region, :origin_city
14
+ attr_accessor :destination_country, :destination_region, :destination_city
15
+ attr_accessor :checkpoints
16
+ attr_accessor :estimated_delivery_date, :estimated_delivery_product
17
+
18
+ def initialize
19
+ @checkpoints = []
20
+ end
21
+
22
+ def destination=(value)
23
+ @destination = value
24
+ self.destination_city, self.destination_region, self.destination_country = value.split(' - ')
25
+ end
26
+
27
+ def origin=(value)
28
+ @origin = value
29
+ self.origin_city, self.origin_region, self.origin_country = value.split(' - ')
30
+ end
31
+
32
+ class << self
33
+
34
+ def new_from_item(item)
35
+ shipment = Shipment.new
36
+ shipment.waybill = item['id']
37
+ shipment.delivery_code = item['delivery']['code']
38
+ shipment.delivery_status = item['delivery']['status']
39
+ shipment.destination = item['destination']['value']
40
+ shipment.origin = item['origin']['value']
41
+ shipment.estimated_delivery_date = Date.parse(item['edd']['date'])
42
+ shipment.estimated_delivery_product = item['edd']['product']
43
+
44
+ item['checkpoints'].each do |item|
45
+ checkpoint = Checkpoint.new_from_item(item)
46
+ shipment.checkpoints << checkpoint
47
+ end
48
+
49
+ shipment
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,33 @@
1
+ require 'dji/dhl/shipment'
2
+
3
+ module DJI
4
+ module DHL
5
+
6
+ class TrackingResults
7
+ attr_accessor :shipments
8
+
9
+ def initialize
10
+ @shipments = []
11
+ end
12
+
13
+ class << self
14
+
15
+ def new_from_results(results)
16
+ return nil if results.blank?
17
+
18
+ tr = TrackingResults.new
19
+
20
+ results.each do |item|
21
+ shipment = DJI::DHL::Shipment.new_from_item(item)
22
+ tr.shipments << shipment
23
+ end
24
+
25
+ tr
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+ end
data/lib/dji/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DJI
2
- VERSION = '0.4.2'
2
+ VERSION = '0.5.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dji
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Elliott
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-28 00:00:00.000000000 Z
11
+ date: 2016-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -125,9 +125,14 @@ files:
125
125
  - lib/dji/command/base.rb
126
126
  - lib/dji/command/behavior.rb
127
127
  - lib/dji/commands.rb
128
+ - lib/dji/commands/dhl/dhl_command.rb
128
129
  - lib/dji/commands/fedex/fedex_command.rb
129
130
  - lib/dji/commands/track/track_command.rb
130
131
  - lib/dji/commands/version/version_command.rb
132
+ - lib/dji/dhl.rb
133
+ - lib/dji/dhl/checkpoint.rb
134
+ - lib/dji/dhl/shipment.rb
135
+ - lib/dji/dhl/tracking_results.rb
131
136
  - lib/dji/fedex.rb
132
137
  - lib/dji/fedex/package.rb
133
138
  - lib/dji/fedex/scan_event.rb