diff --git a/src/Models/GenericResponse.cs b/src/Models/GenericResponse.cs index 70cfbeb..e3e4080 100644 --- a/src/Models/GenericResponse.cs +++ b/src/Models/GenericResponse.cs @@ -1,3 +1,4 @@ +using Newtonsoft.Json; using System.Collections.Generic; namespace Stream.Models @@ -7,6 +8,10 @@ public class GenericGetResponse : ResponseBase { /// Container for objects. public List Results { get; set; } + + /// The ranking expression used for scoring activities. + [JsonProperty("ranking_expr")] + public string RankingExpression { get; set; } } /// Base class for personalized read responses of . diff --git a/src/Models/GetOptions.cs b/src/Models/GetOptions.cs index b00dae2..2f44fef 100644 --- a/src/Models/GetOptions.cs +++ b/src/Models/GetOptions.cs @@ -20,6 +20,7 @@ public class GetOptions private string _user_id = null; private string _ranking_vars = null; private bool _score_vars = false; + private bool _ranking_expr = false; private string _discard_actors = null; private string _discard_actors_sep = null; private string _moderation_template = null; @@ -68,6 +69,12 @@ public GetOptions WithScoreVars() return this; } + public GetOptions WithRankingExpr() + { + _ranking_expr = true; + return this; + } + public GetOptions WithRankingVars(IDictionary rankingVars) { _ranking_vars = StreamJsonConverter.SerializeObject(rankingVars); @@ -149,6 +156,9 @@ internal void Apply(RestRequest request) if (_score_vars) request.AddQueryParameter("withScoreVars", "true"); + if (_ranking_expr) + request.AddQueryParameter("with_ranking_expr", "true"); + if (!string.IsNullOrWhiteSpace(_discard_actors_sep)) request.AddQueryParameter("discard_actors_sep", _discard_actors_sep); diff --git a/tests/ActivityTests/GetActivityTests.cs b/tests/ActivityTests/GetActivityTests.cs index f32cf33..85f600e 100644 --- a/tests/ActivityTests/GetActivityTests.cs +++ b/tests/ActivityTests/GetActivityTests.cs @@ -172,6 +172,36 @@ public async Task TestScoreVars() Assert.IsNull(r2.Results[0].ScoreVars); } + [Test] + public async Task TestRankingExpression() + { + var feed = this.RankedFeed; + + var newActivity1 = new Activity("1", "test", "1") + { + ForeignId = "r-test-1", + Time = DateTime.Parse("2000-08-16T16:32:32"), + }; + + newActivity1.SetData("popularity", 123); + var r1 = await feed.AddActivityAsync(newActivity1); + + // Test with ranking expression flag + var r2 = await feed.GetFlatActivitiesAsync(GetOptions.Default.WithLimit(1).WithRanking("popularity").WithRankingExpr()); + Assert.IsNotNull(r2.RankingExpression); + Assert.IsNotEmpty(r2.RankingExpression); + + // Test without ranking expression flag + r2 = await feed.GetFlatActivitiesAsync(GetOptions.Default.WithLimit(1).WithRanking("popularity")); + Assert.IsNull(r2.RankingExpression); + + // Test with both score vars and ranking expression + r2 = await feed.GetFlatActivitiesAsync(GetOptions.Default.WithLimit(1).WithRanking("popularity").WithScoreVars().WithRankingExpr()); + Assert.IsNotNull(r2.RankingExpression); + Assert.IsNotEmpty(r2.RankingExpression); + Assert.IsNotNull(r2.Results[0].ScoreVars); + } + [Test] public async Task TestGetActivitiesByForeignIDAndTime() { diff --git a/tests/TestBase.cs b/tests/TestBase.cs index aca8531..876f96d 100644 --- a/tests/TestBase.cs +++ b/tests/TestBase.cs @@ -22,7 +22,7 @@ public void Setup() FlatFeed = Client.Feed("flat", System.Guid.NewGuid().ToString()); AggregateFeed = Client.Feed("aggregate", System.Guid.NewGuid().ToString()); NotificationFeed = Client.Feed("notification", System.Guid.NewGuid().ToString()); - RankedFeed = Client.Feed("ranked", System.Guid.NewGuid().ToString()); + RankedFeed = Client.Feed("user", System.Guid.NewGuid().ToString()); } } } \ No newline at end of file