Skip to content

Commit

Permalink
feat: impl contact#update
Browse files Browse the repository at this point in the history
  • Loading branch information
drish committed Dec 28, 2023
1 parent 8bb3539 commit 5a8cb3b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
17 changes: 13 additions & 4 deletions examples/contacts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

def example

audience_id = "48c269ed-9873-4d60-bdd9-cd7e6fc0b9b8"
audience_id = "78b8d3bc-a55a-45a3-aee6-6ec0a5e13d7e"

params = {
audience_id: audience_id,
email: "steve@woz.com",
email: "steve@example.com",
first_name: "Steve",
last_name: "Woz",
unsubscribed: false,
Expand All @@ -21,8 +21,17 @@ def example
contact = Resend::Contacts.create(params)
puts "Contact created: #{contact}"

Resend::Contacts.get(audience_id, contact[:id])
puts "Retrieved contact: #{contact}"
update_params = {
audience_id: audience_id,
id: contact[:id],
unsubscribed: true,
}

retrieved = Resend::Contacts.get(audience_id, contact[:id])
puts retrieved

updated = Resend::Contacts.update(update_params)
puts "Updated contact: #{updated}"

contacts = Resend::Contacts.list(audience_id)
puts contacts
Expand Down
6 changes: 6 additions & 0 deletions lib/resend/contacts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def remove(audience_id, contact_id)
path = "audiences/#{audience_id}/contacts/#{contact_id}"
Resend::Request.new(path, {}, "delete").perform
end

# https://resend.com/docs/api-reference/contacts/update-contact
def update(params)
path = "audiences/#{params[:audience_id]}/contacts/#{params[:id]}"
Resend::Request.new(path, params, "patch").perform
end
end
end
end
27 changes: 27 additions & 0 deletions spec/contacts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,31 @@
expect(deleted[:deleted]).to be true
end
end

describe "update contact" do

before do
Resend.configure do |config|
config.api_key = "re_123"
end
end

it "should update a contact record" do
resp = {
"object": "contact",
"id": "479e3145-dd38-476b-932c-529ceb705947"
}

update_params = {
audience_id: audience_id,
id: "479e3145-dd38-476b-932c-529ceb705947",
unsubscribed: false,
}

allow_any_instance_of(Resend::Request).to receive(:perform).and_return(resp)
contact = Resend::Contacts.update(update_params)
expect(contact[:id]).to eql("479e3145-dd38-476b-932c-529ceb705947")
expect(contact[:object]).to eql("contact")
end
end
end

0 comments on commit 5a8cb3b

Please sign in to comment.