klaviyo-api-sdk 10.0.0 → 11.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: cd86c7db8242a1cdf18cc7edb186fcec7d291228640c74dcd3e674b28b047f2e
4
- data.tar.gz: 83e1c70d807961915812f20fce5e8b6753f2e48fa6b0da6f132ed33792d74041
3
+ metadata.gz: 3610c5beb6ce4880bba0bfec444b31a516885184084bb66d1e37af75c4e3fe1a
4
+ data.tar.gz: 1ed3ee86ebd20fbcf375d479f415481e6a8f5ccf12936cafe3003e738cff4554
5
5
  SHA512:
6
- metadata.gz: 9a26b5b4602dfb7afbe49a203e9cbd03f1b330bcbcc51278f1b1b4593f30b5df1bf30840673667f648acc436669cc6b11ee78eee1d2c1d272f83fc33551cafbd
7
- data.tar.gz: d50c64595fa55e97b02d9fdba9fbad0d95159b3a65894ed79f9b09f36657d54192e745c2dab769d3d0446064f504b2ae4424e9420c1bc243d32a9019b53c01e2
6
+ metadata.gz: '09b4e73aa484885e120a8a44159d6353ea29fc77f77793f8f9092b18c84e22a36c2cf315fee005cc39ecc23f0f334780afbc7461fedde0ccaa9e1ef7293dc045'
7
+ data.tar.gz: 18403de53ef0ae43d3581565a36a2ade54d7fef1371793534b76df01a6b82ac552401ccc66a44ac3e6a58f28818029d95504802d6f97de8b05b0584107a78c26
data/CHANGELOG.md CHANGED
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [11.0.0] - revision 2024-10-15
8
+ ### Changed
9
+ - Improved Retry Logic
10
+ - To address 429 status codes, we have modified the retry logic to use exponential backoff and the `Retry-After` header.
11
+ - **Breaking:** Retry logic is now enabled by default. To disable it, set `config.max_retries` to `0`.
12
+
7
13
  ## [10.0.0] - 2024-10-15
8
14
  ### Added
9
15
  - Universal Content API
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Klaviyo Ruby SDK
2
2
 
3
- - SDK version: 10.0.0
3
+ - SDK version: 11.0.0
4
4
  - API revision: 2024-10-15
5
5
 
6
6
  ## Helpful Resources
@@ -110,13 +110,13 @@ gem build klaviyo-api-sdk.gemspec
110
110
  Then install the gem locally:
111
111
 
112
112
  ```shell
113
- gem install ./klaviyo-api-sdk-10.0.0.gem
113
+ gem install ./klaviyo-api-sdk-11.0.0.gem
114
114
  ```
115
115
 
116
116
 
117
117
  Finally add this to the Gemfile:
118
118
 
119
- gem 'klaviyo-api-sdk', '~> 10.0.0'
119
+ gem 'klaviyo-api-sdk', '~> 11.0.0'
120
120
 
121
121
  To install directly from rubygems:
122
122
 
@@ -152,8 +152,10 @@ end
152
152
 
153
153
  NOTE:
154
154
  * The SDK retries on resolvable errors, namely: rate limits (common) and server errors on klaviyo (rare).
155
- * `max_retry` denotes number of attempts the client will make in order to execute the request successfully.
156
- * `max_delay` denotes total delay (in seconds) across all attempts.
155
+ * `max_retries` denotes the number of attempts the client will make in order to execute the request successfully.
156
+ * Set to 0 to disable automatic retries
157
+ * `max_delay` denotes the maximum amount of time (in seconds) that will be spent retrying a request across all attempts.
158
+ * The time interval between retries is calculated using exponential backoff and the `Retry-After` header.
157
159
 
158
160
  ### To call the `get_catalog_items` operation:
159
161
 
@@ -2619,11 +2621,11 @@ KlaviyoAPI::Profiles.create_profile_suppression_bulk_delete_job(body)
2619
2621
  #### [Create or Update Profile](https://developers.klaviyo.com/en/v2024-10-15/reference/create_or_update_profile)
2620
2622
 
2621
2623
  ```ruby
2622
- KlaviyoAPI::Profiles.create_or_update_profile(body)
2624
+ KlaviyoAPI::Profiles.create_or_update_profile(body, opts)
2623
2625
  ```
2624
2626
  ##### Method alias:
