Sha256: d07602da1aa8d7c54034ffd67d08b41cf17e3ef589d9548c502c5c8b26a13d19

Contents?: true

Size: 1.31 KB

Versions: 14

Compression:

Stored size: 1.31 KB

Contents

require 'uri'

module Voucherify
  module Service
    class Products
      attr_reader :client

      def initialize(client)
        @client = client
      end

      def create(product)
        @client.post('/products', product.to_json)
      end

      def get(product_id)
        @client.get("/products/#{URI.encode(product_id)}")
      end

      def update(product)
        @client.put("/products/#{URI.encode(product['id'] || product[:id])}", product.to_json)
      end

      def delete(product_id)
        @client.delete("/products/#{URI.encode(product_id)}")
      end

      def list(query = {})
        @client.get('/products', query)
      end

      def create_sku(product_id, sku)
        @client.post("/products/#{URI.encode(product_id)}/skus", sku.to_json)
      end

      def get_sku(product_id, sku_id)
        @client.get("/products/#{URI.encode(product_id)}/skus/#{URI.encode(sku_id)}")
      end

      def update_sku(product_id, sku)
        @client.put("/products/#{URI.encode(product_id)}/skus/#{URI.encode(sku['id'] || sku[:id])}", sku.to_json)
      end

      def delete_sku(product_id, sku_id)
        @client.delete("/products/#{URI.encode(product_id)}/skus/#{URI.encode(sku_id)}")
      end

      def list_skus(product_id)
        @client.get("/products/#{URI.encode(product_id)}/skus")
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
voucherify-3.0.0 lib/voucherify/service/products.rb
voucherify-2.4.0 lib/voucherify/service/products.rb
voucherify-2.3.0 lib/voucherify/service/products.rb
voucherify-2.2.0 lib/voucherify/service/products.rb
voucherify-2.1.1 lib/voucherify/service/products.rb
voucherify-2.1.0 lib/voucherify/service/products.rb
voucherify-2.0.0 lib/voucherify/service/products.rb
voucherify-1.6.1 lib/voucherify/service/products.rb
voucherify-1.6.0 lib/voucherify/service/products.rb
voucherify-1.5.0 lib/voucherify/service/products.rb
voucherify-1.4.0 lib/voucherify/service/products.rb
voucherify-1.3.0 lib/voucherify/service/products.rb
voucherify-1.2.0 lib/voucherify/service/products.rb
voucherify-1.1.0 lib/voucherify/service/products.rb