diff --git a/Gemfile.lock b/Gemfile.lock index 7427755..8394429 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - resend (1.22.0) + resend (1.23.0) base64 httparty (>= 0.22.0) diff --git a/examples/events.rb b/examples/events.rb index d223805..0064229 100644 --- a/examples/events.rb +++ b/examples/events.rb @@ -64,11 +64,18 @@ }) puts "sent event with email: #{sent_with_email[:event]}" -# 9. List events +# 9. Send event with an idempotency key +sent_idempotent = Resend::Events.send( + { event: "user.signed_up", email: "test.events@example.com" }, + options: { idempotency_key: "user.signed_up:test.events@example.com" } +) +puts "sent event with idempotency key: #{sent_idempotent[:event]}" + +# 10. List events events = Resend::Events.list puts "total events: #{events[:data].length}, has_more: #{events[:has_more]}" -# 10. List events with pagination params +# 11. List events with pagination params paginated = Resend::Events.list({ limit: 5 }) puts "paginated events (limit 5): #{paginated[:data].length}" @@ -78,14 +85,14 @@ puts "next page: #{more_events[:data].length}" end -# 11. Delete event by ID +# 12. Delete event by ID deleted_by_id = Resend::Events.remove(event_id) puts "deleted event by ID: #{deleted_by_id[:id]}, deleted: #{deleted_by_id[:deleted]}" -# 12. Delete event by name +# 13. Delete event by name deleted_by_name = Resend::Events.remove("user.signed_up") puts "deleted event by name: #{deleted_by_name[:deleted]}" -# 13. Cleanup: delete contact +# 14. Cleanup: delete contact Resend::Contacts.remove({ id: contact_id }) puts "removed contact: #{contact_id}" diff --git a/lib/resend/events.rb b/lib/resend/events.rb index 53d3056..ffce782 100644 --- a/lib/resend/events.rb +++ b/lib/resend/events.rb @@ -32,8 +32,12 @@ def remove(identifier = "") end # https://resend.com/docs/api-reference/events/send-event - def send(params = {}) - Resend::Request.new("events/send", params, "post").perform + # + # @param params [Hash] the event to send + # @param options [Hash] additional options for the request + # @option options [String] :idempotency_key Optional idempotency key + def send(params = {}, options: {}) + Resend::Request.new("events/send", params, "post", options: options).perform end # https://resend.com/docs/api-reference/events/list-events diff --git a/lib/resend/version.rb b/lib/resend/version.rb index 1924332..66a232e 100644 --- a/lib/resend/version.rb +++ b/lib/resend/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Resend - VERSION = "1.22.0" + VERSION = "1.23.0" end diff --git a/spec/events_spec.rb b/spec/events_spec.rb index 16308a0..fb00d9f 100644 --- a/spec/events_spec.rb +++ b/spec/events_spec.rb @@ -213,6 +213,22 @@ end Resend::Events.send(params) end + + it "sends the Idempotency-Key header" do + resp = { object: "event", event: event_name } + allow(resp).to receive(:body).and_return(resp) + allow(HTTParty).to receive(:send).and_return(resp) + + Resend::Events.send({ event: event_name, email: "user@example.com" }, options: { idempotency_key: "evt-1" }) + + expect(HTTParty).to have_received(:send).with( + :post, + "#{Resend::Request::BASE_URL}events/send", + hash_including( + headers: hash_including("Idempotency-Key" => "evt-1") + ) + ) + end end describe "list" do