Skip to content

Commit 557021b

Browse files
committed
Add Intercom::User.count method to fetch total number of users
1 parent 6f817b8 commit 557021b

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/intercom/user.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ def self.create(params)
6868

6969
# Retrieve all the users
7070
# Examples:
71-
# Intercom::User.all.count
72-
# > 5346
7371
# Intercom::User.all.each do |user|
7472
# puts user.inspect
7573
# end
@@ -82,6 +80,14 @@ def self.all
8280
UserCollectionProxy.new
8381
end
8482

83+
# Fetches a count of all Users tracked on Intercom.
84+
#
85+
# @return [Integer]
86+
def self.count
87+
response = Intercom.get("/v1/users", {:per_page => 1})
88+
response["total_count"]
89+
end
90+
8591
# Deletes a user record on your application.
8692
#
8793
# Calls DELETE https://api.intercom.io/v1/users

spec/unit/intercom/user_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@
185185
all.must_be_instance_of(Intercom::UserCollectionProxy)
186186
end
187187

188+
it "returns the total number of users" do
189+
Intercom.expects(:get).with("/v1/users", {:per_page => 1}).returns(page_of_users)
190+
Intercom::User.count.must_be_kind_of(Integer)
191+
end
192+
188193
it "can find_by_email" do
189194
Intercom::User.expects(:find).with(:email => "bob@example.com")
190195
Intercom::User.find_by_email("bob@example.com")

0 commit comments

Comments
 (0)