Skip to content

Commit 921981f

Browse files
authored
feat: add follow stats endpoint (#138)
1 parent 4fad3e4 commit 921981f

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ Gemfile.lock
99
.ruby-version
1010
.ruby-gemset
1111
.idea
12+
.vscode
1213
*.DS_Store
1314
.envrc

lib/stream/feed.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,19 @@ def unfollow(target_feed_slug, target_user_id, keep_history: false)
158158
@client.make_request(:delete, uri, auth_token, params)
159159
end
160160

161+
def follow_stats(followers_slugs = nil, following_slugs = nil)
162+
uri = '/stats/follow'
163+
params = {
164+
followers: @id,
165+
following: @id
166+
}
167+
params[:followers_slugs] = followers_slugs.join(',') if followers_slugs
168+
params[:following_slugs] = following_slugs.join(',') if following_slugs
169+
auth_token = create_jwt_token('*', 'read', '*')
170+
171+
@client.make_request(:get, uri, auth_token, params)
172+
end
173+
161174
private
162175

163176
def create_jwt_token(resource, action, feed_id = nil, user_id = nil)

spec/integration_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,16 @@
288288
expect(follower.get['results'][0]['id']).to eq response['id']
289289
end
290290

291+
example 'get followers statistics' do
292+
f = @client.feed('flat', generate_uniq_feed_name)
293+
f.follow('flat', generate_uniq_feed_name)
294+
f.follow('flat', generate_uniq_feed_name)
295+
f.follow('flat', generate_uniq_feed_name)
296+
stats = f.follow_stats
297+
expect(stats['results']['following']['count']).to eq 3
298+
expect(stats['results']['followers']['count']).to eq 0
299+
end
300+
291301
example 'posting activity using to' do
292302
recipient = 'flat', 'toruby11'
293303
activity = {

0 commit comments

Comments
 (0)