Skip to content

Commit

Permalink
feat: add follow stats endpoint (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdeme authored Feb 8, 2022
1 parent 4fad3e4 commit 921981f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ Gemfile.lock
.ruby-version
.ruby-gemset
.idea
.vscode
*.DS_Store
.envrc
13 changes: 13 additions & 0 deletions lib/stream/feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,19 @@ def unfollow(target_feed_slug, target_user_id, keep_history: false)
@client.make_request(:delete, uri, auth_token, params)
end

def follow_stats(followers_slugs = nil, following_slugs = nil)
uri = '/stats/follow'
params = {
followers: @id,
following: @id
}
params[:followers_slugs] = followers_slugs.join(',') if followers_slugs
params[:following_slugs] = following_slugs.join(',') if following_slugs
auth_token = create_jwt_token('*', 'read', '*')

@client.make_request(:get, uri, auth_token, params)
end

private

def create_jwt_token(resource, action, feed_id = nil, user_id = nil)
Expand Down
10 changes: 10 additions & 0 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,16 @@
expect(follower.get['results'][0]['id']).to eq response['id']
end

example 'get followers statistics' do
f = @client.feed('flat', generate_uniq_feed_name)
f.follow('flat', generate_uniq_feed_name)
f.follow('flat', generate_uniq_feed_name)
f.follow('flat', generate_uniq_feed_name)
stats = f.follow_stats
expect(stats['results']['following']['count']).to eq 3
expect(stats['results']['followers']['count']).to eq 0
end

example 'posting activity using to' do
recipient = 'flat', 'toruby11'
activity = {
Expand Down

0 comments on commit 921981f

Please sign in to comment.