Class: Bring::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/bring/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/bring/cli.rb', line 67

def self.exit_on_failure?
  true
end

Instance Method Details

#postal_code(pnr) ⇒ Object



7
8
9
10
# File 'lib/bring/cli.rb', line 7

def postal_code(pnr)
  require 'bring/postal_code'
  puts PostalCode.new(pnr, :country => options[:country]).city
end

#tracking(tracking_number) ⇒ Object



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
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/bring/cli.rb', line 15

def tracking(tracking_number)
  require 'bring/tracking'
  begin
    tracking = Tracking.new(tracking_number)

    tracking.consignments.each do |consignment|
      say "Shipment Number: #{consignment.consignment_id}", :white
      say "Total Weight: #{consignment.total_weight_in_kgs} kg"
      say "Total Volume: #{consignment.total_volume_in_dm3} dm3"
      say "Number of Packages: #{consignment.packages.count}"

      consignment.packages.each do |package|
        say ""
        say "Package Number: #{package.package_number}", :white

        if package.sender_name
          say "Sender: #{package.sender_name}"
        end

        if package.recipient_address
          say "Recipient: #{package.recipient_address.to_s}"
        end

        sizes =
          [package.length_in_cm, package.width_in_cm, package.height_in_cm]
        say "Measurements: #{sizes.join('x')} cm (LxWxH)"

        if package.date_of_return
          say "Last day for retrieval: #{package.date_of_return}"
        end

        package.events.each_with_index do |event, index|
          color = event.color if options[:color]
          say ""
          say "Status: #{event.status}", color
          say event.description

          say "#{event.date.strftime('%Y-%m-%d %H:%M')}", nil, false
          if event.postal_code?
            say ", #{event.postal_code} #{event.city}", nil, false
          end
          say ''

          break unless options[:full] || index > 0
        end
      end
    end
  rescue Bring::Tracking::Error => exception
    raise Thor::Error, exception.message
  end
end