Class: Celery::Coupon

Inherits:
Object
  • Object
show all
Defined in:
lib/celery/resources/coupon.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api) ⇒ Coupon

Returns a new instance of Coupon.



5
6
7
# File 'lib/celery/resources/coupon.rb', line 5

def initialize(api)
  @api = api
end

Instance Attribute Details

#apiObject

Returns the value of attribute api.



3
4
5
# File 'lib/celery/resources/coupon.rb', line 3

def api
  @api
end

Instance Method Details

#all(params = {}) ⇒ JSON

Returns a list of coupons you have. The coupons are returned in sorted order, with the most recent coupons appearing first.

Examples:


coupons = celery.coupon.all(limit: 25, skip: 2, sort: 'created', order: 'asc')
coupons["total"]
=> 28

Parameters:

  • limit (Integer)

    (optional) Limit the number of results.

  • skip (Integer)

    (optional) Skip n results.

  • sort (String)

    (optional) Field name to sort on.

  • order (String)

    (optional) Either ‘asc` or `desc`.

Returns:

  • (JSON)

    A JSON object with the following attributes:

    • total [Integer]

    • count [Integer]

    • offset [Integer]

    • limit [Integer]

    • has_more [Boolean]

    • coupons [Array]

See Also:



33
34
35
# File 'lib/celery/resources/coupon.rb', line 33

def all(params = {})
  @api.get("coupons", query: params)
end

#destroy(coupon_id) ⇒ JSON

Deletes an existing coupon object.

Examples:


result = celery.coupon.destroy("123abc")
result["status"]
=> true

Parameters:

  • coupon_id (String)

    (required) The identifier of the Coupon to be deleted.

Returns:

  • (JSON)

    A JSON object with the following attributes:

    • status [Boolean]

See Also:



132
133
134
# File 'lib/celery/resources/coupon.rb', line 132

def destroy(coupon_id)
  @api.delete("coupons/#{coupon_id}")
end

#find(coupon_id) ⇒ JSON

Retrieves a coupon that has previously been created.

Examples:


coupon = celery.coupon.find("123abc")
coupon["code"]
=> "Test Coupon Code"

Parameters:

  • coupon_id (String)

    (required) The identifier of the Coupon to be retrieved.

Returns:

  • (JSON)

    A Coupon object with the following attributes:

    • code [String]

    • type [String]

    • discount [Integer]

See Also:



54
55
56
# File 'lib/celery/resources/coupon.rb', line 54

def find(coupon_id)
  @api.get("coupons/#{coupon_id}")
end

#new(coupon) ⇒ JSON

Creates a new coupon object.

Examples:


coupon = {
  code: "New Coupon Code",
  type: "percent",
  discount: 10
}
new_coupon = celery.coupon.new(coupon)
new_coupon["code"]
=> "New Coupon Code"

Parameters:

  • coupon (Hash)

    A hash of coupon attributes.

Options Hash (coupon):

  • code (String) — default: required

    the coupon code.

  • type (String) — default: required

    the type of coupon.

  • discount (Integer) — default: required

    the amount discounted.

Returns:

  • (JSON)

    A Coupon object with the following attributes:

    • code [String]

    • type [String]

    • discount [Integer]

See Also:



83
84
85
# File 'lib/celery/resources/coupon.rb', line 83

def new(coupon)
  @api.post("coupons", body: {coupon: coupon})
end

#update(coupon_id, coupon) ⇒ JSON

Updates an existing coupon object.

Examples:


updated_coupon = {
  code: "Another Coupon Code",
  type: "percent",
  discount: 15
}
coupon = celery.coupon.update("123abc", updated_coupon)
coupon["code"]
=> "Another Coupon Code"

Parameters:

  • coupon_id (String)

    (required) The identifier of the Coupon to be updated.

  • coupon (Hash)

    A hash of coupon attributes.

Options Hash (coupon):

  • code (String) — default: optional

    the coupon code.

  • type (String) — default: optional

    the type of coupon.

  • discount (Integer) — default: optional

    the amount discounted.

Returns:

  • (JSON)

    A Coupon object with the following attributes:

    • code [String]

    • type [String]

    • discount [Integer]

See Also:



113
114
115
# File 'lib/celery/resources/coupon.rb', line 113

def update(coupon_id, coupon)
  @api.put("coupons/#{coupon_id}", body: {coupon: coupon})
end