Class: Runa::Products
Constant Summary collapse
- PATH =
'/product'
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 /v2/product.
- #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/runa/models/products.rb', line 6 def all @all end |
Instance Method Details
#find(name, value) ⇒ Object
Find all products by fieldname.
32 33 34 |
# File 'lib/runa/models/products.rb', line 32 def find(name, value) Runa::Products.new(all: all.select! { |p| p.send(name).eql?(value) }) end |
#get(ctx) ⇒ Object
Product Details List GET /v2/product
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/runa/models/products.rb', line 10 def get(ctx) @all = [] @after_key = nil loop do = {} if !@after_key.nil? = { after: @after_key } end response = ctx.request(:get, PATH, , '') parse(response) if @after_key.nil? break end end self end |
#parse(response) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/runa/models/products.rb', line 36 def parse(response) super(response) if is_successful? # TODO: separate? if @payload['catalog'] @all.concat(@payload['catalog'].map { |p| Runa::Product.new(p) }) end @after_key = @payload['pagination']['cursors']['after'] else @all = [] end end |