Module: Klaviyo::Lists::ApiOperations
- Included in:
- Klaviyo::Lists
- Defined in:
- lib/klaviyo/lists/api_operations.rb
Overview
Instance Method Summary collapse
- #all(client:, page: 0, per: 50) ⇒ Object
- #batch_subscribe(client:, id:, batch: [], confirm_optin: false) ⇒ Object
- #create(client:, name:, list_type: 'standart') ⇒ Object
- #delete(client:, id:) ⇒ Object
- #find(client:, id:) ⇒ Object
- #include_member_in_list?(client:, id:, email:) ⇒ Boolean
- #include_member_in_segment?(client:, segment_id:, email:) ⇒ Boolean
- #subscribe(client:, id:, email:, properties: {}, confirm_optin: false) ⇒ Object
- #unsubscribe(client:, id:, email:, ts: Time.now.to_i) ⇒ Object
- #unsubscribes(client:, id:, reason: 'unsubscribed', sort: 'asc') ⇒ Object
- #update(client:, id:, name:) ⇒ Object
Instance Method Details
#all(client:, page: 0, per: 50) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/klaviyo/lists/api_operations.rb', line 7 def all(client:, page: 0, per: 50) Klaviyo::Resource.build_collection( client.conn.get('/api/v1/lists', api_key: client.api_key, page: page, count: per ).body ) end |
#batch_subscribe(client:, id:, batch: [], confirm_optin: false) ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/klaviyo/lists/api_operations.rb', line 96 def batch_subscribe(client:, id:, batch: [], confirm_optin: false) client.conn.post( "/api/v1/list/#{id}/members/batch", api_key: client.api_key, batch: JSON.generate(batch), confirm_optin: confirm_optin ) end |
#create(client:, name:, list_type: 'standart') ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/klaviyo/lists/api_operations.rb', line 24 def create(client:, name:, list_type: 'standart') Klaviyo::Resource.build( client.conn.post('/api/v1/lists', api_key: client.api_key, name: name, list_type: list_type ).body ) end |
#delete(client:, id:) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/klaviyo/lists/api_operations.rb', line 43 def delete(client:, id:) Klaviyo::Resource.build( client.conn.delete("/api/v1/list/#{id}", api_key: client.api_key ).body ) end |
#find(client:, id:) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/klaviyo/lists/api_operations.rb', line 16 def find(client:, id:) Klaviyo::Resource.build( client.conn.get("/api/v1/list/#{id}", api_key: client.api_key ).body ) end |
#include_member_in_list?(client:, id:, email:) ⇒ Boolean
51 52 53 54 55 56 57 58 |
# File 'lib/klaviyo/lists/api_operations.rb', line 51 def include_member_in_list?(client:, id:, email:) Klaviyo::Resource.build_collection( client.conn.get("/api/v1/list/#{id}/members", api_key: client.api_key, email: email ).body ) end |
#include_member_in_segment?(client:, segment_id:, email:) ⇒ Boolean
60 61 62 63 64 65 66 67 |
# File 'lib/klaviyo/lists/api_operations.rb', line 60 def include_member_in_segment?(client:, segment_id:, email:) Klaviyo::Resource.build_collection( client.conn.get("/api/v1/segment/#{segment_id}/members", api_key: client.api_key, email: email ).body ) end |
#subscribe(client:, id:, email:, properties: {}, confirm_optin: false) ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/klaviyo/lists/api_operations.rb', line 72 def subscribe(client:, id:, email:, properties: {}, confirm_optin: false) Klaviyo::Resource.build( client.conn.post("/api/v1/list/#{id}/members", api_key: client.api_key, email: email, properties: properties, confirm_optin: confirm_optin ).body ) end |
#unsubscribe(client:, id:, email:, ts: Time.now.to_i) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/klaviyo/lists/api_operations.rb', line 83 def unsubscribe(client:, id:, email:, ts: Time.now.to_i) Klaviyo::Resource.build( client.conn.post("/api/v1/list/#{id}/members/exclude", api_key: client.api_key, email: email, timestamp: ts ).body ) end |
#unsubscribes(client:, id:, reason: 'unsubscribed', sort: 'asc') ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/klaviyo/lists/api_operations.rb', line 109 def unsubscribes(client:, id:, reason: 'unsubscribed', sort: 'asc') client.conn.post( "/api/v1/list/#{id}/exclusions", api_key: client.api_key, reason: reason, sort: sort ) end |
#update(client:, id:, name:) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/klaviyo/lists/api_operations.rb', line 34 def update(client:, id:, name:) Klaviyo::Resource.build( client.conn.put("/api/v1/list/#{id}", api_key: client.api_key, name: name ).body ) end |