class GunBroker::Item
Represents a GunBroker
item (listing).
Attributes
attrs[R]
TODO: Refactor this, attributes
, and []
into a module. @return [Hash] Attributes parsed from the JSON response.
Public Class Methods
find(item_id)
click to toggle source
find!(item_id)
click to toggle source
Same as {.find} but raises GunBroker::Error::NotFound
if no Item
is found. @param (see .find) @raise [GunBroker::Error::NotFound] If no Item
with `item_id` exists. @return (see .find)
# File lib/gun_broker/item.rb, line 25 def self.find!(item_id) response = GunBroker::API.get("/Items/#{item_id}") new(response.body) end
new(attrs = {})
click to toggle source
@param attrs [Hash] The JSON attributes from the API
response.
# File lib/gun_broker/item.rb, line 31 def initialize(attrs = {}) @attrs = attrs end
Public Instance Methods
[](key)
click to toggle source
@param key [String] An Item
attribute name (from the JSON response). @return The value of the given `key` or `nil`.
# File lib/gun_broker/item.rb, line 66 def [](key) @attrs[key] end
attributes()
click to toggle source
@return [Hash] Attributes parsed from the JSON response.
# File lib/gun_broker/item.rb, line 41 def attributes @attrs end
category()
click to toggle source
@return [Category] This Items Category
.
# File lib/gun_broker/item.rb, line 46 def category GunBroker::Category.find(@attrs['categoryID']) end
id()
click to toggle source
@return [Integer] The Item
ID.
# File lib/gun_broker/item.rb, line 36 def id @attrs['itemID'] end
title()
click to toggle source
@return [String] Title of this Item
.
# File lib/gun_broker/item.rb, line 51 def title @attrs['title'] end
url()
click to toggle source
@return [String] GunBroker.com URL for this Item
.
# File lib/gun_broker/item.rb, line 56 def url if GunBroker.sandbox "http://www.sandbox.gunbroker.com/Auction/ViewItem.aspx?Item=#{id}" else "http://www.gunbroker.com/Auction/ViewItem.aspx?Item=#{id}" end end