class GunBroker::Order
Represents a GunBroker
order (listing).
Attributes
TODO: Refactor this, attributes
, and []
into a module. @return [Hash] Attributes parsed from the JSON response.
Public Class Methods
@param order_id [Integer, String] The ID of the Order
to find. @return [Order] An Order
instance or `nil` if no Order
with `order_id` exists.
# File lib/gun_broker/order.rb, line 11 def self.find(order_id, params = {}, headers = {}) find!(order_id, params, headers) rescue GunBroker::Error::NotFound nil end
Same as {.find} but raises GunBroker::Error::NotFound
if no Order
is found. @param (see .find) @raise [GunBroker::Error::NotFound] If no Order
with `order_id` exists. @return (see .find)
# File lib/gun_broker/order.rb, line 21 def self.find!(order_id, params = {}, headers = {}) response = GunBroker::API.get("/Orders/#{order_id}", params, headers) new(response.body) end
@param attrs [Hash] The JSON attributes from the API
response.
# File lib/gun_broker/order.rb, line 27 def initialize(attrs = {}) @attrs = attrs end
Public Instance Methods
@param key [String] An Order
attribute name (from the JSON response). @return The value of the given `key` or `nil`.
# File lib/gun_broker/order.rb, line 106 def [](key) @attrs[key] end
@return [Hash] Attributes parsed from the JSON response.
# File lib/gun_broker/order.rb, line 32 def attributes @attrs end
@return [Hash] Billing info for this Order
.
# File lib/gun_broker/order.rb, line 52 def bill_to { name: @attrs['billToName'], address_1: @attrs['billToAddress1'], address_2: @attrs['billToAddress2'], city: @attrs['billToCity'], state: @attrs['billToState'], zip: @attrs['billToPostalCode'], email: @attrs['billToEmail'], phone: @attrs['billToPhone'] } end
@return [String] FFL Number (if applicable) for this Order
.
# File lib/gun_broker/order.rb, line 42 def ffl_number @attrs['fflNumber'] end
@return [Integer] The Order
ID.
# File lib/gun_broker/order.rb, line 37 def id @attrs['orderID'] end
@return [Float] Total sales amount for this Order
.
# File lib/gun_broker/order.rb, line 90 def order_total @attrs['orderTotal'] end
@return [String] Payment methods used for this Order
.
# File lib/gun_broker/order.rb, line 95 def payment_methods @attrs['paymentMethod'].values end
@return [Float] Total sales tax for this Order
.
# File lib/gun_broker/order.rb, line 85 def sales_tax_total @attrs['salesTaxTotal'] end
@return [Hash] Shipping info for this Order
.
# File lib/gun_broker/order.rb, line 66 def ship_to { name: @attrs['shipToName'], address_1: @attrs['shipToAddress1'], address_2: @attrs['shipToAddress2'], city: @attrs['shipToCity'], state: @attrs['shipToState'], zip: @attrs['shipToPostalCode'], email: @attrs['shipToEmail'], phone: @attrs['shipToPhone'] } end
@return [Float] Total shipping amount for this Order
.
# File lib/gun_broker/order.rb, line 80 def shipping_total @attrs['shipCost'] end
@return [Integer] Status key for this Order
.
# File lib/gun_broker/order.rb, line 100 def status_key @attrs['status'].keys.first.to_i end