Class: Wegift::Products

Inherits:
Response show all
Defined in:
lib/wegift/models/products.rb

Constant Summary collapse

PATH =
'/products'

Constants inherited from Response

Response::STATUS

Instance Attribute Summary collapse

Attributes inherited from Response

#error_code, #error_details, #error_string, #payload, #status

Instance Method Summary collapse

Methods inherited from Response

#is_successful?

Methods included from Initializable

#initialize

Instance Attribute Details

#allObject

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