mailchimp-rest-api 0.2.0 → 0.4.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.
@@ -2,32 +2,101 @@
2
2
 
3
3
  module MailchimpAPI
4
4
  module Audience
5
+ # Provides methods for interacting with Mailchimp interest categories
6
+ # Interest categories help organize groups of interests that subscribers can opt into
5
7
  class InterestCategories < Resource
8
+ # Module with endpoints for InterestCategories
6
9
  module APIs
10
+ include Pagination::ListEachItemHelper
11
+
12
+ # List all interest categories for a specific list
13
+ # @param list_id [String] The ID of the Mailchimp list
14
+ # @param query [Hash] Optional query parameters
15
+ # @param body [Hash] Optional request body
16
+ # @param headers [Hash] Optional request headers
17
+ # @return [Hash] API response containing interest categories
18
+ # @example Get all interest categories for a list
19
+ # interest_categories.list('list123')
7
20
  def list(list_id, query: nil, body: nil, headers: nil)
8
21
  path = "/lists/#{list_id}/interest-categories"
9
22
  client.get(path, query: query, body: body, headers: headers)
10
23
  end
11
24
 
25
+ # Create a new interest category
26
+ # @param list_id [String] The ID of the Mailchimp list
27
+ # @param query [Hash] Optional query parameters
28
+ # @param body [Hash] Interest category attributes
29
+ # @option body [String] :title The title of the interest category
30
+ # @option body [String] :type The type of interest category (checkboxes, dropdown, radio, hidden)
31
+ # @param headers [Hash] Optional request headers
32
+ # @return [Hash] API response containing the created interest category
33
+ # @example Create a checkbox interest category
34
+ # interest_categories.create('list123', body: {
35
+ # title: 'Favorite Products',
36
+ # type: 'checkboxes'
37
+ # })
12
38
  def create(list_id, query: nil, body: nil, headers: nil)
13
39
  path = "/lists/#{list_id}/interest-categories"
14
40
  client.post(path, query: query, body: body, headers: headers)
15
41
  end
16
42
 
43
+ # Show details for a specific interest category
44
+ # @param list_id [String] The ID of the Mailchimp list
45
+ # @param interest_category_id [String] The ID of the interest category
46
+ # @param query [Hash] Optional query parameters
47
+ # @param body [Hash] Optional request body
48
+ # @param headers [Hash] Optional request headers
49
+ # @return [Hash] API response containing interest category details
50
+ # @example Get details for an interest category
51
+ # interest_categories.show('list123', 'category456')
17
52
  def show(list_id, interest_category_id, query: nil, body: nil, headers: nil)
18
53
  path = "/lists/#{list_id}/interest-categories/#{interest_category_id}"
19
54
  client.get(path, query: query, body: body, headers: headers)
20
55
  end
21
56
 
57
+ # Delete an interest category
58
+ # @param list_id [String] The ID of the Mailchimp list
59
+ # @param interest_category_id [String] The ID of the interest category to delete
60
+ # @param query [Hash] Optional query parameters
61
+ # @param body [Hash] Optional request body
62
+ # @param headers [Hash] Optional request headers
63
+ # @return [Boolean] True if successful
64
+ # @example Delete an interest category
65
+ # interest_categories.delete('list123', 'category456')
22
66
  def delete(list_id, interest_category_id, query: nil, body: nil, headers: nil)
23
67
  path = "/lists/#{list_id}/interest-categories/#{interest_category_id}"
24
68
  client.delete(path, query: query, body: body, headers: headers)
25
69
  end
26
70
 
71
+ # Update an interest category
72
+ # @param list_id [String] The ID of the Mailchimp list
73
+ # @param interest_category_id [String] The ID of the interest category to update
74
+ # @param query [Hash] Optional query parameters
75
+ # @param body [Hash] Updated interest category attributes
76
+ # @param headers [Hash] Optional request headers
77
+ # @return [Hash] API response containing updated interest category
78
+ # @example Update an interest category title
79
+ # interest_categories.update('list123', 'category456', body: {
80
+ # title: 'Updated Category Name'
81
+ # })
27
82
  def update(list_id, interest_category_id, query: nil, body: nil, headers: nil)
28
83
  path = "/lists/#{list_id}/interest-categories/#{interest_category_id}"
29
84
  client.patch(path, query: query, body: body, headers: headers)
30
85
  end
