Class: Wegift::Products
- Defined in:
- lib/wegift/models/products.rb
Constant Summary collapse
- PATH =
'/products'
Constants inherited from Response
Instance Attribute Summary collapse
-
#all ⇒ Object
Returns the value of attribute all.
Attributes inherited from Response
#error_code, #error_details, #error_string, #payload, #status
Instance Method Summary collapse
-
#find(name, value) ⇒ Object
Find all products by fieldname.
-
#get(ctx) ⇒ Object
Product Details List GET /api/b2b-sync/v1/products/.
- #parse(response) ⇒ Object
Methods inherited from Response
Methods included from Initializable
Instance Attribute Details
#all ⇒ Object
Returns the value of attribute all.
6 7 8 |
# File 'lib/wegift/models/products.rb', line 6 def all @all end |
Instance Method Details
#find(name, value) ⇒ Object
Find all products by fieldname.
16 17 18 |
# File 'lib/wegift/models/products.rb', line 16 def find(name, value) Wegift::Products.new(all: all.select! { |p| p.send(name).eql?(value) }) end |
#get(ctx) ⇒ Object
Product Details List GET /api/b2b-sync/v1/products/
10 11 12 13 |
# File 'lib/wegift/models/products.rb', line 10 def get(ctx) response = ctx.request(:get, PATH) parse(response) end |
#parse(response) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/wegift/models/products.rb', line 20 def parse(response) super(response) if is_successful? # TODO: separate? if @payload['products'] @all = @payload['products'].map { |p| Wegift::Product.new(p) } end else @all = [] end self end |