Sha256: b4750444fce411a080fd6796e6e7279bae4cd7065111c9bfe8c7bc263757e69a

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

require 'uri'

module Voucherify
  module Service
    class Vouchers
      attr_reader :client

      def initialize(client)
        @client = client
      end

      def create(code, options = {})
        url = '/vouchers'
        url += '/' + URI.encode(code) if code
        @client.post(url, options.to_json)
      end

      def get(code)
        @client.get("/vouchers/#{URI.encode(code)}")
      end

      def update(voucher_update)
        @client.put("/vouchers/#{URI.encode(voucher_update['code'] || voucher_update[:code])}", voucher_update.to_json)
      end

      def list(query)
        @client.get('/vouchers', query)
      end

      def enable(code)
        @client.post("/vouchers/#{URI.encode(code)}/enable", nil)
        nil
      end

      def disable(code)
        @client.post("/vouchers/#{URI.encode(code)}/disable", nil)
        nil
      end

      def delete(code, params = {})
        @client.delete("/vouchers/#{URI.encode(code)}", {:force => (!!(params['force'] || params[:force])).to_s})
        nil
      end

      def import(vouchers)
        @client.post('/vouchers/import', vouchers.to_json);
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
voucherify-1.3.0 lib/voucherify/service/vouchers.rb
voucherify-1.2.0 lib/voucherify/service/vouchers.rb