2625
2627
  ```ruby
2626
- KlaviyoAPI::Profiles.create_profile_import(body)
2628
+ KlaviyoAPI::Profiles.create_profile_import(body, opts)
2627
2629
  ```
2628
2630
 
2629
2631
 
@@ -2633,7 +2635,7 @@ KlaviyoAPI::Profiles.create_profile_import(body)
2633
2635
  #### [Create Profile](https://developers.klaviyo.com/en/v2024-10-15/reference/create_profile)
2634
2636
 
2635
2637
  ```ruby
2636
- KlaviyoAPI::Profiles.create_profile(body)
2638
+ KlaviyoAPI::Profiles.create_profile(body, opts)
2637
2639
  ```
2638
2640
 
2639
2641
 
@@ -2943,7 +2945,7 @@ KlaviyoAPI::Profiles.create_profile_bulk_import_job(body)
2943
2945
  #### [Update Profile](https://developers.klaviyo.com/en/v2024-10-15/reference/update_profile)
2944
2946
 
2945
2947
  ```ruby
2946
- KlaviyoAPI::Profiles.update_profile(id, body)
2948
+ KlaviyoAPI::Profiles.update_profile(id, body, opts)
2947
2949
  ```
2948
2950
 
2949
2951
 
@@ -17,7 +17,7 @@ require "klaviyo-api-sdk/version"
17
17
 
18
18
  Gem::Specification.new do |s|
19
19
  s.name = "klaviyo-api-sdk"
20
- s.version = "10.0.0"
20
+ s.version = "11.0.0"
21
21
  s.authors = ['Klaviyo Team']
22
22
  s.email = ['libraries@klaviyo.com']
23
23
  s.summary = 'You heard us, a Ruby wrapper for the Klaviyo API'
@@ -351,6 +351,7 @@ module KlaviyoAPI
351
351
  # Given a set of profile attributes and optionally an ID, create or update a profile. Returns 201 if a new profile was created, 200 if an existing profile was updated. Note that setting a field to `null` will clear out the field, whereas not including a field in your request will leave it unchanged.<br><br>*Rate limits*:<br>Burst: `75/s`<br>Steady: `700/m` **Scopes:** `profiles:write`
352
352
  # @param profile_upsert_query [ProfileUpsertQuery]
353
353
  # @param [Hash] opts the optional parameters
354
+ # @option opts [Array<String>] :additional_fields_profile Request additional fields not included by default in the response. Supported values: &#39;subscriptions&#39;, &#39;predictive_analytics&#39;
354
355
  # @return [Hash<String, Object>]
355
356
  def create_or_update_profile(profile_upsert_query, opts = {})
356
357
  data, _status_code, _headers = create_or_update_profile_with_http_info(profile_upsert_query, opts)
@@ -364,6 +365,7 @@ module KlaviyoAPI
364
365
  # Given a set of profile attributes and optionally an ID, create or update a profile. Returns 201 if a new profile was created, 200 if an existing profile was updated. Note that setting a field to &#x60;null&#x60; will clear out the field, whereas not including a field in your request will leave it unchanged.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;75/s&#x60;&lt;br&gt;Steady: &#x60;700/m&#x60; **Scopes:** &#x60;profiles:write&#x60;
365
366
  # @param profile_upsert_query [ProfileUpsertQuery]
366
367
  # @param [Hash] opts the optional parameters
368
+ # @option opts [Array<String>] :additional_fields_profile Request additional fields not included by default in the response. Supported values: &#39;subscriptions&#39;, &#39;predictive_analytics&#39;
367
369
  # @return [Array<(Hash<String, Object>, Integer, Hash)>] Hash<String, Object> data, response status code and response headers
368
370
  def create_or_update_profile_with_http_info(profile_upsert_query, opts = {})
369
371
  if @api_client.config.debugging
@@ -373,11 +375,16 @@ module KlaviyoAPI
373
375
  if @api_client.config.client_side_validation && profile_upsert_query.nil?
374
376
  fail ArgumentError, "Missing the required parameter 'profile_upsert_query' when calling ProfilesApi.create_or_update_profile"
375
377
  end
378
+ allowable_values = ["subscriptions", "predictive_analytics"]
379
+ if @api_client.config.client_side_validation && opts[:'additional_fields_profile'] && !opts[:'additional_fields_profile'].all? { |item| allowable_values.include?(item) }
380
+ fail ArgumentError, "invalid value for \"additional_fields_profile\", must include one of #{allowable_values}"
381
+ end
376
382
  # resource path
