mailchimp-rest-api 0.3.0 → 0.4.1

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,35 +2,101 @@
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
7
10
  include Pagination::ListEachItemHelper
8
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')
9
21
  def list(list_id, interest_category_id, query: nil, body: nil, headers: nil)
10
22
  path = "/lists/#{list_id}/interest-categories/#{interest_category_id}/interests"
11
23
  client.get(path, query: query, body: body, headers: headers)
12
24
  end
13
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
+ # })
14
38
  def create(list_id, interest_category_id, query: nil, body: nil, headers: nil)
15
39
  path = "/lists/#{list_id}/interest-categories/#{interest_category_id}/interests"
16
40
  client.post(path, query: query, body: body, headers: headers)
17
41
  end
18
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')
19
53
  def show(list_id, interest_category_id, interest_id, query: nil, body: nil, headers: nil)
20
54
  path = "/lists/#{list_id}/interest-categories/#{interest_category_id}/interests/#{interest_id}"
21
55
  client.get(path, query: query, body: body, headers: headers)
22
56
  end
23
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')
24
68
  def delete(list_id, interest_category_id, interest_id, query: nil, body: nil, headers: nil)
25
69
  path = "/lists/#{list_id}/interest-categories/#{interest_category_id}/interests/#{interest_id}"
26
70
  client.delete(path, query: query, body: body, headers: headers)
27
71
  end
28
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
+ # })
29
85
  def update(list_id, interest_category_id, interest_id, query: nil, body: nil, headers: nil)
30
86
  path = "/lists/#{list_id}/interest-categories/#{interest_category_id}/interests/#{interest_id}"
31
87
  client.patch(path, query: query, body: body, headers: headers)
32
88
  end
33
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
34
100
  def each(list_id, interest_category_id, query: nil, body: nil, headers: nil, &block)
35
101
  list_each_item(:interests, list_id, interest_category_id, query: query, body: body, headers: headers, &block)
36
102
  end
@@ -2,27 +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
7
10
  include Pagination::ListEachItemHelper
11
+ include MailchimpAPI::Audience::Utils
8
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')
9
22
  def list(list_id, email, query: nil, body: nil, headers: nil)
10
23
  path = "/lists/#{list_id}/members/#{subscriber_hash(email)}/tags"
11
24
  client.get(path, query: query, body: body, headers: headers)
12
25
  end
13
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
+ # })
14
42
  def create(list_id, email, query: nil, body: nil, headers: nil)
15
43
  path = "/lists/#{list_id}/members/#{subscriber_hash(email)}/tags"
16
44
  client.post(path, query: query, body: body, headers: headers)
17
45
  end
18
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
19
58
  def each(list_id, email, query: nil, body: nil, headers: nil, &block)
20
59
  list_each_item(:tags, list_id, email, query: query, body: body, headers: headers, &block)
21
60
  end
22
61
  end
23
62
 
24
- include MailchimpAPI::Audience::Utils
25
- extend MailchimpAPI::Audience::Utils
26
63
  include APIs
27
64
  extend APIs
28
65
  end
@@ -1,53 +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
7
11
  include Pagination::ListEachItemHelper
12
+ include MailchimpAPI::Audience::Utils
8
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 })
9
26
  def list(list_id, query: nil, body: nil, headers: nil)
10
27
  path = "/lists/#{list_id}/members"
11
28
  client.get(path, query: query, body: body, headers: headers)
12
29
  end
13
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
+ # })
14
46
  def create(list_id, query: nil, body: nil, headers: nil)
15
47
  path = "/lists/#{list_id}/members"
16
48
  client.post(path, query: query, body: body, headers: headers)
17
49
  end
18
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')
19
60
  def show(list_id, email, query: nil, body: nil, headers: nil)
20
61
  path = "/lists/#{list_id}/members/#{subscriber_hash(email)}"
21
62
  client.get(path, query: query, body: body, headers: headers)
22
63
  end
23
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')
24
74
  def archive(list_id, email, query: nil, body: nil, headers: nil)
25
75
  path = "/lists/#{list_id}/members/#{subscriber_hash(email)}"
26
76
  client.delete(path, query: query, body: body, headers: headers)
27
77
  end
28
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
+ # })
29
90
  def update(list_id, email, query: nil, body: nil, headers: nil)
30
91
  path = "/lists/#{list_id}/members/#{subscriber_hash(email)}"
31
92
  client.patch(path, query: query, body: body, headers: headers)
32
93
  end
33
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
+ # })
34
107
  def add_or_update(list_id, email, query: nil, body: nil, headers: nil)
35
108
  path = "/lists/#{list_id}/members/#{subscriber_hash(email)}"
36
109
  client.put(path, query: query, body: body, headers: headers)
