loops_sdk 0.1.2 → 0.2.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: 85549597f27cc413d5ebafb39a9974172a8f2dfc613e6190c8c1a664f964006b
4
- data.tar.gz: cd13f142b86862541207dfb9c1ef2531b3712474de3f9320c2649f2fea697fa9
3
+ metadata.gz: e5cbc02e88853c1dfb986f2d18fc113badcc569865c83c21a58d42809651245c
4
+ data.tar.gz: d38a4ff09a27e949dcae803cbd9c4f143f32b8dfb7100e6e3cbdc9323d61ccb9
5
5
  SHA512:
6
- metadata.gz: aae6977f6e8664bb8fb716a28f90be6a6a6ddc5a35a14bb3c9fc9cb0ba54b91847989b36911d03d299e07b04c2e55494f07fb387ccc8bffc494d954c19194c39
7
- data.tar.gz: f156ba183d35d9825d85ff949cda127d702f84b7a878a6efae3edc73c901235c89731cdb1435f72623131c42c463ecd0ced1475674a3741c80ab1e8ca4d002db
6
+ metadata.gz: e9298ac3c8a13c8e207a1c621bd74a5370881537e11a520a85dc2b9ac7a302ece4d2b13a3997c8726b825a474391624d8f5127610823f4dbb5bb75c3bde7b90f
7
+ data.tar.gz: c3b0de412fea85c5635880c5bdf962164fac8884cd25344b46ad975125dacd89809c541ce4cc921c0e2b304b6204b12fe15455b905479b0593d093126a70c175
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v0.2.0 - Oct 29, 2024
2
+
3
+ Added rate limit handling with `RateLimitError`.
4
+
1
5
  ## v0.1.2 - Aug 16, 2024
2
6
 
3
7
  Support for resetting contact properties with `nil`.
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ - Demonstrating empathy and kindness toward other people
21
+ - Being respectful of differing opinions, viewpoints, and experiences
22
+ - Giving and gracefully accepting constructive feedback
23
+ - Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ - Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ - The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ - Trolling, insulting or derogatory comments, and personal or political attacks
33
+ - Public or private harassment
34
+ - Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ - Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,51 @@
1
+ # Contributing to Loops Ruby SDK
2
+
3
+ Thank you for your interest in contributing to Loops Ruby SDK. We welcome contributions from the community and are excited to see what you'll bring to the project.
4
+
5
+ ## Getting Started
6
+
7
+ 1. Fork the repository on GitHub.
8
+ 2. Clone your fork locally: `git clone <https://github.com/Loops-so/loops-rb.git`>
9
+ 3. Create a new branch for your feature or bug fix: `git checkout -b your-branch-name`
10
+
11
+ ## Making Changes
12
+
13
+ 1. Make your changes in your branch.
14
+ 2. Follow the coding style and conventions used in the project.
15
+ 3. Write clear, concise commit messages.
16
+ 4. Test your changes thoroughly.
17
+
18
+ ## Submitting a Pull Request
19
+
20
+ 1. Push your changes to your fork on GitHub.
21
+ 2. From your fork, open a pull request in the correct branch of the main repository.
22
+ 3. Provide a clear title and description for your pull request using our PR template.
23
+ 4. Link any relevant issues in the pull request description.
24
+
25
+ ## Code of Conduct
26
+
27
+ Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project, you agree to abide by its terms.
28
+
29
+ ## Reporting Bugs
30
+
31
+ If you find a bug, please open an issue on GitHub. Include as much detail as possible:
32
+
33
+ - A clear and descriptive title
34
+ - Steps to reproduce the issue
35
+ - Expected behavior
36
+ - Actual behavior
37
+ - Any error messages or screenshots
38
+
39
+ ## Suggesting Enhancements
40
+
41
+ We welcome suggestions for enhancements! Please open an issue on GitHub with:
42
+
43
+ - A clear and descriptive title
44
+ - A detailed description of the proposed enhancement
45
+ - Any examples or mock-ups if applicable
46
+
47
+ ## Questions?
48
+
49
+ If you have any questions, feel free to open an issue or contact the maintainers directly.
50
+
51
+ Thank you for contributing!
data/README.md CHANGED
@@ -56,6 +56,29 @@ rescue LoopsSdk::APIError => e
56
56
  end
57
57
  ```
58
58
 
59
+ ## Handling rate limits
60
+
61
+ You can use the check for rate limit issues with your requests.
62
+
63
+ You can access details about the rate limits from the `limit` and `remaining` attributes.
64
+
65
+ ```ruby
66
+ begin
67
+
68
+ response = LoopsSdk::Contacts.update(
69
+ email: "dan@loops.so"
70
+ )
71
+
72
+ render json: response
73
+
74
+ rescue LoopsSdk::RateLimitError => e
75
+ Rails.logger.error("Rate limit exceeded (#{e.limit} requests per second)")
76
+ # Code here to re-try this request
77
+ rescue LoopsSdk::APIError => e
78
+ # Handle other errors
79
+ end
80
+ ```
81
+
59
82
  ## Default contact properties
60
83
 
61
84
  Each contact in Loops has a set of default properties. These will always be returned in API results.
@@ -146,8 +169,8 @@ contact_properties = {
146
169
  favoriteColor: "Red" /* Custom property */,
147
170
  };
148
171
  mailing_lists = {
149
- list_123: true,
150
- list_456: false,
172
+ cm06f5v0e45nf0ml5754o9cix: true,
173
+ cm16k73gq014h0mmj5b6jdi9r: false,
151
174
  };
152
175
  response = LoopsSdk::Contacts.create(
153
176
  email: "hello@gmail.com",
@@ -252,7 +275,7 @@ You must use one parameter in the request.
252
275
  ```ruby