86
+
87
+ # Iterate through all interest categories for a list
88
+ # @param list_id [String] The ID of the Mailchimp list
89
+ # @param query [Hash] Optional query parameters
90
+ # @param body [Hash] Optional request body
91
+ # @param headers [Hash] Optional request headers
92
+ # @yield [Hash] Each interest category
93
+ # @example Iterate through interest categories
94
+ # interest_categories.each('list123') do |category|
95
+ # puts category[:title]
96
+ # end
97
+ def each(list_id, query: nil, body: nil, headers: nil, &block)
98
+ list_each_item(:categories, list_id, query: query, body: body, headers: headers, &block)
99
+ end
31
100
  end
32
101
 
33
102
  include APIs
@@ -2,32 +2,104 @@
2
2
 
3
3
  module MailchimpAPI
4
4
  module Audience
5
+ # Provides methods for interacting with Mailchimp interests
6
+ # Interests allow subscribers to opt into specific content categories
5
7
  class Interests < Resource
8
+ # Module with endpoints for Interests APIs
6
9
  module APIs
10
+ include Pagination::ListEachItemHelper
11
+
12
+ # List all interests in a specific interest category
13
+ # @param list_id [String] The ID of the Mailchimp list
14
+ # @param interest_category_id [String] The ID of the interest category
15
+ # @param query [Hash] Optional query parameters
16
+ # @param body [Hash] Optional request body
17
+ # @param headers [Hash] Optional request headers
18
+ # @return [Hash] API response containing interests
19
+ # @example Get all interests in a category
20
+ # interests.list('list123', 'category456')
7
21
  def list(list_id, interest_category_id, query: nil, body: nil, headers: nil)
8
22
  path = "/lists/#{list_id}/interest-categories/#{interest_category_id}/interests"
9
23
  client.get(path, query: query, body: body, headers: headers)
10
24
  end
11
25
 
26
+ # Create a new interest
27
+ # @param list_id [String] The ID of the Mailchimp list
28
+ # @param interest_category_id [String] The ID of the interest category
29
+ # @param query [Hash] Optional query parameters
30
+ # @param body [Hash] Interest attributes
31
+ # @option body [String] :name The name of the interest
32
+ # @param headers [Hash] Optional request headers
33
+ # @return [Hash] API response containing the created interest
34
+ # @example Create a new interest
35
+ # interests.create('list123', 'category456', body: {
36
+ # name: 'Product Updates'
37
+ # })
12
38
  def create(list_id, interest_category_id, query: nil, body: nil, headers: nil)
13
39
  path = "/lists/#{list_id}/interest-categories/#{interest_category_id}/interests"
14
40
  client.post(path, query: query, body: body, headers: headers)
15
41
  end
16
42
 
43
+ # Show details for a specific interest
44
+ # @param list_id [String] The ID of the Mailchimp list
45
+ # @param interest_category_id [String] The ID of the interest category
46
+ # @param interest_id [String] The ID of the interest
47
+ # @param query [Hash] Optional query parameters
48
+ # @param body [Hash] Optional request body
49
+ # @param headers [Hash] Optional request headers
50
+ # @return [Hash] API response containing interest details
51
+ # @example Get details for an interest
52
+ # interests.show('list123', 'category456', 'interest789')
17
53
  def show(list_id, interest_category_id, interest_id, query: nil, body: nil, headers: nil)
18
54
  path = "/lists/#{list_id}/interest-categories/#{interest_category_id}/interests/#{interest_id}"
19
55
  client.get(path, query: query, body: body, headers: headers)
20
56
  end
21
57
 
58
+ # Delete an interest
59
+ # @param list_id [String] The ID of the Mailchimp list
60
+ # @param interest_category_id [String] The ID of the interest category
61
+ # @param interest_id [String] The ID of the interest to delete
62
+ # @param query [Hash] Optional query parameters
63
+ # @param body [Hash] Optional request body
64
+ # @param headers [Hash] Optional request headers
65
+ # @return [Boolean] True if successful
66
+ # @example Delete an interest
67
+ # interests.delete('list123', 'category456', 'interest789')
22
68
  def delete(list_id, interest_category_id, interest_id, query: nil, body: nil, headers: nil)
23
69
  path = "/lists/#{list_id}/interest-categories/#{interest_category_id}/interests/#{interest_id}"
24
70
  client.delete(path, query: query, body: body, headers: headers)
