Class: Voucherify::Service::Vouchers

Inherits:
Object
  • Object
show all
Defined in:
lib/voucherify/service/vouchers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Vouchers

Returns a new instance of Vouchers.



8
9
10
# File 'lib/voucherify/service/vouchers.rb', line 8

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/voucherify/service/vouchers.rb', line 6

def client
  @client
end

Instance Method Details

#add_balance(code, balance) ⇒ Object



49
50
51
# File 'lib/voucherify/service/vouchers.rb', line 49

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

#create(code, options = {}) ⇒ Object



12
13
14
15
16
# File 'lib/voucherify/service/vouchers.rb', line 12

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

#delete(code, params = {}) ⇒ Object



40
41
42
43
# File 'lib/voucherify/service/vouchers.rb', line 40

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

#disable(code) ⇒ Object



35
36
37
38
# File 'lib/voucherify/service/vouchers.rb', line 35

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

#enable(code) ⇒ Object



30
31
32
33
# File 'lib/voucherify/service/vouchers.rb', line 30

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

#get(code) ⇒ Object



18
19
20
# File 'lib/voucherify/service/vouchers.rb', line 18

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

#import(vouchers) ⇒ Object



45
46
47
# File 'lib/voucherify/service/vouchers.rb', line 45

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

#list(query) ⇒ Object



26
27
28
# File 'lib/voucherify/service/vouchers.rb', line 26

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

#update(voucher_update) ⇒ Object



22
23
24
# File 'lib/voucherify/service/vouchers.rb', line 22

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