dji 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/lib/dji/commands/track/track_command.rb +5 -2
- data/lib/dji/order_tracking.rb +46 -4
- data/lib/dji/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e2a5d2d495eeeaadd66d708f483a1db82642463
|
4
|
+
data.tar.gz: 608dd161a829331acba3ac040471fd6a18ade786
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23c77b9dbcf7027cef897adeb4ae74764aaf1900f45d6c74465a2f13fcd27793a06cccc50167f39ee62dffab4c3990bc13e43028355746a24faedf02ca3b20fa
|
7
|
+
data.tar.gz: 482320f82bee5ac0a77e43716133e0b6a84a3ca754b224e3b3d84d56ee8d735de02edcde66ee5b94b82ca25a332a6bab5f4211a770dfc4fa3b6ebbc1d2d58e2a
|
data/README.md
CHANGED
@@ -18,6 +18,11 @@ If you do not manage your Ruby installations with RVM and are just using the sys
|
|
18
18
|
|
19
19
|
$ sudo gem install dji
|
20
20
|
|
21
|
+
If you are on Ubuntu Linux, you can do:
|
22
|
+
|
23
|
+
$ sudo apt install ruby ruby-dev
|
24
|
+
$ sudo gem install dji
|
25
|
+
|
21
26
|
## Usage
|
22
27
|
|
23
28
|
### Track an order
|
@@ -5,6 +5,7 @@ module DJI
|
|
5
5
|
option :order_number, required: true, aliases: :o
|
6
6
|
option :phone_tail, required: true, aliases: :p
|
7
7
|
option :repeat, aliases: :r
|
8
|
+
option :publish, required: false, default: false
|
8
9
|
|
9
10
|
def track
|
10
11
|
if options[:repeat].present?
|
@@ -13,11 +14,13 @@ module DJI
|
|
13
14
|
puts "Requesting order tracking details every #{interval} seconds. Press CONTROL-C to stop..."
|
14
15
|
|
15
16
|
while true
|
16
|
-
DJI::OrderTracking.tracking_details(options[:order_number], options[:phone_tail])
|
17
|
+
data = DJI::OrderTracking.tracking_details(options[:order_number], options[:phone_tail])
|
18
|
+
DJI::OrderTracking.publish(data) if data.present? && options[:publish].present?
|
17
19
|
sleep(interval)
|
18
20
|
end
|
19
21
|
else
|
20
|
-
DJI::OrderTracking.tracking_details(options[:order_number], options[:phone_tail])
|
22
|
+
data = DJI::OrderTracking.tracking_details(options[:order_number], options[:phone_tail])
|
23
|
+
DJI::OrderTracking.publish(data) if data.present? && options[:publish].present?
|
21
24
|
end
|
22
25
|
end
|
23
26
|
end
|
data/lib/dji/order_tracking.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'uri'
|
3
|
+
require 'json'
|
3
4
|
|
4
5
|
require 'nokogiri'
|
5
6
|
|
@@ -42,7 +43,7 @@ module DJI
|
|
42
43
|
request.set_form_data params
|
43
44
|
res = http.request(request)
|
44
45
|
|
45
|
-
case res
|
46
|
+
data = case res
|
46
47
|
when Net::HTTPSuccess, Net::HTTPRedirection
|
47
48
|
# OK
|
48
49
|
page = Nokogiri::HTML(res.body)
|
@@ -57,11 +58,13 @@ module DJI
|
|
57
58
|
data[:tracking_number] = content.at_xpath('div[6]/a').text
|
58
59
|
|
59
60
|
print_tracking_details(data)
|
61
|
+
data
|
60
62
|
else
|
61
|
-
puts res.
|
62
|
-
|
63
|
+
puts "There was an error: #{res.message}"
|
64
|
+
nil
|
63
65
|
end
|
64
|
-
|
66
|
+
|
67
|
+
data
|
65
68
|
end
|
66
69
|
|
67
70
|
# The URL for order tracking
|
@@ -84,6 +87,45 @@ module DJI
|
|
84
87
|
puts
|
85
88
|
end
|
86
89
|
|
90
|
+
def publish(data)
|
91
|
+
url = URI.parse(publish_url)
|
92
|
+
params = {
|
93
|
+
format: :json,
|
94
|
+
order: {
|
95
|
+
order_id: data[:order_number],
|
96
|
+
payment_status: data[:payment_status],
|
97
|
+
payment_total: data[:total],
|
98
|
+
shipping_status: data[:shipping_status],
|
99
|
+
shipping_company: data[:shipping_company],
|
100
|
+
tracking_number: data[:tracking_number]
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
headers = {
|
105
|
+
'Accepts' => 'application/json',
|
106
|
+
'Content-Type' => 'application/json'
|
107
|
+
}
|
108
|
+
|
109
|
+
http = Net::HTTP.new url.host, url.port
|
110
|
+
request = Net::HTTP::Post.new url.path, headers
|
111
|
+
request.body = params.to_json
|
112
|
+
res = http.request(request)
|
113
|
+
|
114
|
+
case res
|
115
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
116
|
+
puts "You have successfully published your latest order status."
|
117
|
+
puts "See order statuses reported by others at #{publish_url}"
|
118
|
+
else
|
119
|
+
puts "There was an error trying to publish your order status: #{res.message}"
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
def publish_url
|
125
|
+
#'http://localhost:3000/orders'
|
126
|
+
'http://dji-track.herokuapp.com/orders'
|
127
|
+
end
|
128
|
+
|
87
129
|
end
|
88
130
|
|
89
131
|
end
|
data/lib/dji/version.rb
CHANGED
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
|
+
version: 0.3.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-
|
11
|
+
date: 2016-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|