Class: WooCommerce::CouponsResource
- Inherits:
-
Resource
- Object
- Resource
- WooCommerce::CouponsResource
show all
- Defined in:
- lib/woo_commerce/resources/coupons.rb
Instance Attribute Summary
Attributes inherited from Resource
#client
Instance Method Summary
collapse
Methods inherited from Resource
#initialize
Instance Method Details
#create(code:, discount_type:, amount:, **params) ⇒ Object
13
14
15
16
|
# File 'lib/woo_commerce/resources/coupons.rb', line 13
def create(code:, discount_type:, amount:, **params)
attributes = {code: code, discount_type: discount_type, amount: amount.to_s}
Coupon.new post_request("coupons", body: attributes.merge(params)).body
end
|
#delete(id:) ⇒ Object
22
23
24
25
|
# File 'lib/woo_commerce/resources/coupons.rb', line 22
def delete(id:)
response = delete_request("coupons/#{id}", params: {force: true})
return true if response.success?
end
|
#list(**params) ⇒ Object
4
5
6
7
|
# File 'lib/woo_commerce/resources/coupons.rb', line 4
def list(**params)
response = get_request("coupons", params: params)
Collection.from_response(response, type: Coupon)
end
|
#retrieve(id:) ⇒ Object
9
10
11
|
# File 'lib/woo_commerce/resources/coupons.rb', line 9
def retrieve(id:)
Coupon.new get_request("coupons/#{id}").body
end
|
#update(id:, **params) ⇒ Object
18
19
20
|
# File 'lib/woo_commerce/resources/coupons.rb', line 18
def update(id:, **params)
Coupon.new put_request("coupons/#{id}", body: params).body
end
|