Class: BigcommerceProductAgent::Client::Variant

Inherits:
AbstractClient show all
Defined in:
lib/client/variant.rb

Instance Method Summary collapse

Methods inherited from AbstractClient

#client, #delete, #get, #index, #initialize, #uri, uri_base, #uri_base

Constructor Details

This class inherits a constructor from BigcommerceProductAgent::Client::AbstractClient

Instance Method Details

#create(payload) ⇒ Object



10
11
12
# File 'lib/client/variant.rb', line 10

def create(payload)
    raise "this endpoint only has upsert available"
end

#get_by_skus(skus, include = %w[custom_fields modifiers]) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/client/variant.rb', line 23

def get_by_skus(skus, include = %w[custom_fields modifiers])
    variants = index({
        'sku:in': skus.join(','),
        include: include.join(','),
    })

    map = {}

    variants.each do |variant|
        map[variant['sku']] = variant
    end

    map
end

#update(payload) ⇒ Object



6
7
8
# File 'lib/client/variant.rb', line 6

def update(payload)
    raise "this endpoint only has upsert available"
end

#upsert(payload) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/client/variant.rb', line 14

def upsert(payload)
    begin
        response = client.put(uri, payload.to_json)
        return response.body['data']
      rescue Faraday::Error::ClientError => e
          raise e, "\n#{e.message}\nFailed to upsert variant with payload = #{payload.to_json}\n", e.backtrace
      end
end