25
71
  end
26
72
 
73
+ # Update an interest
74
+ # @param list_id [String] The ID of the Mailchimp list
75
+ # @param interest_category_id [String] The ID of the interest category
76
+ # @param interest_id [String] The ID of the interest to update
77
+ # @param query [Hash] Optional query parameters
78
+ # @param body [Hash] Updated interest attributes
79
+ # @param headers [Hash] Optional request headers
80
+ # @return [Hash] API response containing updated interest
81
+ # @example Update an interest name
82
+ # interests.update('list123', 'category456', 'interest789', body: {
83
+ # name: 'Updated Interest Name'
84
+ # })
27
85
  def update(list_id, interest_category_id, interest_id, query: nil, body: nil, headers: nil)
28
86
  path = "/lists/#{list_id}/interest-categories/#{interest_category_id}/interests/#{interest_id}"
29
87
  client.patch(path, query: query, body: body, headers: headers)
30
88
  end
89
+
90
+ # Iterate through all interests in an interest category
91
+ # @param list_id [String] The ID of the Mailchimp list
92
+ # @param query [Hash] Optional query parameters
93
+ # @param body [Hash] Optional request body
94
+ # @param headers [Hash] Optional request headers
95
+ # @yield [Hash] Each interest
96
+ # @example Iterate through interest in category
97
+ # interests.each('list123') do |interest|
98
+ # puts interest[:name]
99
+ # end
100
+ def each(list_id, interest_category_id, query: nil, body: nil, headers: nil, &block)
101
+ list_each_item(:interests, list_id, interest_category_id, query: query, body: body, headers: headers, &block)
102
+ end
31
103
  end
32
104
 
33
105
  include APIs
@@ -2,21 +2,64 @@
2
2
 
3
3
  module MailchimpAPI
4
4
  module Audience
5
+ # Provides methods for interacting with Mailchimp member tags
6
+ # Tags help organize and segment your subscribers
5
7
  class MemberTags < Resource
8
+ # Module with endpoints for MemberTags APIs
6
9
  module APIs
10
+ include Pagination::ListEachItemHelper
11
+ include MailchimpAPI::Audience::Utils
12
+
13
+ # List all tags for a specific member
14
+ # @param list_id [String] The ID of the Mailchimp list
15
+ # @param email [String] The member's email address
16
+ # @param query [Hash] Optional query parameters
17
+ # @param body [Hash] Optional request body
18
+ # @param headers [Hash] Optional request headers
19
+ # @return [Hash] API response containing member tags
20
+ # @example Get all tags for a member
21
+ # member_tags.list('list123', 'user@example.com')
7
22
  def list(list_id, email, query: nil, body: nil, headers: nil)
8
23
  path = "/lists/#{list_id}/members/#{subscriber_hash(email)}/tags"
9
24
  client.get(path, query: query, body: body, headers: headers)
10
25
  end
11
26
 
27
+ # Add or update tags for a member
28
+ # @param list_id [String] The ID of the Mailchimp list
29
+ # @param email [String] The member's email address
30
+ # @param query [Hash] Optional query parameters
31
+ # @param body [Hash] Tags to add/update
32
+ # @option body [Array<Hash>] :tags Array of tag objects
33
+ # @param headers [Hash] Optional request headers
34
+ # @return [Hash] API response containing update status
35
+ # @example Add tags to a member
36
+ # member_tags.create('list123', 'user@example.com', body: {
37
+ # tags: [
38
+ # { name: 'Customer', status: 'active' },
39
+ # { name: 'VIP', status: 'active' }
40
+ # ]
41
+ # })
12
42
  def create(list_id, email, query: nil, body: nil, headers: nil)
13
43
  path = "/lists/#{list_id}/members/#{subscriber_hash(email)}/tags"
14
44
  client.post(path, query: query, body: body, headers: headers)
15
45
  end
46
+
47
+ # Iterate through all tags for a member
48
+ # @param list_id [String] The ID of the Mailchimp list
49
+ # @param email [String] The member's email address
50
+ # @param query [Hash] Optional query parameters
51
+ # @param body [Hash] Optional request body
52
+ # @param headers [Hash] Optional request headers
53
+ # @yield [Hash] Each member tag
54
+ # @example Iterate through member tags
55
+ # member_tags.each('list123', 'user@example.com') do |tag|
56
+ # puts tag[:name]
57
+ # end
58
+ def each(list_id, email, query: nil, body: nil, headers: nil, &block)
59
+ list_each_item(:tags, list_id, email, query: query, body: body, headers: headers, &block)
60
+ end
16
61
  end
