File tree 3 files changed +23
-3
lines changed
3 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -23,8 +23,10 @@ def example
23
23
24
24
update_params = {
25
25
audience_id : audience_id ,
26
- id : contact [ :id ] ,
27
- unsubscribed : true ,
26
+ email : params [ :email ] ,
27
+ # id: contact[:id],
28
+ unsubscribed : false ,
29
+ first_name : "Updated" ,
28
30
}
29
31
30
32
retrieved = Resend ::Contacts . get ( audience_id , contact [ :id ] )
Original file line number Diff line number Diff line change @@ -19,6 +19,10 @@ def get(audience_id, id)
19
19
Resend ::Request . new ( path , { } , "get" ) . perform
20
20
end
21
21
22
+ #
23
+ # List contacts in an audience
24
+ #
25
+ # @param audience_id [String] the audience id
22
26
# https://resend.com/docs/api-reference/contacts/list-contacts
23
27
def list ( audience_id )
24
28
path = "audiences/#{ audience_id } /contacts"
@@ -37,9 +41,15 @@ def remove(audience_id, contact_id)
37
41
Resend ::Request . new ( path , { } , "delete" ) . perform
38
42
end
39
43
44
+ #
45
+ # Update a contact
46
+ #
47
+ # @param params [Hash] the contact params
40
48
# https://resend.com/docs/api-reference/contacts/update-contact
41
49
def update ( params )
42
- path = "audiences/#{ params [ :audience_id ] } /contacts/#{ params [ :id ] } "
50
+ raise ArgumentError , "id or email is required" if params [ :id ] . nil? && params [ :email ] . nil?
51
+
52
+ path = "audiences/#{ params [ :audience_id ] } /contacts/#{ params [ :id ] || params [ :email ] } "
43
53
Resend ::Request . new ( path , params , "patch" ) . perform
44
54
end
45
55
end
Original file line number Diff line number Diff line change 136
136
expect ( contact [ :id ] ) . to eql ( "479e3145-dd38-476b-932c-529ceb705947" )
137
137
expect ( contact [ :object ] ) . to eql ( "contact" )
138
138
end
139
+
140
+ it "raise when required fields are not provided" do
141
+ begin
142
+ Resend ::Contacts . update ( { audience_id : "123" } )
143
+ rescue ArgumentError => e
144
+ expect ( e . message ) . to eql ( "id or email is required" )
145
+ end
146
+ end
139
147
end
140
148
end
You can’t perform that action at this time.
0 commit comments