Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Models/Activity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class Activity : ActivityBase
public string Object { get; set; }
public string Target { get; set; }
public string Origin { get; set; }
public Dictionary<string, object> ScoreVars { get; set; }

public Activity(string actor, string verb, string @object)
{
Expand Down
21 changes: 21 additions & 0 deletions src/Models/GetOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Stream.Rest;
using Stream.Utils;
using System.Collections.Generic;

namespace Stream.Models
Expand All @@ -17,6 +18,8 @@ public class GetOptions
private string _endpoint = null;
private string _feed_slug = null;
private string _user_id = null;
private string _ranking_vars = null;
private bool _score_vars = false;

private IDictionary<string, string> _custom = null;

Expand Down Expand Up @@ -56,6 +59,18 @@ public GetOptions WithRanking(string rankingSlug)
return this;
}

public GetOptions WithScoreVars()
{
_score_vars = true;
return this;
}

public GetOptions WithRankingVars(IDictionary<string, object> rankingVars)
{
_ranking_vars = StreamJsonConverter.SerializeObject(rankingVars);
return this;
}

public GetOptions WithSession(string session)
{
_session = session;
Expand Down Expand Up @@ -111,6 +126,12 @@ internal void Apply(RestRequest request)
if (!string.IsNullOrWhiteSpace(_user_id))
request.AddQueryParameter("user_id", _user_id);

if (!string.IsNullOrWhiteSpace(_ranking_vars))
request.AddQueryParameter("ranking_vars", _ranking_vars);

if (_score_vars)
request.AddQueryParameter("withScoreVars", "true");

if (_custom != null)
{
foreach (KeyValuePair<string, string> kvp in _custom)
Expand Down
3 changes: 2 additions & 1 deletion src/StreamFeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ internal StreamFeed(StreamClient client, string feedSlug, string userId)
public async Task<Activity> AddActivityAsync(Activity activity)
{
var request = _client.BuildFeedRequest(this, "/", HttpMethod.Post);
request.SetJsonBody(StreamJsonConverter.SerializeObject(activity));
var body = StreamJsonConverter.SerializeObject(activity);
request.SetJsonBody(body);

var response = await _client.MakeRequestAsync(request);

Expand Down
52 changes: 52 additions & 0 deletions tests/ActivityTests/GetActivityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,58 @@ public async Task TestGetActivitiesByID()
});
}

[Test]
[Ignore("Test database has no ranked method at the moment")]
public async Task TestRankingVars()
{
var newActivity1 = new Activity("1", "test", "1")
{
ForeignId = "r-test-1",
Time = DateTime.Parse("2000-08-16T16:32:32"),
};

newActivity1.SetData("popularity", 123);

var response = await this.UserFeed.AddActivityAsync(newActivity1);

var newActivity2 = new Activity("1", "test", "2")
{
ForeignId = "r-test-2",
Time = DateTime.Parse("2000-08-17T16:32:32"),
};

response = await this.UserFeed.AddActivityAsync(newActivity2);

var ranking_vars = new Dictionary<string, object> { { "popularity", 666 } };
var r2 = await this.UserFeed.GetFlatActivitiesAsync(GetOptions.Default.WithLimit(2).WithRanking("popular").WithRankingVars(ranking_vars));
Assert.NotNull(r2);
Assert.AreEqual(2, r2.Results.Count);
Assert.AreEqual(r2.Results[0].Score, 11.090528);
Assert.AreEqual(r2.Results[1].Score, 0.99999917);
}

[Test]
[Ignore("Test database has no ranked method at the moment")]
public async Task TestScoreVars()
{
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);

var r2 = await feed.GetFlatActivitiesAsync(GetOptions.Default.WithLimit(1).WithRanking("popularity").WithScoreVars());
Assert.IsNotNull(r2.Results[0].ScoreVars);

r2 = await feed.GetFlatActivitiesAsync(GetOptions.Default.WithLimit(1).WithRanking("popularity"));
Assert.IsNull(r2.Results[0].ScoreVars);
}

[Test]
public async Task TestGetActivitiesByForeignIDAndTime()
{
Expand Down
2 changes: 2 additions & 0 deletions tests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public abstract class TestBase
protected IStreamClient Client { get; private set; }
protected IStreamFeed UserFeed { get; private set; }
protected IStreamFeed UserFeed2 { get; private set; }
protected IStreamFeed RankedFeed { get; private set; }
protected IStreamFeed FlatFeed { get; private set; }
protected IStreamFeed AggregateFeed { get; private set; }
protected IStreamFeed NotificationFeed { get; private set; }
Expand All @@ -21,6 +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());
}
}
}