377
383
  local_var_path = '/api/profile-import'
378
384
 
379
385
  # query parameters
380
386
  query_params = opts[:query_params] || {}
387
+ query_params[:'additional-fields[profile]'] = @api_client.build_collection_param(opts[:'additional_fields_profile'], :csv) if !opts[:'additional_fields_profile'].nil?
381
388
 
382
389
  # header parameters
383
390
  header_params = opts[:header_params] || {}
@@ -427,6 +434,7 @@ module KlaviyoAPI
427
434
  # Create a new profile.<br><br>*Rate limits*:<br>Burst: `75/s`<br>Steady: `700/m` **Scopes:** `profiles:write`
428
435
  # @param profile_create_query [ProfileCreateQuery]
429
436
  # @param [Hash] opts the optional parameters
437
+ # @option opts [Array<String>] :additional_fields_profile Request additional fields not included by default in the response. Supported values: &#39;subscriptions&#39;, &#39;predictive_analytics&#39;
430
438
  # @return [Hash<String, Object>]
431
439
  def create_profile(profile_create_query, opts = {})
432
440
  data, _status_code, _headers = create_profile_with_http_info(profile_create_query, opts)
@@ -437,6 +445,7 @@ module KlaviyoAPI
437
445
  # Create a new profile.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;75/s&#x60;&lt;br&gt;Steady: &#x60;700/m&#x60; **Scopes:** &#x60;profiles:write&#x60;
438
446
  # @param profile_create_query [ProfileCreateQuery]
439
447
  # @param [Hash] opts the optional parameters
448
+ # @option opts [Array<String>] :additional_fields_profile Request additional fields not included by default in the response. Supported values: &#39;subscriptions&#39;, &#39;predictive_analytics&#39;
440
449
  # @return [Array<(Hash<String, Object>, Integer, Hash)>] Hash<String, Object> data, response status code and response headers
441
450
  def create_profile_with_http_info(profile_create_query, opts = {})
442
451
  if @api_client.config.debugging
@@ -446,11 +455,16 @@ module KlaviyoAPI
446
455
  if @api_client.config.client_side_validation && profile_create_query.nil?
447
456
  fail ArgumentError, "Missing the required parameter 'profile_create_query' when calling ProfilesApi.create_profile"
448
457
  end
458
+ allowable_values = ["subscriptions", "predictive_analytics"]
459
+ if @api_client.config.client_side_validation && opts[:'additional_fields_profile'] && !opts[:'additional_fields_profile'].all? { |item| allowable_values.include?(item) }
460
+ fail ArgumentError, "invalid value for \"additional_fields_profile\", must include one of #{allowable_values}"
461
+ end
449
462
  # resource path
450
463
  local_var_path = '/api/profiles'
451
464
 
452
465
  # query parameters
453
466
  query_params = opts[:query_params] || {}
467
+ query_params[:'additional-fields[profile]'] = @api_client.build_collection_param(opts[:'additional_fields_profile'], :csv) if !opts[:'additional_fields_profile'].nil?
454
468
 
455
469
  # header parameters
456
470
  header_params = opts[:header_params] || {}
@@ -1498,7 +1512,7 @@ module KlaviyoAPI
1498
1512
  alias get_profile_lists_with_http_info get_lists_for_profile_with_http_info
1499
1513
 
1500
1514
  # Get Profile
1501
- # Get the profile with the given profile ID.<br><br>*Rate limits*:<br>Burst: `75/s`<br>Steady: `700/m` **Scopes:** `profiles:read`
1515
+ # Get the profile with the given profile ID.<br><br>*Rate limits*:<br>Burst: `75/s`<br>Steady: `700/m`<br><br>Rate limits when using the `include=list` parameter in your API request:<br>Burst: `1/s`<br>Steady: `15/m`<br><br>Rate limits when using the `include=segment` parameter in your API request:<br>Burst: `1/s`<br>Steady: `15/m`<br><br>To learn more about how the `include` parameter impacts rate limits, check out our [Rate limits, status codes, and errors](https://developers.klaviyo.com/en/v2024-10-15/docs/rate_limits_and_error_handling) guide. **Scopes:** `profiles:read`
1502
1516
  # @param id [String]
1503
1517
  # @param [Hash] opts the optional parameters
1504
1518
  # @option opts [Array<String>] :additional_fields_profile Request additional fields not included by default in the response. Supported values: &#39;subscriptions&#39;, &#39;predictive_analytics&#39;
