mailchimp-rest-api 0.0.1 → 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: f7356505754644055f03ee2a25a23910247fc87fb350672e6a1fa3f3ead64626
4
- data.tar.gz: f95ac89a0685693ed4be9afb6f5d78fb2948b724b96ac7d7a130e151ae275573
3
+ metadata.gz: cd8e4ac41f0ff072d449fab1c0466bed09d533def2a97db463a0dd76e47aaef2
4
+ data.tar.gz: 24fccb0d0eb4175d77055bdd5ce4e935789cbd5b6ed700d17f7d98ab86ada034
5
5
  SHA512:
6
- metadata.gz: d40b3c60e6ab469604cbca9c7d10da2a91483e9c9653d461d5c9485c84243162b2996ce17e1466607d25ae970a6da3d2075dcbe39c870b6c13ed5f12603444b6
7
- data.tar.gz: ace08ae4987164126a36da7879ae75a7f4acb571b2f1ca8b61df51a5788410636b5c7d105bae535e51e973f21b67984aece570b221e9f951a1d03f0f400c0bb8
6
+ metadata.gz: 8cc1fa18308afd486cb4418317f8809d9e2758df9a1ea4087aaea57ba66db3570ae91fc99faccd8472a4663f22800151519b5c4c350f750f275a484c147544fe
7
+ data.tar.gz: 0df6d93f8742d35b73372a5b7ce139723102261f046243e77bcb30f90937fa519a93e0c1fd4e267bc67bb5a38c9932907d5a2373a0f27ac49f81d763bd4465f5
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:
@@ -106,8 +152,9 @@ client = MailchimpAPI::Client.new(
106
152
  We have two specific methods:
107
153
 
108
154
  - `MailchimpAPI#each_page(response)` - iterates over current and each next page
109
- - `MailchimpAPI#each_page_item(response, items_field_name)` - iterates over
110
- items on each page
155
+ response
156
+ - `MailchimpAPI#each_page_item(response, items: :members)` - iterates over
157
+ each item (each member in this case)
111
158
 
112
159
  Example:
113
160
 
@@ -118,7 +165,7 @@ MailchimpAPI.each_page(first_page) do |response|
118
165
  puts response.body
119
166
  end
120
167
 
121
- MailchimpAPI.each_page_item(first_page, :members) do |item|
168
+ MailchimpAPI.each_page_item(first_page, items: :members) do |item|
122
169
  puts item[:email_address]
123
170
  end
124
171
  ```
@@ -127,13 +174,46 @@ end
127
174
 
128
175
  ...
129
176
 
130
- ## Errors
177
+ ## APIs
131
178
 
132
- ...
179
+ ### Audience Members
133
180
 
134
- ## APIs
181
+ - List `MailchimpAPI.audience_members.get(audience_id)`
182
+ - Create `MailchimpAPI.audience_members.create(audience_id, body: body)`
183
+ - Show `MailchimpAPI.audience_members.show(audience_id, email)`
184
+ - Update `MailchimpAPI.audience_members.update(audience_id, email, body: body)`
185
+ - Add or Update `MailchimpAPI.audience_members.add_or_update(audience_id, email, body: body)`
186
+ - Archive `MailchimpAPI.audience_members.delete(audience_id, email)`
187
+ - Delete Permanently `MailchimpAPI.audience_members.delete(audience_id, email)`
135
188
 
136
- ...
189
+ ### Audience Member Tags
190
+
191
+ - List `MailchimpAPI.audience_member_tags.get(audience_id, email)`
192
+ - Create `MailchimpAPI.audience_member_tags.create(audience_id, email, body: body)`
193
+
194
+ ### Audience Webhooks
195
+
196
+ - List `MailchimpAPI.audience_webhooks.get(audience_id)`
197
+ - Create `MailchimpAPI.audience_webhooks.create(audience_id, body: body)`
198
+ - Show `MailchimpAPI.audience_webhooks.show(audience_id, webhook_id)`
199
+ - Update `MailchimpAPI.audience_webhooks.update(audience_id, webhook_id, body: body)`
200
+ - Delete `MailchimpAPI.audience_webhooks.delete(audience_id, webhook_id)`
201
+
202
+ ### Audience Interest Categories
203
+
204
+ - List `MailchimpAPI.audience_interest_categories.get(audience_id)`
205
+ - Create `MailchimpAPI.audience_interest_categories.create(audience_id, body: body)`
206
+ - Show `MailchimpAPI.audience_interest_categories.show(audience_id, webhook_id)`
207
+ - Update `MailchimpAPI.audience_interest_categories.update(audience_id, webhook_id, body: body)`
208
+ - Delete `MailchimpAPI.audience_interest_categories.delete(audience_id, webhook_id)`
209
+
210
+ ### Audience Interests
211
+
212
+ - List `MailchimpAPI.audience_interests.get(audience_id)`
213
+ - Create `MailchimpAPI.audience_interests.create(audience_id, body: body)`
214
+ - Show `MailchimpAPI.audience_interests.show(audience_id, webhook_id)`
215
+ - Update `MailchimpAPI.audience_interests.update(audience_id, webhook_id, body: body)`
216
+ - Delete `MailchimpAPI.audience_interests.delete(audience_id, webhook_id)`
137
217
 
138
218
  ## Development
139
219
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.2.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
@@ -39,11 +39,11 @@ module MailchimpAPI
39
39
  yield(page) while (page = next_page(page))
40
40
  end
41
41
 
42
- def each_page_item(response, items_field_name, &block)
43
- return enum_for(:each_page_item, response, items_field_name) unless block
42
+ def each_page_item(response, items:, &block)
43
+ return enum_for(:each_page_item, response, items: items) unless block
44
44
 
45
45
  each_page(response) do |page|
46
- page.body.fetch(items_field_name).each(&block)
46
+ page.body.fetch(items).each(&block)
47
47
  end
48
48
  end
49
49
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MailchimpAPI
4
+ module Audience
5
+ class InterestCategories < Resource
6
+ module APIs
7
+ def list(list_id, query: nil, body: nil, headers: nil)
8
+ path = "/lists/#{list_id}/interest-categories"
9
+ client.get(path, query: query, body: body, headers: headers)
10
+ end
11
+
12
+ def create(list_id, query: nil, body: nil, headers: nil)
13
+ path = "/lists/#{list_id}/interest-categories"
14
+ client.post(path, query: query, body: body, headers: headers)
15
+ end
16
+
17
+ def show(list_id, interest_category_id, query: nil, body: nil, headers: nil)
18
+ path = "/lists/#{list_id}/interest-categories/#{interest_category_id}"
19
+ client.get(path, query: query, body: body, headers: headers)
20
+ end
21
+
22
+ def delete(list_id, interest_category_id, query: nil, body: nil, headers: nil)
23
+ path = "/lists/#{list_id}/interest-categories/#{interest_category_id}"
24
+ client.delete(path, query: query, body: body, headers: headers)
25
+ end
26
+
27
+ def update(list_id, interest_category_id, query: nil, body: nil, headers: nil)
28
+ path = "/lists/#{list_id}/interest-categories/#{interest_category_id}"
29
+ client.patch(path, query: query, body: body, headers: headers)
30
+ end
31
+ end
32
+
33
+ include APIs
34
+ extend APIs
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MailchimpAPI
4
+ module Audience
5
+ class Interests < Resource
6
+ module APIs
7
+ def list(list_id, interest_category_id, query: nil, body: nil, headers: nil)
8
+ path = "/lists/#{list_id}/interest-categories/#{interest_category_id}/interests"
9
+ client.get(path, query: query, body: body, headers: headers)
10
+ end
11
+
12
+ def create(list_id, interest_category_id, query: nil, body: nil, headers: nil)
13
+ path = "/lists/#{list_id}/interest-categories/#{interest_category_id}/interests"
14
+ client.post(path, query: query, body: body, headers: headers)
15
+ end
16
+
17
+ def show(list_id, interest_category_id, interest_id, query: nil, body: nil, headers: nil)
18
+ path = "/lists/#{list_id}/interest-categories/#{interest_category_id}/interests/#{interest_id}"
19
+ client.get(path, query: query, body: body, headers: headers)
20
+ end
21
+
22
+ def delete(list_id, interest_category_id, interest_id, query: nil, body: nil, headers: nil)
23
+ path = "/lists/#{list_id}/interest-categories/#{interest_category_id}/interests/#{interest_id}"
24
+ client.delete(path, query: query, body: body, headers: headers)
25
+ end
26
+
27
+ def update(list_id, interest_category_id, interest_id, query: nil, body: nil, headers: nil)
28
+ path = "/lists/#{list_id}/interest-categories/#{interest_category_id}/interests/#{interest_id}"
29
+ client.patch(path, query: query, body: body, headers: headers)
30
+ end
31
+ end
32
+
33
+ include APIs
34
+ extend APIs
35
+ end
36
+ end
37
+ end
@@ -4,13 +4,13 @@ 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
+ def list(list_id, email, query: nil, body: nil, headers: nil)
8
+ path = "/lists/#{list_id}/members/#{subscriber_hash(email)}/tags"
9
9
  client.get(path, query: query, body: body, headers: headers)
10
10
  end
11
11
 
12
- def create(audience_id, email, query: nil, body: nil, headers: nil)
13
- path = "/lists/#{audience_id}/members/#{subscriber_hash(email)}/tags"
12
+ def create(list_id, email, query: nil, body: nil, headers: nil)
13
+ path = "/lists/#{list_id}/members/#{subscriber_hash(email)}/tags"
14
14
  client.post(path, query: query, body: body, headers: headers)
15
15
  end
16
16
  end
@@ -4,38 +4,38 @@ 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
+ def list(list_id, query: nil, body: nil, headers: nil)
8
+ path = "/lists/#{list_id}/members"
9
9
  client.get(path, query: query, body: body, headers: headers)
10
10
  end
11
11
 
12
- def create(audience_id, query: nil, body: nil, headers: nil)
13
- path = "/lists/#{audience_id}/members"
12
+ def create(list_id, query: nil, body: nil, headers: nil)
13
+ path = "/lists/#{list_id}/members"
14
14
  client.post(path, query: query, body: body, headers: headers)
15
15
  end
16
16
 
17
- def show(audience_id, email, query: nil, body: nil, headers: nil)
18
- path = "/lists/#{audience_id}/members/#{subscriber_hash(email)}"
17
+ def show(list_id, email, query: nil, body: nil, headers: nil)
18
+ path = "/lists/#{list_id}/members/#{subscriber_hash(email)}"
19
19
  client.get(path, query: query, body: body, headers: headers)
20
20
  end
21
21
 
22
- def archive(audience_id, email, query: nil, body: nil, headers: nil)
23
- path = "/lists/#{audience_id}/members/#{subscriber_hash(email)}"
22
+ def archive(list_id, email, query: nil, body: nil, headers: nil)
23
+ path = "/lists/#{list_id}/members/#{subscriber_hash(email)}"
24
24
  client.delete(path, query: query, body: body, headers: headers)
25
25
  end
26
26
 
27
- def update(audience_id, email, query: nil, body: nil, headers: nil)
28
- path = "/lists/#{audience_id}/members/#{subscriber_hash(email)}"
27
+ def update(list_id, email, query: nil, body: nil, headers: nil)
28
+ path = "/lists/#{list_id}/members/#{subscriber_hash(email)}"
29
29
  client.patch(path, query: query, body: body, headers: headers)
30
30
  end
31
31
 
32
- def add_or_update(audience_id, email, query: nil, body: nil, headers: nil)
33
- path = "/lists/#{audience_id}/members/#{subscriber_hash(email)}"
32
+ def add_or_update(list_id, email, query: nil, body: nil, headers: nil)
33
+ path = "/lists/#{list_id}/members/#{subscriber_hash(email)}"
34
34
  client.put(path, query: query, body: body, headers: headers)
35
35
  end
36
36
 
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"
37
+ def delete_permanent(list_id, email, query: nil, body: nil, headers: nil)
38
+ path = "/lists/#{list_id}/members/#{subscriber_hash(email)}/actions/delete-permanent"
39
39
  client.post(path, query: query, body: body, headers: headers)
40
40
  end
41
41
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MailchimpAPI
4
+ module Audience
5
+ class Webhooks < Resource
6
+ module APIs
7
+ def list(list_id, query: nil, body: nil, headers: nil)
8
+ path = "/lists/#{list_id}/webhooks"
9
+ client.get(path, query: query, body: body, headers: headers)
10
+ end
11
+
12
+ def create(list_id, query: nil, body: nil, headers: nil)
13
+ path = "/lists/#{list_id}/webhooks"
14
+ client.post(path, query: query, body: body, headers: headers)
15
+ end
16
+
17
+ def show(list_id, webhook_id, query: nil, body: nil, headers: nil)
18
+ path = "/lists/#{list_id}/webhooks/#{webhook_id}"
19
+ client.get(path, query: query, body: body, headers: headers)
20
+ end
21
+
22
+ def delete(list_id, webhook_id, query: nil, body: nil, headers: nil)
23
+ path = "/lists/#{list_id}/webhooks/#{webhook_id}"
24
+ client.delete(path, query: query, body: body, headers: headers)
25
+ end
26
+
27
+ def update(list_id, webhook_id, query: nil, body: nil, headers: nil)
28
+ path = "/lists/#{list_id}/webhooks/#{webhook_id}"
29
+ client.patch(path, query: query, body: body, headers: headers)
30
+ end
31
+ end
32
+
33
+ include APIs
34
+ extend APIs
35
+ end
36
+ end
37
+ 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
@@ -48,8 +51,11 @@ end
48
51
 
49
52
  require_relative "mailchimp-api/resource"
50
53
  require_relative "mailchimp-api/resources/audience/utils/subscriber_hash"
54
+ require_relative "mailchimp-api/resources/audience/interest_categories"
55
+ require_relative "mailchimp-api/resources/audience/interests"
51
56
  require_relative "mailchimp-api/resources/audience/member_tags"
52
57
  require_relative "mailchimp-api/resources/audience/members"
58
+ require_relative "mailchimp-api/resources/audience/webhooks"
53
59
  require_relative "mailchimp-api/batch_request"
54
60
  require_relative "mailchimp-api/client/api_methods"
55
61
  require_relative "mailchimp-api/client/batch_methods"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailchimp-rest-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Glushkov
@@ -11,7 +11,7 @@ date: 2025-04-28 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: Marketing Mailchimp REST API with no dependencies.
13
13
  email:
14
- - aglushkov@shakuro.com
14
+ - andreyruby@yandex.ru
15
15
  executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
@@ -31,20 +31,23 @@ files:
31
31
  - lib/mailchimp-api/request.rb
32
32
  - lib/mailchimp-api/request_executor.rb
33
33
  - lib/mailchimp-api/resource.rb
34
+ - lib/mailchimp-api/resources/audience/interest_categories.rb
35
+ - lib/mailchimp-api/resources/audience/interests.rb
34
36
  - lib/mailchimp-api/resources/audience/member_tags.rb
35
37
  - lib/mailchimp-api/resources/audience/members.rb
36
38
  - lib/mailchimp-api/resources/audience/utils/subscriber_hash.rb
39
+ - lib/mailchimp-api/resources/audience/webhooks.rb
37
40
  - lib/mailchimp-api/response.rb
38
41
  - lib/mailchimp-api/uri_builder.rb
39
42
  - lib/mailchimp-api/version.rb
40
43
  - lib/mailchimp-rest-api.rb
41
- homepage: https://github.com/aglushkov/mailchimp-rest-api
44
+ homepage: https://github.com/andreyruby/mailchimp-rest-api
42
45
  licenses:
43
46
  - MIT
44
47
  metadata:
45
- source_code_uri: https://github.com/aglushkov/mailchimp-rest-api
48
+ source_code_uri: https://github.com/andreyruby/mailchimp-rest-api
46
49
  documentation_uri: https://www.rubydoc.info/gems/mailchimp-rest-api
47
- changelog_uri: https://github.com/aglushkov/mailchimp-rest-api/blob/master/CHANGELOG.md
50
+ changelog_uri: https://github.com/andreyruby/mailchimp-rest-api/blob/master/CHANGELOG.md
48
51
  rdoc_options: []
49
52
  require_paths:
50
53
  - lib