loops_sdk 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 359ea0bf26c0f71ba07ff6e8fe435ecf6ee72c33e994aeff4040661199768a9b
4
- data.tar.gz: 62512a5d7c037aef79d56e4bc6bf13b71aaa0e11fd74ae9b5ac8b35f75779f04
3
+ metadata.gz: aeb0e30d4d199706208e701f31340143aa7eae407b04f561b6bc14fa94f05346
4
+ data.tar.gz: f48c5dc9e2e5c69314656fc20f0e49402ad803b57a01cb00ad9079a837601ce8
5
5
  SHA512:
6
- metadata.gz: e35da20e6e24efa3a37a7a8fdf09acedb6b7e333d515251c095ce8222c7635834dc6fa0acc42d2cab516253b7e101654665b76f252bcce7965cde97adbc98717
7
- data.tar.gz: c20564327c894dad4b4b97ffc65b5b5eca60f7bf5eaad5d106b00ca1e3dd3b87910fc48c47f16b3688af314ef8effe34177a843f55d141df4e6ec0eb628b1e90
6
+ metadata.gz: 526bec40bd9353f5c7c62adc9c049e70cee26eead9d81619ffe9933f5054aa4d416447a18b5d5aea966cf795784b3bf0446d132fa5c2963e16e1a975cffc5d8a
7
+ data.tar.gz: d178e957e3b3287ce91e2598d2e871fb91e4075e9d7dbd8a6002d5d4a11cb91b11e0355c031a38e71ab18c7093320ec4d8619792e4aa628411347f3d1d5b87a3
data/README.md CHANGED
@@ -207,7 +207,7 @@ This method will return a success or error message:
207
207
 
208
208
  ### Contacts.update()
209
209
 
210
- Update a contact.
210
+ Update a contact. This method will create a contact if one doesn't already exist.
211
211
 
212
212
  Note: To update a contact's email address, the contact requires a `userId` value. Then you can make a request with their `userId` and an updated email address.
213
213
 
@@ -217,7 +217,8 @@ Note: To update a contact's email address, the contact requires a `userId` value
217
217
 
218
218
  | Name | Type | Required | Notes |
219
219
  | --------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
220
- | `email` | string | Yes | The email address of the contact to update. If there is no contact with this email address, a new contact will be created using the email and properties in this request. |
220
+ | `email` | string | No | The email address of the contact to update. If there is no contact with this email address, a new contact will be created using the email and properties in this request. Required if `user_id` is not present. |
221
+ | `user_id` | string | No | The contact's unique user ID. If you use `user_id` without `email`, this value must have already been added to your contact in Loops. Required if `email` is not present. |
221
222
  | `properties` | object | No | An object containing default and any custom properties for your contact.<br />Please [add custom properties](https://loops.so/docs/contacts/properties#custom-contact-properties) in your Loops account before using them with the SDK.<br />Values can be of type `string`, `number`, `nil` (to reset a value), `boolean` or `date` ([see allowed date formats](https://loops.so/docs/contacts/properties#dates)). |
222
223
  | `mailing_lists` | object | No | An object of mailing list IDs and boolean subscription statuses. |
223
224
 
@@ -240,6 +241,14 @@ response = LoopsSdk::Contacts.update(
240
241
  userId: "1234",
241
242
  }
242
243
  )
244
+
245
+ # Subscribing a contact to a mailing list
246
+ response = LoopsSdk::Contacts.update(
247
+ email: "hello@gmail.com",
248
+ mailing_lists: {
249
+ cm06f5v0e45nf0ml5754o9cix: true,
250
+ }
251
+ )
243
252
  ```
244
253
 
245
254
  #### Response
@@ -539,6 +548,7 @@ Send an event to trigger an email in Loops. [Read more about events](https://loo
539
548
  | `contact_properties` | object | No | An object containing contact properties, which will be updated or added to the contact when the event is received.<br />Please [add custom properties](https://loops.so/docs/contacts/properties#custom-contact-properties) in your Loops account before using them with the SDK.<br />Values can be of type `string`, `number`, `nil` (to reset a value), `boolean` or `date` ([see allowed date formats](https://loops.so/docs/contacts/properties#dates)). |
540
549
  | `event_properties` | object | No | An object containing event properties, which will be made available in emails that are triggered by this event.<br />Values can be of type `string`, `number`, `boolean` or `date` ([see allowed date formats](https://loops.so/docs/events/properties#important-information-about-event-properties)). |
541
550
  | `mailing_lists` | object | No | An object of mailing list IDs and boolean subscription statuses. |
551
+ | `headers` | object | No | Additional headers to send with the request. |
542
552
 
543
553
  #### Examples
544
554
 
@@ -575,6 +585,15 @@ response = LoopsSdk::Events.send(
575
585
  plan: "pro",
576
586
  },
577
587
  )
588
+
589
+ # Example with Idempotency-Key header
590
+ response = LoopsSdk::Events.send(
591
+ event_name: "signup",
592
+ email: "hello@gmail.com",
593
+ headers: {
594
+ "Idempotency-Key" => "550e8400-e29b-41d4-a716-446655440000"
595
+ },
596
+ )
578
597
  ```
