Class: PatchRetention::Memberships
- Inherits:
-
Object
- Object
- PatchRetention::Memberships
- Defined in:
- lib/patch_retention/memberships.rb
Class Method Summary collapse
- .create(contact_id:, product_id:, start_at: nil, end_at: nil, next_billing_at: nil, external_id: nil, tags: nil, data: nil, config: nil) ⇒ Object
- .find(membership_id:, config: nil) ⇒ Object
- .update(membership_id:, start_at: nil, end_at: nil, external_id: nil, external_data: nil, tags: nil, status: nil, config: nil) ⇒ Object
Class Method Details
.create(contact_id:, product_id:, start_at: nil, end_at: nil, next_billing_at: nil, external_id: nil, tags: nil, data: nil, config: nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/patch_retention/memberships.rb', line 6 def create(contact_id:, product_id:, start_at: nil, end_at: nil, next_billing_at: nil, external_id: nil, tags: nil, data: nil, config: nil) payload = { contact_id: contact_id, product_id: product_id, } payload[:start_at] = start_at if start_at payload[:end_at] = end_at if end_at payload[:next_billing_at] = next_billing_at if next_billing_at payload[:external_id] = external_id if external_id payload[:tags] = if payload[:data] = data if data response = PatchRetention.connection(config).post("/v2/memberships") do |req| req.body = payload end response.body rescue Faraday::Error => e # You might want to handle different types of Faraday errors differently # or raise a custom error class raise Error, "Failed to create membership: #{e.}" end |
.find(membership_id:, config: nil) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/patch_retention/memberships.rb', line 49 def find(membership_id:, config: nil) response = PatchRetention.connection(config).get("/v2/memberships/#{membership_id}") response.body rescue Faraday::Error => e raise Error, "Failed to find membership: #{e.}" end |
.update(membership_id:, start_at: nil, end_at: nil, external_id: nil, external_data: nil, tags: nil, status: nil, config: nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/patch_retention/memberships.rb', line 30 def update(membership_id:, start_at: nil, end_at: nil, external_id: nil, external_data: nil, tags: nil, status: nil, config: nil) payload = {} payload[:start_at] = start_at if start_at payload[:end_at] = end_at if end_at payload[:external_id] = external_id if external_id payload[:external_data] = external_data if external_data payload[:tags] = if payload[:status] = status if status response = PatchRetention.connection(config).patch("/v2/memberships/#{membership_id}") do |req| req.body = payload end response.body rescue Faraday::Error => e raise Error, "Failed to update membership: #{e.}" end |