Class: FetchAPI::Item
- Inherits:
-
Object
show all
- Includes:
- HTTParty
- Defined in:
- lib/fetchapi/item.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(data) ⇒ Item
Returns a new instance of Item.
9
10
11
12
13
14
15
16
|
# File 'lib/fetchapi/item.rb', line 9
def initialize(data)
case data
when Integer, String
@sku = data
when Hash
@sku, @data = data['sku'], data
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/fetchapi/item.rb', line 44
def method_missing(method)
if (data.has_key? method.to_s)
data[method.to_s]
else
super
end
end
|
Instance Attribute Details
#sku ⇒ Object
Returns the value of attribute sku.
8
9
10
|
# File 'lib/fetchapi/item.rb', line 8
def sku
@sku
end
|
Class Method Details
.create(options) ⇒ Object
35
36
37
|
# File 'lib/fetchapi/item.rb', line 35
def self.create(options)
self.post("/items/create", options)
end
|
.find(selector) ⇒ Object
26
27
28
29
30
31
32
33
|
# File 'lib/fetchapi/item.rb', line 26
def self.find(selector)
case selector
when :all
self.get('/items')['items'].map { |data| self.new(data) }
when Integer, String
self.new(selector)
end
end
|
Instance Method Details
#destroy ⇒ Object
18
19
20
|
# File 'lib/fetchapi/item.rb', line 18
def destroy
self.delete("/items/#{sku}/delete")
end
|
#update(options) ⇒ Object
22
23
24
|
# File 'lib/fetchapi/item.rb', line 22
def update(options)
self.post("/items/#{sku}/items", options)
end
|