forked from maximadeka/convertkit-ruby
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsubscribers.rb
More file actions
59 lines (53 loc) · 1.73 KB
/
subscribers.rb
File metadata and controls
59 lines (53 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
module Convertkit
class Client
module Subscribers
def subscribers(options = {})
connection.get("subscribers", options)
end
def subscriber(subscriber_id)
connection.get("subscribers/#{subscriber_id}")
end
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]
f.params["fields"] = options[:fields] if options[:fields]
f.params["first_name"] = options[:first_name] if options[:first_name]
end
response.body
end
def unsubscribe(email)
connection.put("unsubscribe") do |f|
f.params['email'] = email
end
end
def remove_tag_from_subscriber(subscriber_id, tag_id)
connection.delete("subscribers/#{subscriber_id}/tags/#{tag_id}")
end
end
end
end