@@ -1513,7 +1527,7 @@ module KlaviyoAPI
1513
1527
  end
1514
1528
 
1515
1529
  # Get Profile
1516
- # Get the profile with the given profile ID.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;75/s&#x60;&lt;br&gt;Steady: &#x60;700/m&#x60; **Scopes:** &#x60;profiles:read&#x60;
1530
+ # Get the profile with the given profile ID.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;75/s&#x60;&lt;br&gt;Steady: &#x60;700/m&#x60;&lt;br&gt;&lt;br&gt;Rate limits when using the &#x60;include&#x3D;list&#x60; parameter in your API request:&lt;br&gt;Burst: &#x60;1/s&#x60;&lt;br&gt;Steady: &#x60;15/m&#x60;&lt;br&gt;&lt;br&gt;Rate limits when using the &#x60;include&#x3D;segment&#x60; parameter in your API request:&lt;br&gt;Burst: &#x60;1/s&#x60;&lt;br&gt;Steady: &#x60;15/m&#x60;&lt;br&gt;&lt;br&gt;To learn more about how the &#x60;include&#x60; parameter impacts rate limits, check out our [Rate limits, status codes, and errors](https://developers.klaviyo.com/en/v2024-10-15/docs/rate_limits_and_error_handling) guide. **Scopes:** &#x60;profiles:read&#x60;
1517
1531
  # @param id [String]
1518
1532
  # @param [Hash] opts the optional parameters
1519
1533
  # @option opts [Array<String>] :additional_fields_profile Request additional fields not included by default in the response. Supported values: &#39;subscriptions&#39;, &#39;predictive_analytics&#39;
@@ -2202,6 +2216,7 @@ module KlaviyoAPI
2202
2216
  # @param id [String] Primary key that uniquely identifies this profile. Generated by Klaviyo.
2203
2217
  # @param profile_partial_update_query [ProfilePartialUpdateQuery]
2204
2218
  # @param [Hash] opts the optional parameters
2219
+ # @option opts [Array<String>] :additional_fields_profile Request additional fields not included by default in the response. Supported values: &#39;subscriptions&#39;, &#39;predictive_analytics&#39;
2205
2220
  # @return [Hash<String, Object>]
2206
2221
  def update_profile(id, profile_partial_update_query, opts = {})
2207
2222
  data, _status_code, _headers = update_profile_with_http_info(id, profile_partial_update_query, opts)
@@ -2213,6 +2228,7 @@ module KlaviyoAPI
2213
2228
  # @param id [String] Primary key that uniquely identifies this profile. Generated by Klaviyo.
2214
2229
  # @param profile_partial_update_query [ProfilePartialUpdateQuery]
2215
2230
  # @param [Hash] opts the optional parameters
2231
+ # @option opts [Array<String>] :additional_fields_profile Request additional fields not included by default in the response. Supported values: &#39;subscriptions&#39;, &#39;predictive_analytics&#39;
2216
2232
  # @return [Array<(Hash<String, Object>, Integer, Hash)>] Hash<String, Object> data, response status code and response headers
2217
2233
  def update_profile_with_http_info(id, profile_partial_update_query, opts = {})
2218
2234
  if @api_client.config.debugging
@@ -2226,11 +2242,16 @@ module KlaviyoAPI
2226
2242
  if @api_client.config.client_side_validation && profile_partial_update_query.nil?
2227
2243
  fail ArgumentError, "Missing the required parameter 'profile_partial_update_query' when calling ProfilesApi.update_profile"
2228
2244
  end
2245
+ allowable_values = ["subscriptions", "predictive_analytics"]
2246
+ if @api_client.config.client_side_validation && opts[:'additional_fields_profile'] && !opts[:'additional_fields_profile'].all? { |item| allowable_values.include?(item) }
2247
+ fail ArgumentError, "invalid value for \"additional_fields_profile\", must include one of #{allowable_values}"
2248
+ end
2229
2249
  # resource path
2230
2250
  local_var_path = '/api/profiles/{id}'.sub('{' + 'id' + '}', CGI.escape(id.to_s))
2231
2251
 
2232
2252
  # query parameters
2233
2253
  query_params = opts[:query_params] || {}
2254
+ query_params[:'additional-fields[profile]'] = @api_client.build_collection_param(opts[:'additional_fields_profile'], :csv) if !opts[:'additional_fields_profile'].nil?
2234
2255
 
