Class: GunBroker::Order
- Inherits:
-
Object
- Object
- GunBroker::Order
- Defined in:
- lib/gun_broker/order.rb,
lib/gun_broker/order/constants.rb
Overview
Represents a GunBroker order (listing).
Defined Under Namespace
Modules: Constants
Instance Attribute Summary collapse
-
#attrs ⇒ Hash
readonly
TODO: Refactor this, #attributes, and #[] into a module.
Class Method Summary collapse
-
.find(order_id, params = {}, headers = {}) ⇒ Order
An Order instance or
nil
if no Order withorder_id
exists. -
.find!(order_id, params = {}, headers = {}) ⇒ Order
Same as Order.find but raises GunBroker::Error::NotFound if no Order is found.
Instance Method Summary collapse
-
#[](key) ⇒ Object
The value of the given
key
ornil
. -
#attributes ⇒ Hash
Attributes parsed from the JSON response.
-
#bill_to ⇒ Hash
Billing info for this Order.
-
#ffl_number ⇒ String
FFL Number (if applicable) for this Order.
-
#id ⇒ Integer
The Order ID.
-
#initialize(attrs = {}) ⇒ Order
constructor
A new instance of Order.
-
#item_ids ⇒ Array
Item IDs of associated items for this Order.
-
#order_total ⇒ Float
Total sales amount for this Order.
-
#payment_methods ⇒ String
Payment methods used for this Order.
-
#sales_tax_total ⇒ Float
Total sales tax for this Order.
-
#ship_to ⇒ Hash
Shipping info for this Order.
-
#shipping_total ⇒ Float
Total shipping amount for this Order.
-
#status_key ⇒ Integer
Status key for this Order.
Constructor Details
#initialize(attrs = {}) ⇒ Order
Returns a new instance of Order.
27 28 29 |
# File 'lib/gun_broker/order.rb', line 27 def initialize(attrs = {}) @attrs = attrs end |
Instance Attribute Details
#attrs ⇒ Hash (readonly)
TODO: Refactor this, #attributes, and #[] into a module.
7 8 9 |
# File 'lib/gun_broker/order.rb', line 7 def attrs @attrs end |
Class Method Details
.find(order_id, params = {}, headers = {}) ⇒ Order
Returns An Order instance or nil
if no Order with order_id
exists.
11 12 13 14 15 |
# 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 = {}) ⇒ Order
Same as find but raises GunBroker::Error::NotFound if no Order is found.
21 22 23 24 |
# 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 |
Instance Method Details
#[](key) ⇒ Object
Returns The value of the given key
or nil
.
106 107 108 |
# File 'lib/gun_broker/order.rb', line 106 def [](key) @attrs[key] end |
#attributes ⇒ Hash
Returns Attributes parsed from the JSON response.
32 33 34 |
# File 'lib/gun_broker/order.rb', line 32 def attributes @attrs end |
#bill_to ⇒ Hash
Returns Billing info for this Order.
52 53 54 55 56 57 58 59 60 61 62 63 |
# 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 ⇒ String
Returns FFL Number (if applicable) for this Order.
42 43 44 |
# File 'lib/gun_broker/order.rb', line 42 def ffl_number @attrs['fflNumber'] end |
#id ⇒ Integer
Returns The Order ID.
37 38 39 |
# File 'lib/gun_broker/order.rb', line 37 def id @attrs['orderID'] end |
#item_ids ⇒ Array
Returns Item IDs of associated items for this Order.
47 48 49 |
# File 'lib/gun_broker/order.rb', line 47 def item_ids (@attrs['items'] || @attrs['orderItemsCollection']).collect { |item| item['itemID'] } end |
#order_total ⇒ Float
Returns Total sales amount for this Order.
90 91 92 |
# File 'lib/gun_broker/order.rb', line 90 def order_total @attrs['orderTotal'] || @attrs['totalPrice'] end |
#payment_methods ⇒ String
Returns Payment methods used for this Order.
95 96 97 |
# File 'lib/gun_broker/order.rb', line 95 def payment_methods @attrs['paymentMethod'].values end |
#sales_tax_total ⇒ Float
Returns Total sales tax for this Order.
85 86 87 |
# File 'lib/gun_broker/order.rb', line 85 def sales_tax_total @attrs['salesTaxTotal'] end |
#ship_to ⇒ Hash
Returns Shipping info for this Order.
66 67 68 69 70 71 72 73 74 75 76 77 |
# 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 ⇒ Float
Returns Total shipping amount for this Order.
80 81 82 |
# File 'lib/gun_broker/order.rb', line 80 def shipping_total @attrs['shipCost'] end |
#status_key ⇒ Integer
Returns Status key for this Order.
100 101 102 |
# File 'lib/gun_broker/order.rb', line 100 def status_key @attrs['status'].keys.first.to_i end |