17
62
 
18
- include MailchimpAPI::Audience::Utils
19
- extend MailchimpAPI::Audience::Utils
20
63
  include APIs
21
64
  extend APIs
22
65
  end
@@ -1,47 +1,143 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MailchimpAPI
4
+ # Contains classes related to Audiences APIs collection
4
5
  module Audience
6
+ # Provides methods for interacting with Mailchimp list members
7
+ # Members are subscribers who belong to a Mailchimp list
5
8
  class Members < Resource
9
+ # Module with endpoints for Members APIs
6
10
  module APIs
11
+ include Pagination::ListEachItemHelper
12
+ include MailchimpAPI::Audience::Utils
13
+
14
+ # List all members in a specific list
15
+ # @param list_id [String] The ID of the Mailchimp list
16
+ # @param query [Hash] Optional query parameters
17
+ # @option query [Integer] :count Number of records to return (default: 10)
18
+ # @option query [Integer] :offset Number of records to skip (default: 0)
19
+ # @param body [Hash] Optional request body
20
+ # @param headers [Hash] Optional request headers
21
+ # @return [Hash] API response containing list members
22
+ # @example Get first 10 members of a list
23
+ # members.list('list123')
24
+ # @example Get members 11-20
25
+ # members.list('list123', query: { count: 10, offset: 10 })
7
26
  def list(list_id, query: nil, body: nil, headers: nil)
8
27
  path = "/lists/#{list_id}/members"
9
28
  client.get(path, query: query, body: body, headers: headers)
10
29
  end
11
30
 
31
+ # Add a new member to a list
32
+ # @param list_id [String] The ID of the Mailchimp list
33
+ # @param query [Hash] Optional query parameters
34
+ # @param body [Hash] Member attributes
35
+ # @option body [String] :email_address The member's email address
36
+ # @option body [String] :status Subscription status (subscribed, unsubscribed, etc.)
37
+ # @option body [Hash] :merge_fields Merge fields like FNAME, LNAME
38
+ # @param headers [Hash] Optional request headers
39
+ # @return [Hash] API response containing the created member
40
+ # @example Add a new subscriber
41
+ # members.create('list123', body: {
42
+ # email_address: 'new@example.com',
43
+ # status: 'subscribed',
44
+ # merge_fields: { FNAME: 'John', LNAME: 'Doe' }
45
+ # })
12
46
  def create(list_id, query: nil, body: nil, headers: nil)
13
47
  path = "/lists/#{list_id}/members"
14
48
  client.post(path, query: query, body: body, headers: headers)
15
49
  end
16
50
 
51
+ # Show details for a specific member
52
+ # @param list_id [String] The ID of the Mailchimp list
53
+ # @param email [String] The member's email address
54
+ # @param query [Hash] Optional query parameters
55
+ # @param body [Hash] Optional request body
56
+ # @param headers [Hash] Optional request headers
57
+ # @return [Hash] API response containing member details
58
+ # @example Get member details
59
+ # members.show('list123', 'user@example.com')
17
60
  def show(list_id, email, query: nil, body: nil, headers: nil)
18
61
  path = "/lists/#{list_id}/members/#{subscriber_hash(email)}"
19
62
  client.get(path, query: query, body: body, headers: headers)
20
63
  end
21
64
 
65
+ # Archive a list member (soft delete)
66
+ # @param list_id [String] The ID of the Mailchimp list
67
+ # @param email [String] The member's email address
68
+ # @param query [Hash] Optional query parameters
69
+ # @param body [Hash] Optional request body
70
+ # @param headers [Hash] Optional request headers
71
+ # @return [Boolean] True if successful
72
+ # @example Archive a member
73
+ # members.archive('list123', 'user@example.com')
22
74
  def archive(list_id, email, query: nil, body: nil, headers: nil)
23
75
  path = "/lists/#{list_id}/members/#{subscriber_hash(email)}"
24
76
  client.delete(path, query: query, body: body, headers: headers)
25
77
  end
26
78
 