2235
2256
  # header parameters
2236
2257
  header_params = opts[:header_params] || {}
@@ -32,7 +32,7 @@ module KlaviyoAPI
32
32
  # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
33
33
  def initialize(config = Configuration.default)
34
34
  @config = config
35
- @user_agent = "klaviyo-api-ruby/10.0.0"
35
+ @user_agent = "klaviyo-api-ruby/11.0.0"
36
36
  @default_headers = {
37
37
  'Content-Type' => 'application/json',
38
38
  'User-Agent' => @user_agent
@@ -206,7 +206,7 @@ module KlaviyoAPI
206
206
  # Check to see if the all the properties in the model are valid
207
207
  # @return true if the model is valid
208
208
  def valid?
209
- klaviyo_sdk_validator = EnumAttributeValidator.new('String', ["android", "react_native", "swift"])
209
+ klaviyo_sdk_validator = EnumAttributeValidator.new('String', ["android", "flutter_community", "react_native", "swift"])
210
210
  return false unless klaviyo_sdk_validator.valid?(@klaviyo_sdk)
211
211
  os_name_validator = EnumAttributeValidator.new('String', ["android", "ios", "ipados", "macos", "tvos"])
212
212
  return false unless os_name_validator.valid?(@os_name)
@@ -218,7 +218,7 @@ module KlaviyoAPI
218
218
  # Custom attribute writer method checking allowed values (enum).
219
219
  # @param [Object] klaviyo_sdk Object to be assigned
220
220
  def klaviyo_sdk=(klaviyo_sdk)
221
- validator = EnumAttributeValidator.new('String', ["android", "react_native", "swift"])
221
+ validator = EnumAttributeValidator.new('String', ["android", "flutter_community", "react_native", "swift"])
222
222
  unless validator.valid?(klaviyo_sdk)
223
223
  fail ArgumentError, "invalid value for \"klaviyo_sdk\", must be one of #{validator.allowable_values}."
224
224
  end
@@ -19,14 +19,11 @@ module KlaviyoAPI
19
19
 
20
20
  attr_accessor :display_options
21
21
 
22
- attr_accessor :styles
23
-
24
22
  # Attribute mapping from ruby-style variable name to JSON key.
25
23
  def self.attribute_map
26
24
  {
27
25
  :'content' => :'content',
28
- :'display_options' => :'display_options',
29
- :'styles' => :'styles'
26
+ :'display_options' => :'display_options'
30
27
  }
31
28
  end
32
29
 
@@ -39,15 +36,13 @@ module KlaviyoAPI
39
36
  def self.openapi_types
40
37
  {
41
38
  :'content' => :'String',
42
- :'display_options' => :'BlockDisplayOptions',
43
- :'styles' => :'String'
39
+ :'display_options' => :'BlockDisplayOptions'
44
40
  }
45
41
  end
46
42
 
47
43
  # List of attributes with nullable: true
48
44
  def self.openapi_nullable
49
45
  Set.new([
50
- :'styles'
51
46
  ])
52
47
  end
53
48
 
@@ -73,10 +68,6 @@ module KlaviyoAPI
73
68
  if attributes.key?(:'display_options')
74
69
  self.display_options = attributes[:'display_options']
75
70
  end
76
-
77
- if attributes.key?(:'styles')
78
- self.styles = attributes[:'styles']
79
- end
80
71
  end
81
72
 
82
73
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -108,8 +99,7 @@ module KlaviyoAPI
108
99
  return true if self.equal?(o)
109
100
  self.class == o.class &&
110
101
  content == o.content &&
111
- display_options == o.display_options &&
112
- styles == o.styles
102
+ display_options == o.display_options
113
103
  end
114
104
 
115
105
  # @see the `==` method
@@ -121,7 +111,7 @@ module KlaviyoAPI
121
111
  # Calculates hash code according to all attributes.
122
112
  # @return [Integer] Hash code
123
113
  def hash
124
- [content, display_options, styles].hash
114
+ [content, display_options].hash
125
115
  end
126
116
 
127
117
  # Builds the object from hash
@@ -17,10 +17,13 @@ module KlaviyoAPI
17
17
  class SMSSubscriptionParameters
18
18
  attr_accessor :marketing
19
19
 
20
+ attr_accessor :transactional
21
+
20
22
  # Attribute mapping from ruby-style variable name to JSON key.
21
23
  def self.attribute_map
22
24
  {
23
- :'marketing' => :'marketing'
25
+ :'marketing' => :'marketing',
26
+ :'transactional' => :'transactional'
24
27
  }
25
28
  end
26
29
 
@@ -32,7 +35,8 @@ module KlaviyoAPI
32
35
  # Attribute type mapping.
33
36
  def self.openapi_types
34
37
  {
35
- :'marketing' => :'SubscriptionParameters'
38
+ :'marketing' => :'SubscriptionParameters',
39
+ :'transactional' => :'SubscriptionParameters'
36
40
  }
37
41
  end
38
42
 
@@ -60,6 +64,10 @@ module KlaviyoAPI
60
64
  if attributes.key?(:'marketing')
61
65
  self.marketing = attributes[:'marketing']
62
66
  end
67
+
68
+ if attributes.key?(:'transactional')
69
+ self.transactional = attributes[:'transactional']
70
+ end
63
71
  end
64
72
 
65
73
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -80,7 +88,8 @@ module KlaviyoAPI
80
88
  def ==(o)
81
89
  return true if self.equal?(o)
82
90
  self.class == o.class &&
83
- marketing == o.marketing
91
+ marketing == o.marketing &&
92
+ transactional == o.transactional
84
93
  end
85
94
 
86
95
  # @see the `==` method
@@ -92,7 +101,7 @@ module KlaviyoAPI
92
101
  # Calculates hash code according to all attributes.
93
102
  # @return [Integer] Hash code
94
103
  def hash
95
- [marketing].hash
104
+ [marketing, transactional].hash
96
105
  end
97
106
 
98
107
  # Builds the object from hash
@@ -660,25 +660,10 @@ module KlaviyoAPI
660
660
  # recreate methods
661
661
  original_class.public_instance_methods(false).each do |m|
662
662
  wrapper_class.class_eval {
663
- define_singleton_method m do |*arg|
664
- # max_delay=60, max_retries=3
665
- # retry_codes = [429,503,504]
666
- # only add retriable if both of these are not set
667
- max_retries = Configuration.default.max_retries
668
- max_delay = Configuration.default.max_delay
669
-
670
- if (max_retries != nil && max_delay != nil)
671
- Retriable.configure do |c|
672
- c.tries = max_retries
673
- c.max_elapsed_time = max_delay
674
- c.on = {
675
- KlaviyoAPI::ApiError => [/429/, /503/, /504/]
676
- }
677
- end
678
- Retriable.retriable do
679
- KlaviyoAPI.const_get(c).new.send(m, *arg)
680
- end
681
- else
663
+ define_singleton_method m do |*arg|
664
+ max_retries = Configuration.default.max_retries || 3
665
+ max_delay = Configuration.default.max_delay || 60
666
+ KlaviyoAPI.with_retry(max_retries, max_delay) do
682
667
  KlaviyoAPI.const_get(c).new.send(m, *arg)
683
668
  end
684
669
  end
@@ -689,5 +674,33 @@ module KlaviyoAPI
689
674
  @is_initialized = true
690
675
  end
691
676
  end
677
+
678
+ def with_retry(tries, max_elapsed_time)
679
+ start_time = Time.now
680
+ elapsed_time = -> { Time.now - start_time }
681
+ last_request_retry_after = nil
682
+ last_request_timestamp = nil
683
+ index = 0
684
+ attempt = 0
685
+ last_exception = nil
686
+ while true
687
+ begin
688
+ retry_after_value_elapsed = last_request_retry_after == nil || Time.now - last_request_timestamp > Integer(last_request_retry_after)
689
+ if retry_after_value_elapsed
690
+ attempt += 1
691
+ return yield
692
+ end
693
+ rescue KlaviyoAPI::ApiError => exception
694
+ last_exception = exception
695
+ last_request_retry_after = exception.response_headers[:'Retry-After']
696
+ last_request_timestamp = Time.now
697
+ raise unless [429, 503, 504, 524].include? exception.code
698
+ end
699
+ interval = Retriable::ExponentialBackoff.new(tries: index + 1).intervals[index]
700
+ raise last_exception if attempt >= tries || (elapsed_time.call + interval) > max_elapsed_time
701
+ sleep interval
702
+ index += 1
703
+ end
704
+ end
692
705
  end
693
706
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: klaviyo-api-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.0.0
4
+ version: 11.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Klaviyo Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-17 00:00:00.000000000 Z
11
+ date: 2024-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: retriable