Class: Voucherify::Service::LoyaltyRewards

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ LoyaltyRewards

Returns a new instance of LoyaltyRewards.



78
79
80
# File 'lib/voucherify/service/loyalties.rb', line 78

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



76
77
78
# File 'lib/voucherify/service/loyalties.rb', line 76

def client
  @client
end

Instance Method Details

#create(loyalty_id, assignments) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/voucherify/service/loyalties.rb', line 86

def create(loyalty_id, assignments)
  payload = assignments
  if assignments.is_a? Hash
    payload = [ assignments ]
  end
  @client.post("/loyalties/#{URI.encode(loyalty_id)}/rewards", payload.to_json)
end

#delete(loyalty_id, assignment_id) ⇒ Object



98
99
100
101
# File 'lib/voucherify/service/loyalties.rb', line 98

def delete(loyalty_id, assignment_id)
  @client.delete("/loyalties/#{URI.encode(loyalty_id)}/rewards/#{URI.encode(assignment_id)}")
  nil
end

#list(loyalty_id, query = {}) ⇒ Object



82
83
84
# File 'lib/voucherify/service/loyalties.rb', line 82

def list(loyalty_id, query = {})
  @client.get("/loyalties/#{URI.encode(loyalty_id)}/rewards", query)
end

#update(loyalty_id, assignment_id, assignment) ⇒ Object



94
95
96
# File 'lib/voucherify/service/loyalties.rb', line 94

def update(loyalty_id, assignment_id, assignment)
  @client.put("/loyalties/#{URI.encode(loyalty_id)}/rewards/#{URI.encode(assignment_id)}", assignment.to_json)
end