79
+ # Update a list member
80
+ # @param list_id [String] The ID of the Mailchimp list
81
+ # @param email [String] The member's email address
82
+ # @param query [Hash] Optional query parameters
83
+ # @param body [Hash] Updated member attributes
84
+ # @param headers [Hash] Optional request headers
85
+ # @return [Hash] API response containing updated member
86
+ # @example Update member status
87
+ # members.update('list123', 'user@example.com', body: {
88
+ # status: 'unsubscribed'
89
+ # })
27
90
  def update(list_id, email, query: nil, body: nil, headers: nil)
28
91
  path = "/lists/#{list_id}/members/#{subscriber_hash(email)}"
29
92
  client.patch(path, query: query, body: body, headers: headers)
30
93
  end
31
94
 
95
+ # Add or update a list member
96
+ # @param list_id [String] The ID of the Mailchimp list
97
+ # @param email [String] The member's email address
98
+ # @param query [Hash] Optional query parameters
99
+ # @param body [Hash] Member attributes
100
+ # @param headers [Hash] Optional request headers
101
+ # @return [Hash] API response containing the member
102
+ # @example Add or update a member
103
+ # members.add_or_update('list123', 'user@example.com', body: {
104
+ # status: 'subscribed',
105
+ # merge_fields: { FNAME: 'Updated Name' }
106
+ # })
32
107
  def add_or_update(list_id, email, query: nil, body: nil, headers: nil)
33
108
  path = "/lists/#{list_id}/members/#{subscriber_hash(email)}"
34
109
  client.put(path, query: query, body: body, headers: headers)
35
110
  end
36
111
 
112
+ # Permanently delete a list member
113
+ # @param list_id [String] The ID of the Mailchimp list
114
+ # @param email [String] The member's email address
115
+ # @param query [Hash] Optional query parameters
116
+ # @param body [Hash] Optional request body
117
+ # @param headers [Hash] Optional request headers
118
+ # @return [Boolean] True if successful
119
+ # @example Permanently delete a member
120
+ # members.delete_permanent('list123', 'user@example.com')
37
121
  def delete_permanent(list_id, email, query: nil, body: nil, headers: nil)
38
122
  path = "/lists/#{list_id}/members/#{subscriber_hash(email)}/actions/delete-permanent"
39
123
  client.post(path, query: query, body: body, headers: headers)
40
124
  end
125
+
126
+ # Iterate through all members in a list
127
+ # @param list_id [String] The ID of the Mailchimp list
128
+ # @param query [Hash] Optional query parameters
129
+ # @param body [Hash] Optional request body
130
+ # @param headers [Hash] Optional request headers
131
+ # @yield [Hash] Each list member
132
+ # @example Iterate through list members
133
+ # members.each('list123') do |member|
134
+ # puts member[:email_address]
135
+ # end
136
+ def each(list_id, query: nil, body: nil, headers: nil, &block)
137
+ list_each_item(:members, list_id, query: query, body: body, headers: headers, &block)
138
+ end
41
139
  end
42
140
 
43
- include MailchimpAPI::Audience::Utils
44
- extend MailchimpAPI::Audience::Utils
45
141
  include APIs
46
142
  extend APIs
47
143
  end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MailchimpAPI
