Class: Gameball::Coupon
- Inherits:
-
Object
- Object
- Gameball::Coupon
- Defined in:
- lib/gameball/models/coupon.rb
Class Method Summary collapse
- .create_discount_coupon(body) ⇒ Object
- .redeem_discount_coupon(body) ⇒ Object
- .validate_discount_coupon(body) ⇒ Object
Class Method Details
.create_discount_coupon(body) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/gameball/models/coupon.rb', line 3 def self.create_discount_coupon(body) # Validating keys in incoming body Gameball::Utils.validate(body, ["playerUniqueId"], ["startAt", "endsAt", "entitledCollectionIds", "entitledProductIds", "oncePerCustomer", "prerequisiteQuantityRange", "prerequisiteShippingPriceRange", "prerequisiteSubtotalRange", "prerequisiteCollectionIds", "prerequisiteProductIds", "code", "usageLimit", "value", "valueType", "cap"]) body[:transactionTime] = Time.now.utc body["hash"] = Gameball::Utils::hashBody(playerUniqueId: body[:playerUniqueId]) res = Gameball::Utils::request("post", "/Integrations/Coupon", body) # Check for HTTP Success and throws error if not success unless res.kind_of? Net::HTTPSuccess if res.kind_of? Net::HTTPInternalServerError raise Gameball::GameballError.new("An Internal Server Error has occurred") else raise Gameball::GameballError.new(res.body) end else return res end end |
.redeem_discount_coupon(body) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/gameball/models/coupon.rb', line 40 def self.redeem_discount_coupon(body) # Check for HTTP Success and throws error if not success Gameball::Utils.validate(body, ["playerUniqueId", "code"]) body[:transactionTime] = Time.now.utc body["hash"] = Gameball::Utils::hashBody(playerUniqueId: body[:playerUniqueId]) res = Gameball::Utils::request("post", "/Integrations/Coupon/Redeem", body) # Check for HTTP Success and throws error if not success unless res.kind_of? Net::HTTPSuccess if res.kind_of? Net::HTTPInternalServerError raise Gameball::GameballError.new("An Internal Server Error has occurred") else raise Gameball::GameballError.new(res.body) end else return true end end |
.validate_discount_coupon(body) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/gameball/models/coupon.rb', line 23 def self.validate_discount_coupon(body) # Validating keys in incoming body Gameball::Utils.validate(body, ["playerUniqueId", "code"]) body[:transactionTime] = Time.now.utc body["hash"] = Gameball::Utils::hashBody(playerUniqueId: body[:playerUniqueId]) res = Gameball::Utils::request("post", "/Integrations/Coupon/Validate", body) # Check for HTTP Success and throws error if not success unless res.kind_of? Net::HTTPSuccess if res.kind_of? Net::HTTPInternalServerError raise Gameball::GameballError.new("An Internal Server Error has occurred") else raise Gameball::GameballError.new(res.body) end else return res end end |