579
598
 
580
599
  #### Response
@@ -608,12 +627,13 @@ Send a transactional email to a contact. [Learn about sending transactional emai
608
627
  | ---------------------------- | -------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
609
628
  | `transactional_id` | string | Yes | The ID of the transactional email to send. |
610
629
  | `email` | string | Yes | The email address of the recipient. |
611
- | `add_to_audience` | boolean | No | If `true`, a contact will be created in your audience using the `email` value (if a matching contact doesnt already exist). |
630
+ | `add_to_audience` | boolean | No | If `true`, a contact will be created in your audience using the `email` value (if a matching contact doesn't already exist). |
612
631
  | `data_variables` | object | No | An object containing data as defined by the data variables added to the transactional email template.<br />Values can be of type `string` or `number`. |
613
632
  | `attachments` | object[] | No | A list of attachments objects.<br />**Please note**: Attachments need to be enabled on your account before using them with the API. [Read more](https://loops.so/docs/transactional/attachments) |
614
633
  | `attachments[].filename` | string | No | The name of the file, shown in email clients. |
615
634
  | `attachments[].content_type` | string | No | The MIME type of the file. |
616
635
  | `attachments[].data` | string | No | The base64-encoded content of the file. |
636
+ | `headers` | object | No | Additional headers to send with the request. |
617
637
 
618
638
  #### Examples
619
639
 
@@ -626,6 +646,18 @@ response = LoopsSdk::Transactional.send(
626
646
  },
627
647
  )
628
648
 
649
+ # Example with Idempotency-Key header
650
+ response = LoopsSdk::Transactional.send(
651
+ transactional_id: "clfq6dinn000yl70fgwwyp82l",
652
+ email: "hello@gmail.com",
653
+ data_variables: {
654
+ loginUrl: "https://myapp.com/login/",
655
+ },
656
+ headers: {
657
+ "Idempotency-Key" => "550e8400-e29b-41d4-a716-446655440000"
658
+ },
659
+ )
660
+
629
661
  # Please contact us to enable attachments on your account.
630
662
  response = LoopsSdk::Transactional.send(
631
663
  transactional_id: "clfq6dinn000yl70fgwwyp82l",
@@ -21,19 +21,15 @@ module LoopsSdk
21
21
  end
22
22
 
23
23
  def make_request(method:, path:, headers: {}, params: {}, body: nil)
24
- # Merge default headers with request-specific headers
25
24
  merged_headers = LoopsSdk.configuration.connection.headers.merge(headers)
26
-
27
- response = LoopsSdk.configuration.connection.send(
28
- method: method,
29
- path: path,
30
- headers: merged_headers,
31
- params: params,
32
- body: body
33
- ) do |req|
34
- req.body = body.to_json if body
35
- req
25
+
26
+ response = LoopsSdk.configuration.connection.send(method) do |req|
27
+ req.url path
28
+ req.headers = merged_headers
29
+ req.params = params
30
+ req.body = body ? body.to_json : nil
36
31
  end
32
+
37
33
  handle_response(response)
38
34
  end
39
35
  end
@@ -11,9 +11,12 @@ module LoopsSdk
11
11
  make_request(method: :post, path: "v1/contacts/create", body: contact_data)
12
12
  end
13
13
 
14
- def update(email:, properties: {}, mailing_lists: {})
14
+ def update(email: nil, user_id: nil, properties: {}, mailing_lists: {})
15
+ raise ArgumentError, "You must provide an email or user_id value." if email.nil? && user_id.nil?
16
+
15
17
  contact_data = {
16
18
  email: email,
19
+ userId: user_id,
17
20
  mailingLists: mailing_lists
18
21
  }.merge(properties)
19
22
  make_request(method: :put, path: "v1/contacts/update", body: contact_data)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LoopsSdk
4
- VERSION = "1.2.0"
4
+ VERSION = "2.0.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loops_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Rowden
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-05-15 00:00:00.000000000 Z
11
+ date: 2025-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday