class GunBroker::Order

Represents a GunBroker order (listing).

Attributes

attrs[R]

TODO: Refactor this, attributes, and [] into a module. @return [Hash] Attributes parsed from the JSON response.

Public Class Methods

find(order_id, params = {}, headers = {}) click to toggle source

@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
find!(order_id, params = {}, headers = {}) click to toggle source

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
new(attrs = {}) click to toggle source

@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

[](key) click to toggle source

@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
attributes() click to toggle source

@return [Hash] Attributes parsed from the JSON response.

# File lib/gun_broker/order.rb, line 32
def attributes
  @attrs
end
bill_to() click to toggle source

@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
ffl_number() click to toggle source

@return [String] FFL Number (if applicable) for this Order.

# File lib/gun_broker/order.rb, line 42
def ffl_number
  @attrs['fflNumber']
end
id() click to toggle source

@return [Integer] The Order ID.

# File lib/gun_broker/order.rb, line 37
def id
  @attrs['orderID']
end
item_ids() click to toggle source

@return [Array] Item IDs of associated items for this Order.

# File lib/gun_broker/order.rb, line 47
def item_ids
  (@attrs['items'] || @attrs['orderItemsCollection']).collect { |item| item['itemID'] }
end
order_total() click to toggle source

@return [Float] Total sales amount for this Order.

# File lib/gun_broker/order.rb, line 90
def order_total
  @attrs['orderTotal']
end
payment_methods() click to toggle source

@return [String] Payment methods used for this Order.

# File lib/gun_broker/order.rb, line 95
def payment_methods
  @attrs['paymentMethod'].values
end
sales_tax_total() click to toggle source

@return [Float] Total sales tax for this Order.

# File lib/gun_broker/order.rb, line 85
def sales_tax_total
  @attrs['salesTaxTotal']
end
ship_to() click to toggle source

@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
shipping_total() click to toggle source

@return [Float] Total shipping amount for this Order.

# File lib/gun_broker/order.rb, line 80
def shipping_total
  @attrs['shipCost']
end
status_key() click to toggle source

@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