Sha256: cf83e875eb91e839aa0cab5fe5d71633d0098ee6908278f1298816d155603b39

Contents?: true

Size: 771 Bytes

Versions: 3

Compression:

Stored size: 771 Bytes

Contents

# frozen_string_literal: true

class Wegift::Stock < Wegift::Response
  PATH = '/stock'

  # request/payload
  attr_reader :id

  # response/success
  attr_accessor :available_stock, :currency_code, :product_code, :product_name

  def initialize(params = {})
    @id = params[:id]
  end

  # Product Stock
  # GET /api/b2b-sync/v1/stock/ID
  def get(ctx)
    response = ctx.request(:get, path)
    parse(response)

    self
  end

  private

  def path
    [PATH, id.to_s].join('/')
  end

  def parse(response)
    super

    if is_successful?
      self.available_stock = payload['available_stock']
      self.currency_code = payload['currency_code']
      self.product_code = payload['product_code']
      self.product_name = payload['product_name']
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wegift-ruby-client-1.10.2 lib/wegift/models/stock.rb
wegift-ruby-client-1.10.0 lib/wegift/models/stock.rb
wegift-ruby-client-1.9.1 lib/wegift/models/stock.rb