Class: DJI::Command::TrackCommand

Inherits:
Base
  • Object
show all
Defined in:
lib/dji/commands/track/track_command.rb

Instance Method Summary collapse

Methods inherited from Base

command_name, inherited, namespace, perform

Instance Method Details

#trackObject



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
# File 'lib/dji/commands/track/track_command.rb', line 19

def track
  order_time = Time.parse(options[:order_time]) if options[:order_time].present?

  provided_options = {
    order_number:  options[:order_number],
    order_time:    order_time,
    phone_tail:    options[:phone_tail],
    country:       options[:country],
    debug:         options[:debug],
    dji_username:  options[:dji_username],
    email_address: options[:email_address],
  }

  if options[:repeat].present?
    interval = options[:repeat].to_i.presence || 300
    puts
    puts "Requesting order tracking details every #{interval} seconds. Press CONTROL-C to stop..."

    while true
      data = DJI::OrderTracking.tracking_details(provided_options)
      DJI::OrderTracking.publish(data) if data.present? && options[:publish].present?
      sleep(interval)
    end
  else
    data = DJI::OrderTracking.tracking_details(provided_options)
    DJI::OrderTracking.publish(data) if data.present? && options[:publish].present?
  end
end