Class: OrionWholesale::Tracking

Inherits:
Base
  • Object
show all
Defined in:
lib/orion_wholesale/tracking.rb

Constant Summary collapse

BASE_TRACKING_FILE_DIRECTORY =
"%s-TRACK".freeze
BASE_TRACKING_FILE_NAME =
"%s_PackageTracking.csv".freeze
CARRIER =
'UPS'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

connect

Constructor Details

#initialize(options = {}) ⇒ Tracking

Returns a new instance of Tracking.



8
9
10
11
12
13
# File 'lib/orion_wholesale/tracking.rb', line 8

def initialize(options = {})
  requires!(options, :username, :password, :dealer_number)

  @options = options
  @dealer_number = options[:dealer_number]
end

Class Method Details

.fetch_data(options = {}) ⇒ Object



15
16
17
18
19
# File 'lib/orion_wholesale/tracking.rb', line 15

def self.fetch_data(options = {})
  requires!(options, :username, :password, :dealer_number)

  new(options).fetch_data
end

Instance Method Details

#fetch_dataObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/orion_wholesale/tracking.rb', line 21

def fetch_data
  tracking_file_name = BASE_TRACKING_FILE_NAME % @dealer_number
  tracking_file_directory = BASE_TRACKING_FILE_DIRECTORY % @dealer_number
  tracking_file = get_file(tracking_file_name, tracking_file_directory)

  tracking_details = CSV.foreach(tracking_file, { headers: :first_row }).map do |row|
    {
      po_number: row['USR_VEND_ORD_NO'],
      carrier: CARRIER,
      tracking_numbers: [row['TRK_NO_1'], row['TRK_NO_2'], row['TRK_NO_3'], row['TRK_NO_4'], row['TRK_NO_5']].reject(&:blank?),
    }
  end

  tracking_file.unlink

  tracking_details
end