diff --git a/lib/convertkit/client/subscribers.rb b/lib/convertkit/client/subscribers.rb index 92ecd86..1cfd338 100644 --- a/lib/convertkit/client/subscribers.rb +++ b/lib/convertkit/client/subscribers.rb @@ -13,6 +13,29 @@ def subscriber_tags(subscriber_id) connection.get("subscribers/#{subscriber_id}/tags") end + # returns an hash with the following keys: + # { + # "subscriber": { + # "id": 3436990966, + # "stats": { + # "sent": 2, + # "opened": 2, + # "clicked": 2, + # "bounced": 0, + # "open_rate": 1, + # "click_rate": 1, + # "last_sent": "2025-06-25 16:44:37.000", + # "last_opened": "2025-06-25 16:45:36.000", + # "last_clicked": "2025-06-25 16:45:42.000", + # "sent_since_last_open": 0, + # "sent_since_last_click": 0 + # } + # } + # } + def subscriber_stats(subscriber_id) + connection.get("subscribers/#{subscriber_id}/stats") + end + def update_subscriber(subscriber_id, options = {}) response = connection.put("subscribers/#{subscriber_id}") do |f| f.params["email_address"] = options[:email_address] if options[:email_address] diff --git a/spec/convertkit/client/subscribers_spec.rb b/spec/convertkit/client/subscribers_spec.rb index 5657cea..aad43ea 100644 --- a/spec/convertkit/client/subscribers_spec.rb +++ b/spec/convertkit/client/subscribers_spec.rb @@ -31,6 +31,14 @@ class Client end end + describe "#subscriber_stats" do + it "sends the right request" do + subscriber_id = ENV['SUBSCRIBER_ID'] + r = @client.subscriber_stats(subscriber_id) + expect(r.success?).to be_truthy + end + end + describe "#update_subscriber" do it "updates a subscriber" do old_email = "old-email-#{Time.now.to_i}@example.com"