class Honey::Order
Attributes
address1[RW]
address2[RW]
city[RW]
country[RW]
date[RW]
emailaddress[RW]
first[RW]
instructions[RW]
items[RW]
last[RW]
phone[RW]
reference[RW]
shipby[RW]
shipping[RW]
state[RW]
zip[RW]
Public Class Methods
attr_accessor(*attributes)
click to toggle source
Calls superclass method
# File lib/honey/order.rb, line 3 def self.attr_accessor(*attributes) @attributes ||= [] @attributes.concat attributes super(*attributes) end
attributes()
click to toggle source
# File lib/honey/order.rb, line 9 def self.attributes @attributes end
new(args = {})
click to toggle source
# File lib/honey/order.rb, line 19 def initialize(args = {}) update(args) end
shipping_option(carrier: :special, service:)
click to toggle source
# File lib/honey/order.rb, line 71 def self.shipping_option(carrier: :special, service:) carrier = carrier.to_s service = service.to_s unless carrier_options = shipping_options[carrier.downcase] raise Honey::Error, "'#{carrier}' isn't a valid carrier. Valid carriers are: #{shipping_options.keys}" end unless option = carrier_options[service.downcase] raise Honey::Error, "'#{service}' isn't a shipping option for #{carrier}. Valid options are: #{carrier_options.keys}" end option end
shipping_option_from_api_code(api_code)
click to toggle source
# File lib/honey/order.rb, line 87 def self.shipping_option_from_api_code(api_code) shipping_options.each_pair do |carrier, options| options.each_pair do |service, code| return { carrier: carrier, service: service } if api_code == code end end nil end
Private Class Methods
shipping_options()
click to toggle source
# File lib/honey/order.rb, line 97 def self.shipping_options { "special" => { "pickup" => "PICKUP", "best rate" => "RTSHOP", "cheapest" => "RTSHOP" }, "fedex" => { "first overnight" => "F001", "priority overnight" => "F002", "standard overnight" => "F003", "2 day air" => "F004", "express saver" => "F005", "ground north america" => "F006", "ground home delivery" => "F007", "international priority" => "F008", "international economy" => "F009" }, "usps" => { "express mail" => "P001", "priority mail" => "P002", "first class" => "P003", "parcel post" => "P004", "international express" => "P005", "international priority" => "P006", "international first class" => "P007", "priority flat rate" => "P008" }, "ups" => { "next day air" => "U001", "2 day air" => "U002", "3 day air" => "U003", "ground" => "U004", "standard" => "U005" } } end
Public Instance Methods
attributes()
click to toggle source
# File lib/honey/order.rb, line 13 def attributes self.class.attributes end
each_pair() { |key, send, block| ... }
click to toggle source
# File lib/honey/order.rb, line 47 def each_pair(&block) present_attributes.each do |key| yield(key, self.send(key), block) end end
invalid?()
click to toggle source
# File lib/honey/order.rb, line 57 def invalid? !valid? end
present_attributes()
click to toggle source
# File lib/honey/order.rb, line 65 def present_attributes attributes.collect do |attr| attr unless self.send(attr).nil? end.compact end
reference=(id)
click to toggle source
# File lib/honey/order.rb, line 29 def reference=(id) if id == :test @reference = "TEST" << Digest::MD5.base64digest(Time.now.to_s).gsub(/\W/, '') else @reference = id end end
required_attributes()
click to toggle source
# File lib/honey/order.rb, line 61 def required_attributes attributes - [:address2, :instructions, :phone] end
shipby=(code)
click to toggle source
# File lib/honey/order.rb, line 37 def shipby=(code) if code.is_a?(String) @shipby = code else @shipby = shipping_option(code) end end
Also aliased as: shipping=
shipping_option(*args)
click to toggle source
# File lib/honey/order.rb, line 83 def shipping_option(*args) self.class.shipping_option(*args) end
update(args = {})
click to toggle source
# File lib/honey/order.rb, line 23 def update(args = {}) args.each_pair do |key, value| self.send("#{key}=".to_sym, value) end end
valid?()
click to toggle source
# File lib/honey/order.rb, line 53 def valid? (required_attributes - present_attributes).empty? end