mailchimp-rest-api 0.1.0 → 0.3.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: 9e12dd5f9138dd42df18a44d79b07a9d7d280a8c09694a64e5c9e7963dd6d992
4
- data.tar.gz: 7fd21428cd4d12c5881e2eea7bc4c3a045742bfd9120b01cf1a62704e834b814
3
+ metadata.gz: 428009c6c680a7c4bc6ec3b80fe5e4c1485df70e358928655fefabbf0b76637c
4
+ data.tar.gz: bd8307d56a558d64a4d7a7551a21cacf9dfe1e44036882191421c359c1b2682a
5
5
  SHA512:
6
- metadata.gz: 4fdebf9fbf90a37a171ec67d64c3ff8c53361cf4bc0d90a22649ddb14f962e76f4f4742ef7ac16b6bdbcc8be49677557f3debe8a2f6dd229101d58641ec9a993
7
- data.tar.gz: 948ee7442f8a69395c4d1743cb4b91140f32820f96d4bf4709e4c625699bc551092cc2648700540c5e26418f5f05a0523957b90baa8e5d1d45daeec138544906
6
+ metadata.gz: c3f2cc4b7561902a8ba1991b8acb68be65714a506854adea22cd3d0f1a7fa449aae6cea82267cb55d4b45a9ea7f11f6c4ba41b5e602d8a75ecb6f6f4df8a3102
7
+ data.tar.gz: f4bb0e6175805b8363ed59df417c4f103ee6b70c5bc40dd6003e7f8ac7eaef3ac5ac992a251b055d224981ab6142f9c460e2a0924ce7691bfbf0cc560e922f7f
data/README.md CHANGED
@@ -60,6 +60,52 @@ MailchimpAPI.audience_members.create(audience_id, body: body)
60
60
  - `response.success?` - checks HTTP status code is 2xx
61
61
  - `response.failed?` - checks HTTP status code is not 2xx
62
62
 
63
+ ## Errors
64
+
65
+ All error classes inherit from `MailchimpAPI::Error` and provide:
66
+
67
+ - `error_type` - Error type returned by Mailchimp
68
+ - `error_title` - Error title or response error class name
69
+ - `error_status` - Error status or HTTP status
70
+ - `error_detail` - Error description from Mailchimp
71
+ - `error_fields` - Field-specific errors
72
+ - `error_instance` - Error ID from Mailchimp
73
+ - `response` - Response object
74
+ - `request` - Request object
75
+
76
+ MailchimpAPI provides specific error classes for different types of errors:
77
+
78
+ ### Network Errors
79
+
80
+ - `MailchimpAPI::Errors::NetworkError` - Raised when a network error occurs
81
+ during request execution
82
+
83
+ ### HTTP Status Code Errors
84
+
85
+ - `MailchimpAPI::Errors::BadRequest` (400) - Invalid request parameters
86
+ - `MailchimpAPI::Errors::Unauthorized` (401) - Invalid API key
87
+ - `MailchimpAPI::Errors::Forbidden` (403) - Insufficient permissions
88
+ - `MailchimpAPI::Errors::NotFound` (404) - Resource not found
89
+ - `MailchimpAPI::Errors::MethodNotAllowed` (405) - HTTP method not allowed
90
+ - `MailchimpAPI::Errors::RequestURITooLong` (414) - Request URI too long
91
+ - `MailchimpAPI::Errors::UnprocessableEntity` (422) - Request validation failed
92
+ - `MailchimpAPI::Errors::UpgradeRequired` (426) - API version upgrade required
93
+ - `MailchimpAPI::Errors::TooManyRequests` (429) - Rate limit exceeded
94
+ - `MailchimpAPI::Errors::ServerError` (5xx) - Mailchimp server error
95
+
96
+ Example:
97
+
98
+ ```ruby
99
+ begin
100
+ MailchimpAPI.audience_members.create(audience_id, body: body)
101
+ rescue MailchimpAPI::Errors::UnprocessableEntity => e
102
+ puts "Validation failed: #{e.error_detail}"
103
+ puts "Field errors: #{e.error_fields}"
104
+ rescue MailchimpAPI::Errors::NetworkError => e
105
+ puts "Network error: #{e.error_detail}"
106
+ end
107
+ ```
108
+
63
109
  ## Configuration options
64
110
 
65
111
  MailchimpAPI client accepts this additional options:
