Class: LemonSqueezy::Customer
- Defined in:
- lib/lemon_squeezy/models/customer.rb
Class Method Summary collapse
- .create(store_id:, name:, email:, **params) ⇒ Object
- .list(**params) ⇒ Object
- .retrieve(id:) ⇒ Object
- .update(id:, **params) ⇒ Object
Methods inherited from Object
Constructor Details
This class inherits a constructor from LemonSqueezy::Object
Class Method Details
.create(store_id:, name:, email:, **params) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/lemon_squeezy/models/customer.rb', line 16 def create(store_id:, name:, email:, **params) body = { data: { type: "customers", attributes: { name: name, email: email }.merge(params), relationships: { store: { data: { type: "stores", id: store_id.to_s } }, } } } response = Client.post_request("customers", body: body.to_json) Customer.new(response.body["data"]) if response.success? end |
.list(**params) ⇒ Object
6 7 8 9 |
# File 'lib/lemon_squeezy/models/customer.rb', line 6 def list(**params) response = Client.get_request("customers", params: Client.build_list_request_params(params)) Collection.from_response(response, type: Customer) end |
.retrieve(id:) ⇒ Object
11 12 13 14 |
# File 'lib/lemon_squeezy/models/customer.rb', line 11 def retrieve(id:) response = Client.get_request("customers/#{id}") Customer.new(response.body["data"]) if response.success? end |
.update(id:, **params) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/lemon_squeezy/models/customer.rb', line 38 def update(id:, **params) body = { data: { type: "customers", id: id.to_s, attributes: params } } response = Client.patch_request("customers/#{id}", body: body.to_json) Customer.new(response.body["data"]) if response.success? end |