37
110
  end
38
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')
39
121
  def delete_permanent(list_id, email, query: nil, body: nil, headers: nil)
40
122
  path = "/lists/#{list_id}/members/#{subscriber_hash(email)}/actions/delete-permanent"
41
123
  client.post(path, query: query, body: body, headers: headers)
42
124
  end
43
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
44
136
  def each(list_id, query: nil, body: nil, headers: nil, &block)
45
137
  list_each_item(:members, list_id, query: query, body: body, headers: headers, &block)
46
138
  end
47
139
  end
48
140
 
49
- include MailchimpAPI::Audience::Utils
50
- extend MailchimpAPI::Audience::Utils
51
141
  include APIs
52
142
  extend APIs
53
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
@@ -2,35 +2,98 @@
2
2
 
3
3
  module MailchimpAPI
4
4
  module Audience
5
+ # Provides methods for interacting with Mailchimp webhooks
6
+ # Webhooks allow you to receive notifications about events in your Mailchimp account
5
7
  class Webhooks < Resource
8
+ # Module with endpoints for Webhooks APIs
6
9
  module APIs
7
10
  include Pagination::ListEachItemHelper
8
11
 
12
+ # List all webhooks 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 webhooks
18
+ # @example Get all webhooks for a list
19
+ # webhooks.list('list123')
9
20
  def list(list_id, query: nil, body: nil, headers: nil)
10
21
  path = "/lists/#{list_id}/webhooks"
11
22
  client.get(path, query: query, body: body, headers: headers)
12
23
  end
13
24
 
25
+ # Create a new webhook
26
+ # @param list_id [String] The ID of the Mailchimp list
27
+ # @param query [Hash] Optional query parameters
28
+ # @param body [Hash] Webhook attributes
29
+ # @option body [String] :url The URL for the webhook
30
+ # @option body [Hash] :events Events to subscribe to
31
+ # @param headers [Hash] Optional request headers
32
+ # @return [Hash] API response containing the created webhook
33
+ # @example Create a webhook for subscribe events
34
+ # webhooks.create('list123', body: {
35
+ # url: 'https://example.com/webhook',
36
+ # events: { subscribe: true }
37
+ # })
14
38
  def create(list_id, query: nil, body: nil, headers: nil)
15
39
  path = "/lists/#{list_id}/webhooks"
16
40
  client.post(path, query: query, body: body, headers: headers)
17
41
  end
18
42
 
43
+ # Show details for a specific webhook
44
+ # @param list_id [String] The ID of the Mailchimp list
45
+ # @param webhook_id [String] The ID of the webhook
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 webhook details
50
+ # @example Get details for a webhook
51
+ # webhooks.show('list123', 'webhook456')
19
52
  def show(list_id, webhook_id, query: nil, body: nil, headers: nil)
20
53
  path = "/lists/#{list_id}/webhooks/#{webhook_id}"
21
54
  client.get(path, query: query, body: body, headers: headers)
22
55
  end
23
56
 
57
+ # Delete a webhook
58
+ # @param list_id [String] The ID of the Mailchimp list
59
+ # @param webhook_id [String] The ID of the webhook 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 a webhook
65
+ # webhooks.delete('list123', 'webhook456')
24
66
  def delete(list_id, webhook_id, query: nil, body: nil, headers: nil)
25
67
  path = "/lists/#{list_id}/webhooks/#{webhook_id}"
26
68
  client.delete(path, query: query, body: body, headers: headers)
27
69
  end
28
70
 
71
+ # Update a webhook
72
+ # @param list_id [String] The ID of the Mailchimp list
73
+ # @param webhook_id [String] The ID of the webhook to update
74
+ # @param query [Hash] Optional query parameters
75
+ # @param body [Hash] Updated webhook attributes
76
+ # @param headers [Hash] Optional request headers
77
+ # @return [Hash] API response containing updated webhook
78
+ # @example Update webhook events
79
+ # webhooks.update('list123', 'webhook456', body: {
80
+ # events: { subscribe: true, unsubscribe: true }
81
+ # })
29
82
  def update(list_id, webhook_id, query: nil, body: nil, headers: nil)
30
83
  path = "/lists/#{list_id}/webhooks/#{webhook_id}"
31
84
  client.patch(path, query: query, body: body, headers: headers)
32
85
  end
33
86
 
87
+ # Iterate through all webhooks 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 webhook
93
+ # @example Iterate through webhooks
94
+ # webhooks.each('list123') do |webhook|
95
+ # puts webhook[:url]
96
+ # end
34
97
  def each(list_id, query: nil, body: nil, headers: nil, &block)
35
98
  list_each_item(:webhooks, list_id, query: query, body: body, headers: headers, &block)
36
99
  end