253
276
  response = LoopsSdk::Contacts.find(email: "hello@gmail.com")
254
277
 
255
- response = LoopsSdk::Contacts.find(userId: "12345")
278
+ response = LoopsSdk::Contacts.find(user_id: "12345")
256
279
  ```
257
280
 
258
281
  #### Response
@@ -272,6 +295,9 @@ If no contact is found, an empty list will be returned.
272
295
  "subscribed": true,
273
296
  "userGroup": "",
274
297
  "userId": "12345",
298
+ "mailingLists": {
299
+ "cm06f5v0e45nf0ml5754o9cix": true
300
+ },
275
301
  "favoriteColor": "Blue" /* Custom property */
276
302
  }
277
303
  ]
@@ -281,7 +307,7 @@ If no contact is found, an empty list will be returned.
281
307
 
282
308
  ### Contacts.delete()
283
309
 
284
- Delete a contact, either by email address or `userId`.
310
+ Delete a contact.
285
311
 
286
312
  [API Reference](https://loops.so/docs/api-reference/delete-contact)
287
313
 
@@ -299,7 +325,7 @@ You must use one parameter in the request.
299
325
  ```ruby
300
326
  response = LoopsSdk::Contacts.delete(email: "hello@gmail.com")
301
327
 
302
- response = LoopsSdk::Contacts.delete(userId: "12345")
328
+ response = LoopsSdk::Contacts.delete(user_id: "12345")
303
329
  ```
304
330
 
305
331
  #### Response
@@ -340,19 +366,21 @@ response = LoopsSdk::MailingLists.list
340
366
 
341
367
  #### Response
342
368
 
343
- This method will return a list of mailing list objects containing `id` and `name` attributes.
369
+ This method will return a list of mailing list objects containing `id`, `name` and `isPublic` attributes.
344
370
 
345
371
  If your account has no mailing lists, an empty list will be returned.
346
372
 
347
373
  ```json
348
374
  [
349
375
  {
350
- "id": "list_123",
351
- "name": "Main list"
376
+ "id": "cm06f5v0e45nf0ml5754o9cix",
377
+ "name": "Main list",
378
+ "isPublic": true
352
379
  },
353
380
  {
354
- "id": "list_456",
355
- "name": "Investors"
381
+ "id": "cm16k73gq014h0mmj5b6jdi9r",
382
+ "name": "Investors",
383
+ "isPublic": false
356
384
  }
357
385
  ]
358
386
  ```
@@ -392,8 +420,8 @@ response = LoopsSdk::Events.send(
392
420
  signupDate: "2024-03-21T10:09:23Z",
393
421
  },
394
422
  mailing_lists: {
395
- list_123: true,
396
- list_456: false,
423
+ cm06f5v0e45nf0ml5754o9cix: true,
424
+ cm16k73gq014h0mmj5b6jdi9r: false,
397
425
  },
398
426
  })
399
427
 
@@ -553,4 +581,4 @@ If your account has no custom fields, an empty list will be returned.
553
581
 
554
582
  ## Contributing
555
583
 
556
- Bug reports and pull requests are welcome on GitHub at https://github.com/Loops-so/loops-rb.
584
+ Bug reports and pull requests are welcome. Please read our [Contributing Guidelines](CONTRIBUTING.md).
@@ -9,6 +9,10 @@ module LoopsSdk
9
9
  case response.status
10
10
  when 200
11
11
  JSON.parse(response.body)
12
+ when 429
13
+ limit = response.headers["x-ratelimit-limit"]
14
+ remaining = response.headers["x-ratelimit-remaining"]
15
+ raise RateLimitError.new(limit, remaining)
12
16
  when 400, 404, 405, 409, 500
13
17
  raise APIError.new(response.status, response.body)
14
18
  else
@@ -25,8 +29,16 @@ module LoopsSdk
25
29
  end
26
30
  end
27
31
 
28
- # The `APIError` class in Ruby represents an error that occurs during an API request with specific
29
- # status and response body information.
32
+ class RateLimitError < StandardError
33
+ attr_reader :limit, :remaining
34
+
35
+ def initialize(limit, remaining)
36
+ @limit = limit
37
+ @remaining = remaining
38
+ super("Rate limit of #{limit} requests per second exceeded.")
39
+ end
40
+ end
41
+
30
42
  class APIError < StandardError
31
43
  attr_reader :status, :body
32
44
 
@@ -16,7 +16,6 @@ module LoopsSdk
16
16
  email: email,
17
17
  mailingLists: mailing_lists
18
18
  }.merge(properties)
19
- puts "Contact Data: #{contact_data.inspect}"
20
19
  make_request(:put, "v1/contacts/update", {}, contact_data)
21
20
  end
22
21
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LoopsSdk
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.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: 0.1.2
4
+ version: 0.2.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: 2024-08-16 00:00:00.000000000 Z
11
+ date: 2024-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -33,6 +33,8 @@ extra_rdoc_files: []
33
33
  files:
34
34
  - ".rubocop.yml"
35
35
  - CHANGELOG.md
36
+ - CODE_OF_CONDUCT.md
37
+ - CONTRIBUTING.md
36
38
  - LICENSE.txt
37
39
  - README.md
38
40
  - Rakefile