Class: Voucherify::Service::Validations

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Validations

Returns a new instance of Validations.



8
9
10
# File 'lib/voucherify/service/validations.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/validations.rb', line 6

def client
  @client
end

Instance Method Details

#validate(code, context = {}) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/voucherify/service/validations.rb', line 16

def validate(code, context = {})
  if code.is_a? Hash
    context = code
    return @client.promotions.validate(context)
  end
  @client.validations.validate_voucher(code, context)
end

#validate_voucher(code, context = {}) ⇒ Object



12
13
14
# File 'lib/voucherify/service/validations.rb', line 12

def validate_voucher(code, context = {})
  @client.post("/vouchers/#{URI.encode(code)}/validate", context.to_json)
end