Class: OrionWholesale::Order

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

Overview

To submit an order:

See each method for a list of required options.

Constant Summary collapse

HEADERS =
[
  'Ordering Dealer Number',
  'Ordering Dealer Name',
  'Ship to Name',
  'Ship To Address',
  'Ship to City',
  'Ship to State',
  'Ship to Zip',
  'Ship to email',
  'Ship to phone',
  'Ship to FFL',
  'Item',
  'Item Desc',
  'Item UPC',
  'Item Qty',
  'Item Price',
  'Special Instructions'
]

Instance Method Summary collapse

Methods inherited from Base

connect

Constructor Details

#initialize(options = {}) ⇒ Order

Returns a new instance of Order.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :username (String)

    required



31
32
33
34
35
36
37
# File 'lib/orion_wholesale/order.rb', line 31

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

  @dealer_number = options[:username]
  @po_number     = options[:po_number]
  @items         = []
end

Instance Method Details

#add_item(item = {}) ⇒ Object

Parameters:

  • item (Hash) (defaults to: {})
    • :identifier [String] required

    • :description [String]

    • :upc [String] required

    • :qty [Integer] required

    • :price [String]



63
64
65
66
# File 'lib/orion_wholesale/order.rb', line 63

def add_item(item = {})
  requires!(item, :identifier, :upc, :qty)
  @items << item
end

#add_recipient(hash = {}) ⇒ Object

Parameters:

  • header (Hash)
    • :dealer_name [String] required

    • :ffl [String]

    • :shipping [Hash] required

      • :name [String] required

      • :address [String] required

      • :city [String] required

      • :state [String] required

      • :zip [String] required

      • :email [String] required

      • :phone [String] required

    • :special_instructions [String] optional



51
52
53
54
55
# File 'lib/orion_wholesale/order.rb', line 51

def add_recipient(hash = {})
  requires!(hash, :dealer_name, :shipping)
  requires!(hash[:shipping], :name, :address, :city, :state, :zip, :email, :phone)
  @headers = hash
end

#filenameObject



68
69
70
71
72
# File 'lib/orion_wholesale/order.rb', line 68

def filename
  return @filename if defined?(@filename)
  timestamp = Time.now.strftime('%Y%m%d%T').gsub(':', '')
  @filename = "ORION-#{@po_number}-#{timestamp}.csv"
end

#to_csvObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/orion_wholesale/order.rb', line 74

def to_csv
  CSV.generate(headers: true) do |csv|
    csv << HEADERS

    @items.each do |item|
      csv << [
        @dealer_number,
        @headers[:dealer_name],
        @headers[:shipping][:name],
        @headers[:shipping][:address],
        @headers[:shipping][:city],
        @headers[:shipping][:state],
        @headers[:shipping][:zip],
        @headers[:shipping][:email],
        @headers[:shipping][:phone],
        @headers[:ffl],
        item[:identifier],
        item[:description],
        item[:upc],
        item[:qty],
        item[:price],
        @headers[:special_instructions]
      ]
    end
  end # CSV.generate
end