@@ -103,38 +149,65 @@ client = MailchimpAPI::Client.new(
103
149
 
104
150
  ## Pagination
105
151
 
106
- We have two specific methods:
107
-
108
- - `MailchimpAPI#each_page(response)` - iterates over current and each next page
109
- response
110
- - `MailchimpAPI#each_page_item(response, items: :members)` - iterates over
111
- each item (each member in this case)
112
-
113
- Example:
152
+ All REST resources have `#each` method. Example:
114
153
 
115
154
  ```ruby
116
- first_page = MailchimpAPI.audience_members.list(list_id, query: { count: 100 }
155
+ MailchimpAPI.audience_members.each(list_id) { |member| ... }
156
+ MailchimpAPI.audience_member_tags.each(list_id, member_id) { |tag| ... }
157
+ ```
117
158
 
118
- MailchimpAPI.each_page(first_page) do |response|
119
- puts response.body
120
- end
159
+ `Each` method accepts `query`, `body` and `headers` as any other API.
160
+ By default it requests 1000 items on each page, but it is configurable through
161
+ `query` parameter. Example:
121
162
 
122
- MailchimpAPI.each_page_item(first_page, items: :members) do |item|
123
- puts item[:email_address]
124
- end
163
+ ```ruby
164
+ MailchimpAPI.audience_members.each(list_id, query: { count: 100 }) { |member| ... }
125
165
  ```
126
166
 
127
167
  ## Request
128
168
 
129
169
  ...
130
170
 
131
- ## Errors
171
+ ## APIs
132
172
 
133
- ...
173
+ ### Audience Members
134
174
 
135
- ## APIs
175
+ - List `MailchimpAPI.audience_members.get(audience_id)`
176
+ - Create `MailchimpAPI.audience_members.create(audience_id, body: body)`
177
+ - Show `MailchimpAPI.audience_members.show(audience_id, email)`
178
+ - Update `MailchimpAPI.audience_members.update(audience_id, email, body: body)`
179
+ - Add or Update `MailchimpAPI.audience_members.add_or_update(audience_id, email, body: body)`
180
+ - Archive `MailchimpAPI.audience_members.delete(audience_id, email)`
181
+ - Delete Permanently `MailchimpAPI.audience_members.delete(audience_id, email)`
136
182
 
137
- ...
183
+ ### Audience Member Tags
184
+
185
+ - List `MailchimpAPI.audience_member_tags.get(audience_id, email)`
186
+ - Create `MailchimpAPI.audience_member_tags.create(audience_id, email, body: body)`
187
+
188
+ ### Audience Webhooks
189
+
190
+ - List `MailchimpAPI.audience_webhooks.get(audience_id)`
191
+ - Create `MailchimpAPI.audience_webhooks.create(audience_id, body: body)`
192
+ - Show `MailchimpAPI.audience_webhooks.show(audience_id, webhook_id)`
193
+ - Update `MailchimpAPI.audience_webhooks.update(audience_id, webhook_id, body: body)`
194
+ - Delete `MailchimpAPI.audience_webhooks.delete(audience_id, webhook_id)`
195
+
196
+ ### Audience Interest Categories
197
+
198
+ - List `MailchimpAPI.audience_interest_categories.get(audience_id)`
199
+ - Create `MailchimpAPI.audience_interest_categories.create(audience_id, body: body)`
200
+ - Show `MailchimpAPI.audience_interest_categories.show(audience_id, webhook_id)`
201
+ - Update `MailchimpAPI.audience_interest_categories.update(audience_id, webhook_id, body: body)`
202
+ - Delete `MailchimpAPI.audience_interest_categories.delete(audience_id, webhook_id)`
203
+
204
+ ### Audience Interests
205
+
206
+ - List `MailchimpAPI.audience_interests.get(audience_id)`
207
+ - Create `MailchimpAPI.audience_interests.create(audience_id, body: body)`
208
+ - Show `MailchimpAPI.audience_interests.show(audience_id, webhook_id)`
209
+ - Update `MailchimpAPI.audience_interests.update(audience_id, webhook_id, body: body)`
210
+ - Delete `MailchimpAPI.audience_interests.delete(audience_id, webhook_id)`
138
211
 
139
212
  ## Development
140
213
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.3.0
@@ -6,13 +6,25 @@ module MailchimpAPI
6
6
  # Methods to access API resources
7
7
  #
8
8
  module APIMethods
9
- def audience_members
10
- Audience::Members.new(self)
9
+ def audience_interest_categories
10
+ Audience::InterestCategories.new(self)
11
+ end
12
+
13
+ def audience_interests
14
+ Audience::Interests.new(self)
11
15
  end
12
16
 
13
17
  def audience_member_tags
14
18
  Audience::MemberTags.new(self)
15
19
  end
20
+
21
+ def audience_members
22
+ Audience::Members.new(self)
23
+ end
24
+
25
+ def audience_webhooks
26
+ Audience::Webhooks.new(self)
27
+ end
16
28
  end
17
29
  end
18
30
  end
@@ -6,7 +6,6 @@ module MailchimpAPI
6
6
 
7
7
  include APIMethods
8
8
  include BatchMethods
9
- include PaginationMethods
10
9
 
11
10
  attr_reader :api_key, :api_url, :api_version, :authorization_token, :config
12
11
 
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MailchimpAPI
4
+ module Pagination
5
+ module ListEachItemHelper
6
+ private
7
+
8
+ def list_each_item(items_field, *args, query: nil, body: nil, headers: nil, &block)
9
+ return enum_for(:list_each_item, items_field, *args, query: query, body: body, headers: headers) unless block
10
+
11
+ query = PrepareQueryParams.call(query, items_field: items_field)
12
+
13
+ loop do
14
+ response = list(*args, query: query, body: body, headers: headers)
15
+ response.body.fetch(items_field).each(&block)
16
+
17
+ total_received_items_count = query.fetch(:offset) + query.fetch(:count)
18
+ break if total_received_items_count >= response.body.fetch(:total_items)
19
+
20
+ query[:offset] = total_received_items_count
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MailchimpAPI
4
+ module Pagination
5
+ class PrepareQueryParams
6
+ class << self
7
+ def call(query, items_field:)
8
+ query ||= {}
9
+ query = query.transform_keys(&:to_sym)
10
+
11
+ prepare_offset(query)
12
+ prepare_count(query)
13
+
14
+ ensure_fields_included(query, items_field: items_field, total_field: "total_items")
15
+ ensure_fields_not_excluded(query, items_field: items_field, total_field: "total_items")
16
+ query
17
+ end
18
+
19
+ private
20
+
21
+ def prepare_offset(query)
22
+ query[:offset] = query[:offset].to_i
23
+ end
24
+
25
+ def prepare_count(query)
26
+ query[:count] = query[:count].to_i
27
+ query[:count] = 1000 if query[:count] == 0
28
+ end
29
+
30
+ def ensure_fields_included(query, items_field:, total_field:)
31
+ fields = query[:fields] || ""
32
+ query[:fields] = (fields.split(",") + [items_field.to_s, total_field]).uniq.join(",")
33
+ end
34
+
35
+ def ensure_fields_not_excluded(query, items_field:, total_field:)
36
+ excluded_fields = query[:excluded_fields]
37
+ return unless excluded_fields
38
+
39
+ excluded_fields = (excluded_fields.split(",") - [items_field.to_s, total_field]).join(",")
40
+ excluded_fields.empty? ? query.delete(:excluded_fields) : query[:excluded_fields] = excluded_fields
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MailchimpAPI
4
+ module Audience
5
+ class InterestCategories < Resource
6
+ module APIs
7
+ include Pagination::ListEachItemHelper
8
+
9
+ def list(list_id, query: nil, body: nil, headers: nil)
10
+ path = "/lists/#{list_id}/interest-categories"
11
+ client.get(path, query: query, body: body, headers: headers)
12
+ end
13
+
14
+ def create(list_id, query: nil, body: nil, headers: nil)
15
+ path = "/lists/#{list_id}/interest-categories"
16
+ client.post(path, query: query, body: body, headers: headers)
17
+ end
18
+
19
+ def show(list_id, interest_category_id, query: nil, body: nil, headers: nil)
20
+ path = "/lists/#{list_id}/interest-categories/#{interest_category_id}"
21
+ client.get(path, query: query, body: body, headers: headers)
22
+ end
23
+
24
+ def delete(list_id, interest_category_id, query: nil, body: nil, headers: nil)
25
+ path = "/lists/#{list_id}/interest-categories/#{interest_category_id}"
26
+ client.delete(path, query: query, body: body, headers: headers)
27
+ end
28
+
29
+ def update(list_id, interest_category_id, query: nil, body: nil, headers: nil)
30
+ path = "/lists/#{list_id}/interest-categories/#{interest_category_id}"
31
+ client.patch(path, query: query, body: body, headers: headers)
32
+ end
33
+
34
+ def each(list_id, query: nil, body: nil, headers: nil, &block)
35
+ list_each_item(:categories, list_id, query: query, body: body, headers: headers, &block)
36
+ end
37
+ end
38
+
39
+ include APIs
40
+ extend APIs
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MailchimpAPI
4
+ module Audience
5
+ class Interests < Resource
6
+ module APIs
7
+ include Pagination::ListEachItemHelper
8
+
9
+ def list(list_id, interest_category_id, query: nil, body: nil, headers: nil)
10
+ path = "/lists/#{list_id}/interest-categories/#{interest_category_id}/interests"
11
+ client.get(path, query: query, body: body, headers: headers)
12
+ end
13
+
14
+ def create(list_id, interest_category_id, query: nil, body: nil, headers: nil)
15
+ path = "/lists/#{list_id}/interest-categories/#{interest_category_id}/interests"
16
+ client.post(path, query: query, body: body, headers: headers)
17
+ end
18
+
19
+ def show(list_id, interest_category_id, interest_id, query: nil, body: nil, headers: nil)
20
+ path = "/lists/#{list_id}/interest-categories/#{interest_category_id}/interests/#{interest_id}"
21
+ client.get(path, query: query, body: body, headers: headers)
22
+ end
23
+
24
+ def delete(list_id, interest_category_id, interest_id, query: nil, body: nil, headers: nil)
25
+ path = "/lists/#{list_id}/interest-categories/#{interest_category_id}/interests/#{interest_id}"
26
+ client.delete(path, query: query, body: body, headers: headers)
27
+ end
28
+
29
+ def update(list_id, interest_category_id, interest_id, query: nil, body: nil, headers: nil)
30
+ path = "/lists/#{list_id}/interest-categories/#{interest_category_id}/interests/#{interest_id}"
31
+ client.patch(path, query: query, body: body, headers: headers)
32
+ end
33
+
34
+ def each(list_id, interest_category_id, query: nil, body: nil, headers: nil, &block)
35
+ list_each_item(:interests, list_id, interest_category_id, query: query, body: body, headers: headers, &block)
36
+ end
37
+ end
38
+
39
+ include APIs
40
+ extend APIs
41
+ end
42
+ end
43
+ end
@@ -4,15 +4,21 @@ module MailchimpAPI
4
4
  module Audience
5
5
  class MemberTags < Resource
6
6
  module APIs
7
- def list(audience_id, email, query: nil, body: nil, headers: nil)
8
- path = "/lists/#{audience_id}/members/#{subscriber_hash(email)}/tags"
7
+ include Pagination::ListEachItemHelper
8
+
9
+ def list(list_id, email, query: nil, body: nil, headers: nil)
10
+ path = "/lists/#{list_id}/members/#{subscriber_hash(email)}/tags"
9
11
  client.get(path, query: query, body: body, headers: headers)
10
12
  end
11
13
 
12
- def create(audience_id, email, query: nil, body: nil, headers: nil)
13
- path = "/lists/#{audience_id}/members/#{subscriber_hash(email)}/tags"
14
+ def create(list_id, email, query: nil, body: nil, headers: nil)
15
+ path = "/lists/#{list_id}/members/#{subscriber_hash(email)}/tags"
14
16
  client.post(path, query: query, body: body, headers: headers)
15
17
  end
18
+
19
+ def each(list_id, email, query: nil, body: nil, headers: nil, &block)
20
+ list_each_item(:tags, list_id, email, query: query, body: body, headers: headers, &block)
21
+ end
16
22
  end
17
23
 
18
24
  include MailchimpAPI::Audience::Utils
@@ -4,40 +4,46 @@ module MailchimpAPI
4
4
  module Audience
5
5
  class Members < Resource
6
6
  module APIs
7
- def list(audience_id, query: nil, body: nil, headers: nil)
8
- path = "/lists/#{audience_id}/members"
7
+ include Pagination::ListEachItemHelper
8
+
9
+ def list(list_id, query: nil, body: nil, headers: nil)
10
+ path = "/lists/#{list_id}/members"
9
11
  client.get(path, query: query, body: body, headers: headers)
10
12
  end
11
13
 
12
- def create(audience_id, query: nil, body: nil, headers: nil)
13
- path = "/lists/#{audience_id}/members"
14
+ def create(list_id, query: nil, body: nil, headers: nil)
15
+ path = "/lists/#{list_id}/members"
14
16
  client.post(path, query: query, body: body, headers: headers)
15
17
  end
16
18
 
17
- def show(audience_id, email, query: nil, body: nil, headers: nil)
18
- path = "/lists/#{audience_id}/members/#{subscriber_hash(email)}"
19
+ def show(list_id, email, query: nil, body: nil, headers: nil)
20
+ path = "/lists/#{list_id}/members/#{subscriber_hash(email)}"
19
21
  client.get(path, query: query, body: body, headers: headers)
20
22
  end
21
23
 
22
- def archive(audience_id, email, query: nil, body: nil, headers: nil)
23
- path = "/lists/#{audience_id}/members/#{subscriber_hash(email)}"
24
+ def archive(list_id, email, query: nil, body: nil, headers: nil)
25
+ path = "/lists/#{list_id}/members/#{subscriber_hash(email)}"
24
26
  client.delete(path, query: query, body: body, headers: headers)
25
27
  end
26
28
 
27
- def update(audience_id, email, query: nil, body: nil, headers: nil)
28
- path = "/lists/#{audience_id}/members/#{subscriber_hash(email)}"
29
+ def update(list_id, email, query: nil, body: nil, headers: nil)
30
+ path = "/lists/#{list_id}/members/#{subscriber_hash(email)}"
29
31
  client.patch(path, query: query, body: body, headers: headers)
30
32
  end
31
33
 
32
- def add_or_update(audience_id, email, query: nil, body: nil, headers: nil)
33
- path = "/lists/#{audience_id}/members/#{subscriber_hash(email)}"
34
+ def add_or_update(list_id, email, query: nil, body: nil, headers: nil)
35
+ path = "/lists/#{list_id}/members/#{subscriber_hash(email)}"
34
36
  client.put(path, query: query, body: body, headers: headers)
35
37
  end
36
38
 
37
- def delete_permanent(audience_id, email, query: nil, body: nil, headers: nil)
38
- path = "/lists/#{audience_id}/members/#{subscriber_hash(email)}/actions/delete-permanent"
39
+ def delete_permanent(list_id, email, query: nil, body: nil, headers: nil)
40
+ path = "/lists/#{list_id}/members/#{subscriber_hash(email)}/actions/delete-permanent"
39
41
  client.post(path, query: query, body: body, headers: headers)
40
42
  end
43
+
44
+ def each(list_id, query: nil, body: nil, headers: nil, &block)
45
+ list_each_item(:members, list_id, query: query, body: body, headers: headers, &block)
46
+ end
41
47
  end
42
48
 
43
49
  include MailchimpAPI::Audience::Utils
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MailchimpAPI
4
+ module Audience
5
+ class Webhooks < Resource
6
+ module APIs
7
+ include Pagination::ListEachItemHelper
8
+
9
+ def list(list_id, query: nil, body: nil, headers: nil)
10
+ path = "/lists/#{list_id}/webhooks"
11
+ client.get(path, query: query, body: body, headers: headers)
12
+ end
13
+
14
+ def create(list_id, query: nil, body: nil, headers: nil)
15
+ path = "/lists/#{list_id}/webhooks"
16
+ client.post(path, query: query, body: body, headers: headers)
17
+ end
18
+
19
+ def show(list_id, webhook_id, query: nil, body: nil, headers: nil)
20
+ path = "/lists/#{list_id}/webhooks/#{webhook_id}"
21
+ client.get(path, query: query, body: body, headers: headers)
22
+ end
23
+
24
+ def delete(list_id, webhook_id, query: nil, body: nil, headers: nil)
25
+ path = "/lists/#{list_id}/webhooks/#{webhook_id}"
26
+ client.delete(path, query: query, body: body, headers: headers)
27
+ end
28
+
29
+ def update(list_id, webhook_id, query: nil, body: nil, headers: nil)
30
+ path = "/lists/#{list_id}/webhooks/#{webhook_id}"
31
+ client.patch(path, query: query, body: body, headers: headers)
32
+ end
33
+
34
+ def each(list_id, query: nil, body: nil, headers: nil, &block)
35
+ list_each_item(:webhooks, list_id, query: query, body: body, headers: headers, &block)
36
+ end
37
+ end
38
+
39
+ include APIs
40
+ extend APIs
41
+ end
42
+ end
43
+ end
data/lib/mailchimp-api.rb CHANGED
@@ -35,8 +35,11 @@ module MailchimpAPI
35
35
 
36
36
  # Resources
37
37
  def_delegators :@client,
38
+ :audience_interest_categories,
39
+ :audience_interests,
40
+ :audience_member_tags,
38
41
  :audience_members,
39
- :audience_member_tags
42
+ :audience_webhooks
40
43
 
41
44
  def client
42
45
  raise "#{name}.client must be set" unless @client
@@ -46,14 +49,18 @@ module MailchimpAPI
46
49
  end
47
50
  end
48
51
 
52
+ require_relative "mailchimp-api/pagination/list_each_item_helper"
53
+ require_relative "mailchimp-api/pagination/prepare_query_params"
49
54
  require_relative "mailchimp-api/resource"
50
55
  require_relative "mailchimp-api/resources/audience/utils/subscriber_hash"
56
+ require_relative "mailchimp-api/resources/audience/interest_categories"
57
+ require_relative "mailchimp-api/resources/audience/interests"
51
58
  require_relative "mailchimp-api/resources/audience/member_tags"
52
59
  require_relative "mailchimp-api/resources/audience/members"
60
+ require_relative "mailchimp-api/resources/audience/webhooks"
53
61
  require_relative "mailchimp-api/batch_request"
54
62
  require_relative "mailchimp-api/client/api_methods"
55
63
  require_relative "mailchimp-api/client/batch_methods"
56
- require_relative "mailchimp-api/client/pagination_methods"
57
64
  require_relative "mailchimp-api/client"
58
65
  require_relative "mailchimp-api/config"
59
66
  require_relative "mailchimp-api/error"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailchimp-rest-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Glushkov
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-04-28 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: Marketing Mailchimp REST API with no dependencies.
13
13
  email:
@@ -23,17 +23,21 @@ files:
23
23
  - lib/mailchimp-api/client.rb
24
24
  - lib/mailchimp-api/client/api_methods.rb
25
25
  - lib/mailchimp-api/client/batch_methods.rb
26
- - lib/mailchimp-api/client/pagination_methods.rb
27
26
  - lib/mailchimp-api/config.rb
28
27
  - lib/mailchimp-api/error.rb
29
28
  - lib/mailchimp-api/failed_request_error_builder.rb
30
29
  - lib/mailchimp-api/network_error_builder.rb
30
+ - lib/mailchimp-api/pagination/list_each_item_helper.rb
31
+ - lib/mailchimp-api/pagination/prepare_query_params.rb
31
32
  - lib/mailchimp-api/request.rb
32
33
  - lib/mailchimp-api/request_executor.rb
33
34
  - lib/mailchimp-api/resource.rb
35
+ - lib/mailchimp-api/resources/audience/interest_categories.rb
36
+ - lib/mailchimp-api/resources/audience/interests.rb
34
37
  - lib/mailchimp-api/resources/audience/member_tags.rb
35
38
  - lib/mailchimp-api/resources/audience/members.rb
36
39
  - lib/mailchimp-api/resources/audience/utils/subscriber_hash.rb
40
+ - lib/mailchimp-api/resources/audience/webhooks.rb
37
41
  - lib/mailchimp-api/response.rb
38
42
  - lib/mailchimp-api/uri_builder.rb
39
43
  - lib/mailchimp-api/version.rb
@@ -59,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
63
  - !ruby/object:Gem::Version
60
64
  version: '0'
61
65
  requirements: []
62
- rubygems_version: 3.6.2
66
+ rubygems_version: 3.6.8
63
67
  specification_version: 4
64
68
  summary: Mailchimp REST API (Marketing)
65
69
  test_files: []
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MailchimpAPI
4
- class Client
5
- module PaginationMethods
6
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
7
- def next_page(response)
8
- unless response.body.key?(:total_items)
9
- raise Error, "Please ensure `total_items` field is not excluded from response"
10
- end
11
-
12
- request = response.request
13
- query = request.query
14
-
15
- count = query.key?(:count) ? query[:count].to_i : 10
16
- offset = query.key?(:offset) ? query[:offset].to_i : 0
17
-
18
- body = response.body
19
- total_items = body[:total_items].to_i
20
- is_final_page = ((offset + count) >= total_items)
21
- return if is_final_page
22
-
23
- new_query = query.merge(offset: offset + count, count: count)
24
-
25
- get(
26
- request.path,
27
- query: new_query,
28
- body: request.body,
29
- headers: request.headers
30
- )
31
- end
32
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
33
-
34
- def each_page(response, &block)
35
- return enum_for(:each_page, response) unless block
36
-
37
- page = response
38
- yield(page)
39
- yield(page) while (page = next_page(page))
40
- end
41
-
42
- def each_page_item(response, items:, &block)
43
- return enum_for(:each_page_item, response, items: items) unless block
44
-
45
- each_page(response) do |page|
46
- page.body.fetch(items).each(&block)
47
- end
48
- end
49
- end
50
- end
51
- end