4
+ module Audience
5
+ # Provides methods for interacting with Mailchimp segment members
6
+ # Segment members are subscribers who belong to a specific segment
7
+ class SegmentMembers < Resource
8
+ # Module with endpoints for SegmentMembers APIs
9
+ module APIs
10
+ include Pagination::ListEachItemHelper
11
+ include MailchimpAPI::Audience::Utils
12
+
13
+ # List all members in a specific segment
14
+ # @param list_id [String] The ID of the Mailchimp list
15
+ # @param segment_id [String] The ID of the segment
16
+ # @param query [Hash] Optional query parameters
17
+ # @param body [Hash] Optional request body
18
+ # @param headers [Hash] Optional request headers
19
+ # @return [Hash] API response containing segment members
20
+ # @example Get all members in a segment
21
+ # segment_members.list('list123', 'segment456')
22
+ def list(list_id, segment_id, query: nil, body: nil, headers: nil)
23
+ path = "/lists/#{list_id}/segments/#{segment_id}/members"
24
+ client.get(path, query: query, body: body, headers: headers)
25
+ end
26
+
27
+ # Add a member to a static segment
28
+ # @param list_id [String] The ID of the Mailchimp list
29
+ # @param segment_id [String] The ID of the segment
30
+ # @param query [Hash] Optional query parameters
31
+ # @param body [Hash] Member details
32
+ # @param headers [Hash] Optional request headers
33
+ # @return [Hash] API response containing the added member
34
+ # @example Add a member to a segment
35
+ # segment_members.create('list123', 'segment456', body: {
36
+ # email_address: 'new@example.com'
37
+ # })
38
+ def create(list_id, segment_id, query: nil, body: nil, headers: nil)
39
+ path = "/lists/#{list_id}/segments/#{segment_id}/members"
40
+ client.post(path, query: query, body: body, headers: headers)
41
+ end
42
+
43
+ # Remove a member from a static segment
44
+ # @param list_id [String] The ID of the Mailchimp list
45
+ # @param segment_id [String] The ID of the segment
46
+ # @param email [String] The email address of the member to remove
47
+ # @param query [Hash] Optional query parameters
48
+ # @param body [Hash] Optional request body
49
+ # @param headers [Hash] Optional request headers
50
+ # @return [Boolean] True if successful
51
+ # @example Remove a member from a segment
52
+ # segment_members.delete('list123', 'segment456', 'user@example.com')
53
+ def delete(list_id, segment_id, email, query: nil, body: nil, headers: nil)
54
+ path = "/lists/#{list_id}/segments/#{segment_id}/members/#{subscriber_hash(email)}"
55
+ client.delete(path, query: query, body: body, headers: headers)
56
+ end
57
+
58
+ # Iterate through all members in a segment
59
+ # @param list_id [String] The ID of the Mailchimp list
60
+ # @param segment_id [String] The ID of the segment
61
+ # @param query [Hash] Optional query parameters
62
+ # @param body [Hash] Optional request body
63
+ # @param headers [Hash] Optional request headers
64
+ # @yield [Hash] Each segment member
65
+ # @example Iterate through segment members
66
+ # segment_members.each('list123', 'segment456') do |member|
67
+ # puts member[:email_address]
68
+ # end
69
+ def each(list_id, segment_id, query: nil, body: nil, headers: nil, &block)
70
+ list_each_item(:members, list_id, segment_id, query: query, body: body, headers: headers, &block)
71
+ end
72
+ end
73
+
74
+ include APIs
75
+ extend APIs
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MailchimpAPI
4
+ module Audience
5
+ # Provides methods for interacting with Mailchimp segments
6
+ # Segments allow you to group subscribers based on specific conditions
7
+ class Segments < Resource
8
+ # Module with endpoints for Segments APIs
9
+ module APIs
10
+ include Pagination::ListEachItemHelper
11
+
12
+ # List all segments for a specific list
13
+ # @param list_id [String] The ID of the Mailchimp list
14
+ # @param query [Hash] Optional query parameters
15
+ # @param body [Hash] Optional request body
16
+ # @param headers [Hash] Optional request headers
17
+ # @return [Hash] API response containing segments
18
+ # @example Get all segments for a list
19
+ # segments.list('list123')
20
+ def list(list_id, query: nil, body: nil, headers: nil)
21
+ path = "/lists/#{list_id}/segments"
22
+ client.get(path, query: query, body: body, headers: headers)
23
+ end
24
+
25
+ # Create a new segment
26
+ # @param list_id [String] The ID of the Mailchimp list
27
+ # @param query [Hash] Optional query parameters
28
+ # @param body [Hash] Segment attributes
29
+ # @option body [String] :name The name of the segment
30
+ # @option body [Array<Hash>] :conditions Segment conditions
31
+ # @param headers [Hash] Optional request headers
32
+ # @return [Hash] API response containing the created segment
33
+ # @example Create a static segment
34
+ # segments.create('list123', body: {
35
+ # name: 'Premium Customers',
36
+ # static_segment: ['user1@example.com', 'user2@example.com']
37
+ # })
38
+ def create(list_id, query: nil, body: nil, headers: nil)
39
+ path = "/lists/#{list_id}/segments"
40
+ client.post(path, query: query, body: body, headers: headers)
41
+ end
42
+
43
+ # Show details for a specific segment
44
+ # @param list_id [String] The ID of the Mailchimp list
45
+ # @param segment_id [String] The ID of the segment
46
+ # @param query [Hash] Optional query parameters
47
+ # @param body [Hash] Optional request body
48
+ # @param headers [Hash] Optional request headers
49
+ # @return [Hash] API response containing segment details
50
+ # @example Get details for a segment
51
+ # segments.show('list123', 'segment456')
52
+ def show(list_id, segment_id, query: nil, body: nil, headers: nil)
53
+ path = "/lists/#{list_id}/segments/#{segment_id}"
54
+ client.get(path, query: query, body: body, headers: headers)
55
+ end
56
+
57
+ # Update a segment
58
+ # @param list_id [String] The ID of the Mailchimp list
59
+ # @param segment_id [String] The ID of the segment to update
60
+ # @param query [Hash] Optional query parameters
61
+ # @param body [Hash] Updated segment attributes
62
+ # @param headers [Hash] Optional request headers
63
+ # @return [Hash] API response containing updated segment
64
+ # @example Update a segment name
65
+ # segments.update('list123', 'segment456', body: {
66
+ # name: 'Updated Segment Name'
67
+ # })
68
+ def update(list_id, segment_id, query: nil, body: nil, headers: nil)
69
+ path = "/lists/#{list_id}/segments/#{segment_id}"
70
+ client.patch(path, query: query, body: body, headers: headers)
71
+ end
72
+
73
+ # Delete a segment
74
+ # @param list_id [String] The ID of the Mailchimp list
75
+ # @param segment_id [String] The ID of the segment to delete
76
+ # @param query [Hash] Optional query parameters
77
+ # @param body [Hash] Optional request body
78
+ # @param headers [Hash] Optional request headers
79
+ # @return [Boolean] True if successful
80
+ # @example Delete a segment
81
+ # segments.delete('list123', 'segment456')
82
+ def delete(list_id, segment_id, query: nil, body: nil, headers: nil)
83
+ path = "/lists/#{list_id}/segments/#{segment_id}"
84
+ client.delete(path, query: query, body: body, headers: headers)
85
+ end
86
+
87
+ # Batch add or remove members from a static segment
88
+ # @param list_id [String] The ID of the Mailchimp list
89
+ # @param segment_id [String] The ID of the segment
90
+ # @param query [Hash] Optional query parameters
91
+ # @param body [Hash] Members to add/remove
92
+ # @option body [Array<String>] :members_to_add Array of emails to add
93
+ # @option body [Array<String>] :members_to_remove Array of emails to remove
94
+ # @param headers [Hash] Optional request headers
95
+ # @return [Hash] API response containing update status
96
+ # @example Add and remove members from a segment
97
+ # segments.batch_add_or_remove_members('list123', 'segment456', body: {
98
+ # members_to_add: ['new@example.com'],
99
+ # members_to_remove: ['old@example.com']
100
+ # })
101
+ def batch_add_or_remove_members(list_id, segment_id, query: nil, body: nil, headers: nil)
102
+ path = "/lists/#{list_id}/segments/#{segment_id}"
103
+ client.post(path, query: query, body: body, headers: headers)
104
+ end
105
+
106
+ # Iterate through all segments for a list
107
+ # @param list_id [String] The ID of the Mailchimp list
108
+ # @param query [Hash] Optional query parameters
109
+ # @param body [Hash] Optional request body
110
+ # @param headers [Hash] Optional request headers
111
+ # @yield [Hash] Each segment
112
+ # @example Iterate through segments
113
+ # segments.each('list123') do |segment|
114
+ # puts segment[:name]
115
+ # end
116
+ def each(list_id, query: nil, body: nil, headers: nil, &block)
117
+ list_each_item(:segments, list_id, query: query, body: body, headers: headers, &block)
118
+ end
119
+ end
120
+
121
+ include APIs
122
+ extend APIs
123
+ end
124
+ end
125
+ end
@@ -4,8 +4,17 @@ require "digest"
4
4
 
5
5
  module MailchimpAPI
6
6
  module Audience
7
+ # Namespace for utils that are required for Audience APIs collection
8
+ # @api private
7
9
  module Utils
10
+ # Internal class for generating MD5 hashes of email addresses
11
+ # @api private
8
12
  class SubscriberHash
13
+ # Generates an MD5 hash of a lowercase email address
14
+ # @param email [String] Email address to hash
15
+ # @return [String] MD5 hash of the lowercase email
16
+ # @example
17
+ # SubscriberHash.call("User@Example.com") # => "b58996c504c5638798eb6b511e6f49af"
9
18
  def self.call(email)
10
19
  Digest::MD5.hexdigest(email.downcase)
11
20
  end