Sha256: 3d31e01f620ed71e2f51152e144d41ea9c99e9bfb3bb8c087512b2472a1b8ed9

Contents?: true

Size: 1.25 KB

Versions: 11

Compression:

Stored size: 1.25 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

      def add_balance(code, balance)
        @client.post("/vouchers/#{URI.encode(code)}/balance", balance.to_json)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

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