Class: GunBroker::Item
- Inherits:
-
Object
- Object
- GunBroker::Item
- Includes:
- Constants
- Defined in:
- lib/gun_broker/item.rb,
lib/gun_broker/item/constants.rb
Overview
Represents a GunBroker item (listing).
Defined Under Namespace
Modules: Constants
Constant Summary
Constants included from Constants
Constants::AUCTION_DURATION, Constants::AUTO_RELIST, Constants::CONDITION, Constants::FIXED_PRICE_DURATION, Constants::INSPECTION_PERIOD, Constants::PAYMENT_METHODS, Constants::SHIPPING_CLASSES, Constants::SHIPPING_PAYER
Instance Attribute Summary collapse
-
#attrs ⇒ Hash
readonly
TODO: Refactor this, #attributes, and #[] into a module.
Class Method Summary collapse
-
.find(item_id) ⇒ Item
An Item instance or
nil
if no Item withitem_id
exists. -
.find!(item_id) ⇒ Item
Same as Item.find but raises GunBroker::Error::NotFound if no Item is found.
Instance Method Summary collapse
-
#[](key) ⇒ Object
The value of the given
key
ornil
. -
#attributes ⇒ Hash
Attributes parsed from the JSON response.
-
#category ⇒ Category
This Items Category.
-
#id ⇒ Integer
The Item ID.
-
#initialize(attrs = {}) ⇒ Item
constructor
A new instance of Item.
-
#title ⇒ String
Title of this Item.
-
#url ⇒ String
GunBroker.com URL for this Item.
Constructor Details
#initialize(attrs = {}) ⇒ Item
Returns a new instance of Item.
31 32 33 |
# File 'lib/gun_broker/item.rb', line 31 def initialize(attrs = {}) @attrs = attrs end |
Instance Attribute Details
#attrs ⇒ Hash (readonly)
TODO: Refactor this, #attributes, and #[] into a module.
11 12 13 |
# File 'lib/gun_broker/item.rb', line 11 def attrs @attrs end |
Class Method Details
Instance Method Details
#[](key) ⇒ Object
Returns The value of the given key
or nil
.
66 67 68 |
# File 'lib/gun_broker/item.rb', line 66 def [](key) @attrs[key] end |
#attributes ⇒ Hash
Returns Attributes parsed from the JSON response.
41 42 43 |
# File 'lib/gun_broker/item.rb', line 41 def attributes @attrs end |
#category ⇒ Category
Returns This Items Category.
46 47 48 |
# File 'lib/gun_broker/item.rb', line 46 def category GunBroker::Category.find(@attrs['categoryID']) end |
#id ⇒ Integer
Returns The Item ID.
36 37 38 |
# File 'lib/gun_broker/item.rb', line 36 def id @attrs['itemID'] end |
#title ⇒ String
Returns Title of this Item.
51 52 53 |
# File 'lib/gun_broker/item.rb', line 51 def title @attrs['title'] end |