loops_sdk 1.1.0 → 1.2.1

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: 8eeddad6948c305215fe8efe6bd218550fad021aaa12615f6e32b8d69d552fda
4
- data.tar.gz: b4632c42a4762b587fc5a96b05c8aa25f734823bb2fe5de31a181556a6ac976d
3
+ metadata.gz: cef2e34971e3c98b0ceaf334bb80415ab912b3b3c384f9bc0f3daee486af3137
4
+ data.tar.gz: 43bd7500763bdc8eec606220a122cd5c2acb9ce24e3fa7070917fb13ffa0c541
5
5
  SHA512:
6
- metadata.gz: e9cff4116be11b5c86aa25137b0fe832ee1dd1875a33a3625554a094048781b2637388ed6065c8cd23be28d6b1771567f1fd5704c63f2f985aae4f3abd5b9f1f
7
- data.tar.gz: fc376fc43f139688c1e76bbe5a06cad0c39e6b3762f481636438a33e1548fa9af6eb1ea90f228384cccad162acb88aec927f50cf1487d35e88e18cdba1abc893
6
+ metadata.gz: 99dffd773f4da8f24ea7679433c8e1c239d96f2b8df98b8fbf7d93cd732b6ca241fe6e1380864a0c74439a31b756b4671d908d8dd2c2cffec43c88347938772f
7
+ data.tar.gz: '0128fc22eac586c9c3500283493b5519ab279cf5d46fcc46ea92e15c2d057eb106a75fdd9322413ae101d4b460fe0dd33ec6cc244ea8c9751b3cc76903b217c8'
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Loops Ruby SDK
2
2
 
3
+ [![Gem Total Downloads](https://img.shields.io/gem/dt/loops_sdk?style=social)](https://rubygems.org/gems/loops_sdk)
4
+
3
5
  ## Introduction
4
6
 
5
7
  This is the official Ruby SDK for [Loops](https://loops.so), an email platform for modern software companies.
@@ -537,6 +539,7 @@ Send an event to trigger an email in Loops. [Read more about events](https://loo
537
539
  | `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)). |
538
540
  | `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)). |
539
541
  | `mailing_lists` | object | No | An object of mailing list IDs and boolean subscription statuses. |
542
+ | `headers` | object | No | Additional headers to send with the request. |
540
543
 
541
544
  #### Examples
542
545
 
@@ -573,6 +576,15 @@ response = LoopsSdk::Events.send(
573
576
  plan: "pro",
574
577
  },
575
578
  )
579
+
580
+ # Example with Idempotency-Key header
581
+ response = LoopsSdk::Events.send(
582
+ event_name: "signup",
583
+ email: "hello@gmail.com",
584
+ headers: {
585
+ "Idempotency-Key" => "550e8400-e29b-41d4-a716-446655440000"
586
+ },
587
+ )
576
588
  ```
577
589
 
578
590
  #### Response
@@ -606,12 +618,13 @@ Send a transactional email to a contact. [Learn about sending transactional emai
606
618
  | ---------------------------- | -------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
607
619
  | `transactional_id` | string | Yes | The ID of the transactional email to send. |
608
620
  | `email` | string | Yes | The email address of the recipient. |
609
- | `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). |
621
+ | `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). |
610
622
  | `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`. |
611
623
  | `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) |
612
624
  | `attachments[].filename` | string | No | The name of the file, shown in email clients. |
613
625
  | `attachments[].content_type` | string | No | The MIME type of the file. |
614
626
  | `attachments[].data` | string | No | The base64-encoded content of the file. |
627
+ | `headers` | object | No | Additional headers to send with the request. |
615
628
 
616
629
  #### Examples
617
630
 
@@ -624,6 +637,18 @@ response = LoopsSdk::Transactional.send(
624
637
  },
625
638
  )
626
639
 
640
+ # Example with Idempotency-Key header
641
+ response = LoopsSdk::Transactional.send(
642
+ transactional_id: "clfq6dinn000yl70fgwwyp82l",
643
+ email: "hello@gmail.com",
644
+ data_variables: {
645
+ loginUrl: "https://myapp.com/login/",
646
+ },
647
+ headers: {
648
+ "Idempotency-Key" => "550e8400-e29b-41d4-a716-446655440000"
649
+ },
650
+ )
651
+
627
652
  # Please contact us to enable attachments on your account.
628
653
  response = LoopsSdk::Transactional.send(
629
654
  transactional_id: "clfq6dinn000yl70fgwwyp82l",
@@ -736,6 +761,12 @@ response = LoopsSdk::Transactional.list(perPage: 15)
736
761
 
737
762
  ---
738
763
 
764
+ ## Testing
765
+
766
+ Run tests with `bundle exec rspec`.
767
+
768
+ ---
769
+
739
770
  ## Contributing
740
771
 
741
772
  Bug reports and pull requests are welcome. Please read our [Contributing Guidelines](CONTRIBUTING.md).
@@ -4,7 +4,7 @@ module LoopsSdk
4
4
  class ApiKey < Base
5
5
  class << self
6
6
  def test
7
- make_request(:get, "v1/api-key")
7
+ make_request(method: :get, path: "v1/api-key")
8
8
  end
9
9
  end
10
10
  end
@@ -20,10 +20,16 @@ module LoopsSdk
20
20
  end
21
21
  end
22
22
 
23
- def make_request(method, path, params = {}, body = nil)
24
- response = LoopsSdk.configuration.connection.send(method, path, params) do |req|
25
- req.body = body.to_json if body
23
+ def make_request(method:, path:, headers: {}, params: {}, body: nil)
24
+ merged_headers = LoopsSdk.configuration.connection.headers.merge(headers)
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
26
31
  end
32
+
27
33
  handle_response(response)
28
34
  end
29
35
  end
@@ -8,11 +8,11 @@ module LoopsSdk
8
8
  name: name,
9
9
  type: type
10
10
  }
