dji 0.3.8 → 0.3.9

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: 709b42b533db5c7dd69ba5875661fa008d06f8f0
4
- data.tar.gz: ba9c86ae0d78b2d9e1208296a141fd22e0879bdb
3
+ metadata.gz: d6c7466dc976d6bab33aa9d69de6c9aa92145f6e
4
+ data.tar.gz: 0222e16f71c237dfedb3932dd334f352a11a9890
5
5
  SHA512:
6
- metadata.gz: 9deae5ba1a44390df1625e75313b662572ed85f59d03a26fe7d0f8c9969f3aaac9cc759d7e2c008c281429924c7cf560c2e312001f54b76ee276a9779b6007de
7
- data.tar.gz: b692e03ab6e77e5a565761604e7f2ae2629d8f295d088b48889e02c6865a5ce7af1364ce8d447956dcc75b2cc09fb5e7b7d36d26aa61b2e696ccbe8e4e21b574
6
+ metadata.gz: 87e29875f092a73d57e8831f1e8c85b0b0fb4ba9ecef1829aba29d9755c2fd316ebc96d0db313b4904a86f12598b37e6c082dde89b0b7a97f19448a6dd34c45e
7
+ data.tar.gz: a93faf41a6518d1e0374b6617d4f08acff7bbb2f927007870ed8d4396a689c6a8f246beaccbcad9229204e397415b774f1ba6a4067e525e826073848bdc9fae3
@@ -6,15 +6,20 @@ module DJI
6
6
  option :phone_tail, required: true, aliases: :p
7
7
  option :repeat, aliases: :r
8
8
  option :publish, required: false, default: false
9
+
9
10
  option :country, required: false, aliases: :c
11
+ option :debug, required: false, default: false, aliases: :d
10
12
  option :dji_username, required: false, aliases: [:username, :u]
11
-
13
+ option :email_address, required: false, aliases: [:email, :e]
14
+
12
15
  def track
13
16
  provided_options = {
14
17
  order_number: options[:order_number],
15
18
  phone_tail: options[:phone_tail],
16
19
  country: options[:country],
17
- dji_username: options[:dji_username]
20
+ debug: options[:debug],
21
+ dji_username: options[:dji_username],
22
+ email: options[:email_address],
18
23
  }
19
24
 
20
25
  if options[:repeat].present?
@@ -10,12 +10,19 @@ module DJI
10
10
  class << self
11
11
 
12
12
  # Retrieve an authenticity_token
13
- def authenticity_token(url)
13
+ def authenticity_token(url, options = {})
14
14
  uri = URI(url)
15
15
  http = Net::HTTP.new uri.host, uri.port
16
16
  request = Net::HTTP::Get.new uri.path
17
17
  response = http.request request
18
18
 
19
+ if options[:debug].present?
20
+ puts "DEBUG: -------------------------------------------------------------------"
21
+ puts "DEBUG: Authenticity Token Body"
22
+ puts "DEBUG: #{response.body}"
23
+ puts "DEBUG: -------------------------------------------------------------------"
24
+ end
25
+
19
26
  page = Nokogiri::HTML(response.body)
20
27
  token_dom = page.at_xpath('//meta[@name="csrf-token"]/@content')
21
28
  token = token_dom.text if token_dom.present?
@@ -26,7 +33,7 @@ module DJI
26
33
 
27
34
  # Get the tracking details for an order
28
35
  def tracking_details(options = {})
29
- auth_token = authenticity_token(tracking_url)
36
+ auth_token = authenticity_token(tracking_url, options)
30
37
 
31
38
  url = URI.parse(tracking_url)
32
39
  params = { 'number' => options[:order_number], 'phone_tail' => options[:phone_tail], 'utf8' => '✓' }
@@ -42,12 +49,19 @@ module DJI
42
49
  http = Net::HTTP.new url.host, url.port
43
50
  request = Net::HTTP::Post.new url.path, headers
44
51
  request.set_form_data params
45
- res = http.request(request)
52
+ response = http.request(request)
53
+
54
+ if options[:debug].present?
55
+ puts "DEBUG: -------------------------------------------------------------------"
56
+ puts "DEBUG: Tracking Page Body"
57
+ puts "DEBUG: #{response.body}"
58
+ puts "DEBUG: -------------------------------------------------------------------"
59
+ end
46
60
 
47
- data = case res
61
+ data = case response
48
62
  when Net::HTTPSuccess, Net::HTTPRedirection
49
63
  # OK
50
- page = Nokogiri::HTML(res.body)
64
+ page = Nokogiri::HTML(response.body)
51
65
  content = page.at_xpath('//div[@id="main"]/div[@class="container"]/div[@class="row"]/div[@class="col-xs-9"]/div[@class="col-xs-10 well"][2]')
52
66
 
53
67
  data = {}
@@ -58,13 +72,15 @@ module DJI
58
72
  data[:shipping_company] = content.at_xpath('div[5]/span').text
59
73
  data[:tracking_number] = content.at_xpath('div[6]/a').text
60
74
 
61
- data[:shipping_country] = options[:country] if options[:country].present?
75
+ data[:email_address] = options[:email_address] if options[:email_address].present?
76
+ data[:debug] = options[:debug] if options[:debug].present?
62
77
  data[:dji_username] = options[:dji_username] if options[:dji_username].present?
78
+ data[:shipping_country] = options[:country] if options[:country].present?
63
79
 
64
80
  print_tracking_details(data)
65
81
  data
66
82
  else
67
- puts "There was an error: #{res.message}"
83
+ puts "There was an error: #{response.message}"
68
84
  nil
69
85
  end
70
86
 
@@ -118,14 +134,14 @@ module DJI
118
134
  http = Net::HTTP.new url.host, url.port
119
135
  request = Net::HTTP::Post.new url.path, headers
120
136
  request.body = params.to_json
121
- res = http.request(request)
137
+ response = http.request(request)
122
138
 
123
- case res
139
+ case response
124
140
  when Net::HTTPSuccess, Net::HTTPRedirection
125
141
  puts "You have successfully published your latest order status."
126
142
  puts "See order statuses reported by others at #{publish_url}"
127
143
  else
128
- puts "There was an error trying to publish your order status: #{res.message}"
144
+ puts "There was an error trying to publish your order status: #{response.message}"
129
145
  end
130
146
 
131
147
  end
@@ -1,3 +1,3 @@
1
1
  module DJI
2
- VERSION = '0.3.8'
2
+ VERSION = '0.3.9'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dji
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Elliott