Sha256: 3947616d329c7ccf3af7708612decc6a6cdbe70009c737e3ff8e9ddb70b86618

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 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 += '/' + ERB::Util.url_encode(code) if code
        @client.post(url, options.to_json)
      end

      def get(code)
        @client.get("/vouchers/#{ERB::Util.url_encode(code)}")
      end

      def update(voucher_update)
        @client.put("/vouchers/#{ERB::Util.url_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/#{ERB::Util.url_encode(code)}/enable", nil)
        nil
      end

      def disable(code)
        @client.post("/vouchers/#{ERB::Util.url_encode(code)}/disable", nil)
        nil
      end

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

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

      def add_balance(code, balance)
        @client.post("/vouchers/#{ERB::Util.url_encode(code)}/balance", balance.to_json)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
voucherify-4.1.0 lib/voucherify/service/vouchers.rb
voucherify-4.0.0 lib/voucherify/service/vouchers.rb