11
- make_request(:post, "v1/contacts/properties", {}, body)
11
+ make_request(method: :post, path: "v1/contacts/properties", body: body)
12
12
  end
13
13
  def list(list: nil)
14
14
  raise ArgumentError, "List value must be nil, 'custom' or 'all'." unless [nil, "custom", "all"].include?(list)
15
- make_request(:get, "v1/contacts/properties", {list: list || "all"})
15
+ make_request(method: :get, path: "v1/contacts/properties", params: { list: list || "all" })
16
16
  end
17
17
  end
18
18
  end
@@ -8,7 +8,7 @@ module LoopsSdk
8
8
  email: email,
9
9
  mailingLists: mailing_lists
10
10
  }.merge(properties)
11
- make_request(:post, "v1/contacts/create", {}, contact_data)
11
+ make_request(method: :post, path: "v1/contacts/create", body: contact_data)
12
12
  end
13
13
 
14
14
  def update(email:, properties: {}, mailing_lists: {})
@@ -16,7 +16,7 @@ module LoopsSdk
16
16
  email: email,
17
17
  mailingLists: mailing_lists
18
18
  }.merge(properties)
19
- make_request(:put, "v1/contacts/update", {}, contact_data)
19
+ make_request(method: :put, path: "v1/contacts/update", body: contact_data)
20
20
  end
21
21
 
22
22
  def find(email: nil, user_id: nil)
@@ -24,7 +24,7 @@ module LoopsSdk
24
24
  raise ArgumentError, "You must provide an email or user_id value." if email.nil? && user_id.nil?
25
25
 
26
26
  params = email ? { email: email } : { userId: user_id }
27
- make_request(:get, "v1/contacts/find", params)
27
+ make_request(method: :get, path: "v1/contacts/find", params: params)
28
28
  end
29
29
 
30
30
  def delete(email: nil, user_id: nil)
@@ -32,7 +32,7 @@ module LoopsSdk
32
32
  raise ArgumentError, "You must provide an email or user_id value." if email.nil? && user_id.nil?
33
33
 
34
34
  body = email ? { email: email } : { userId: user_id }
35
- make_request(:post, "v1/contacts/delete", {}, body)
35
+ make_request(method: :post, path: "v1/contacts/delete", body: body)
36
36
  end
37
37
  end
38
38
  end
@@ -3,7 +3,7 @@
3
3
  module LoopsSdk
4
4
  class Events < Base
5
5
  class << self
6
- def send(event_name:, email: nil, user_id: nil, contact_properties: {}, event_properties: {}, mailing_lists: {})
6
+ def send(event_name:, email: nil, user_id: nil, contact_properties: {}, event_properties: {}, mailing_lists: {}, headers: {})
7
7
  raise ArgumentError, "You must provide an email or user_id value." if email.nil? && user_id.nil?
8
8
 
9
9
  event_data = {
@@ -13,7 +13,7 @@ module LoopsSdk
13
13
  eventProperties: event_properties.compact,
14
14
  mailingLists: mailing_lists.compact
15
15
  }.merge(contact_properties)
16
- make_request(:post, "v1/events/send", {}, event_data)
16
+ make_request(method: :post, path: "v1/events/send", headers: headers, body: event_data)
17
17
  end
18
18
  end
19
19
  end
@@ -4,7 +4,7 @@ module LoopsSdk
4
4
  class MailingLists < Base
5
5
  class << self
6
6
  def list
7
- make_request(:get, "v1/lists")
7
+ make_request(method: :get, path: "v1/lists")
8
8
  end
9
9
  end
10
10
  end
@@ -4,9 +4,9 @@ module LoopsSdk
4
4
  class Transactional < Base
5
5
  class << self
6
6
  def list(perPage: 20, cursor: nil)
7
- make_request(:get, "v1/transactional", { perPage: perPage, cursor: cursor })
7
+ make_request(method: :get, path: "v1/transactional", params: { perPage: perPage, cursor: cursor })
8
8
  end
9
- def send(transactional_id:, email:, add_to_audience: false, data_variables: {}, attachments: [])
9
+ def send(transactional_id:, email:, add_to_audience: false, data_variables: {}, attachments: [], headers: {})
10
10
  attachments = attachments.map do |attachment|
11
11
  attachment.transform_keys { |key| key == :content_type ? :contentType : key }
12
12
  end
@@ -17,7 +17,7 @@ module LoopsSdk
17
17
  dataVariables: data_variables,
18
18
  attachments: attachments
19
19
  }.compact
20
- make_request(:post, "v1/transactional", {}, email_data)
20
+ make_request(method: :post, path: "v1/transactional", headers: headers, body: email_data)
21
21
  end
22
22
  end
23
23
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LoopsSdk
4
- VERSION = "1.1.0"
4
+ VERSION = "1.2.1"
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.1.0
4
+ version: 1.2.1
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-02-27 00:00:00.000000000 Z
11
+ date: 2025-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday