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
5 changes: 5 additions & 0 deletions src/IStreamClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public interface IStreamClient
/// </summary>
IStreamFeed Feed(string feedSlug, string userId);

/// <summary>
/// Reads enriched activities of a personalized feed.
/// </summary>
Task<PersonalizedGetResponse<EnrichedActivity>> GetPersonalizedFeedAsync(GetOptions options = null);

/// <summary>
/// Allows you to retrieve open graph information from a URL which you can then use to add images and a description to activities.
/// </summary>
Expand Down
11 changes: 10 additions & 1 deletion src/Models/GenericResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@ public class GenericGetResponse<T> : ResponseBase
/// <summary>Container for <typeparamref name="T"/> objects.</summary>
public List<T> Results { get; set; }
}
}

/// <summary>Base class for personalized read responses of <typeparamref name="T"/>.</summary>
public class PersonalizedGetResponse<T> : GenericGetResponse<T>
{
public int Limit { get; set; }
public string Next { get; set; }
public int Offset { get; set; }
public string Version { get; set; }
}
}
30 changes: 30 additions & 0 deletions src/Models/GetOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public class GetOptions
private ReactionOption _reaction = null;
private string _ranking = null;
private string _session = null;
private string _endpoint = null;
private string _feed_slug = null;
private string _user_id = null;

public GetOptions WithOffset(int offset)
{
Expand Down Expand Up @@ -56,6 +59,24 @@ public GetOptions WithSession(string session)
return this;
}

public GetOptions WithEndpoint(string endpoint)
{
_endpoint = endpoint;
return this;
}

public GetOptions WithFeedSlug(string feedSlug)
{
_feed_slug = feedSlug;
return this;
}

public GetOptions WithUserId(string userId)
{
_user_id = userId;
return this;
}

internal void Apply(RestRequest request)
{
request.AddQueryParameter("offset", _offset.ToString());
Expand All @@ -67,6 +88,15 @@ internal void Apply(RestRequest request)
if (!string.IsNullOrWhiteSpace(_session))
request.AddQueryParameter("session", _session);

if (!string.IsNullOrWhiteSpace(_endpoint))
request.AddQueryParameter("endpoint", _endpoint);

if (!string.IsNullOrWhiteSpace(_feed_slug))
request.AddQueryParameter("feed_slug", _feed_slug);

if (!string.IsNullOrWhiteSpace(_endpoint))
request.AddQueryParameter("user_id", _user_id);

_filter?.Apply(request);
_marker?.Apply(request);
_reaction?.Apply(request);
Expand Down
16 changes: 16 additions & 0 deletions src/StreamClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ public IStreamFeed Feed(string feedSlug, string userId)
return new StreamFeed(this, feedSlug, userId);
}

public async Task<PersonalizedGetResponse<EnrichedActivity>> GetPersonalizedFeedAsync(GetOptions options = null)
{
options = options ?? GetOptions.Default;
var request = this.BuildPersonalizedFeedRequest();
options.Apply(request);

var response = await this.MakeRequestAsync(request);
if (response.StatusCode == HttpStatusCode.OK)
return StreamJsonConverter.DeserializeObject<PersonalizedGetResponse<EnrichedActivity>>(response.Content);

throw StreamException.FromResponse(response);
}

public async Task<ResponseBase> ActivityPartialUpdateAsync(string id = null, ForeignIdTime foreignIdTime = null, Dictionary<string, object> set = null, IEnumerable<string> unset = null)
{
if (id == null && foreignIdTime == null)
Expand Down Expand Up @@ -175,6 +188,9 @@ internal RestRequest BuildFeedRequest(StreamFeed feed, string path, HttpMethod m
internal RestRequest BuildEnrichedFeedRequest(StreamFeed feed, string path, HttpMethod method)
=> BuildRestRequest(BaseUrlPath + feed.EnrichedPath + path, method);

internal RestRequest BuildPersonalizedFeedRequest()
=> BuildRestRequest(BaseUrlPath + "enrich/personalization/feed/", HttpMethod.Get);

internal RestRequest BuildActivitiesRequest()
=> BuildRestRequest(BaseUrlPath + ActivitiesUrlPath, HttpMethod.Post);

Expand Down
20 changes: 19 additions & 1 deletion tests/PersonalizationTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using NUnit.Framework;
using System;
using Stream.Models;
using System.Collections.Generic;
using System.Threading.Tasks;

Expand All @@ -25,5 +27,21 @@ public async Task ReadPersonalization()
Assert.True(d.ContainsKey("duration"));
Assert.True(d.ContainsKey("results"));
}

[Test]
[Ignore("Not always needed, set credentials to run when needed")]
public async Task ReadPersonalizedFeed()
{
var options = GetOptions.Default.
WithEndpoint("etoro_newsfeed").
WithFeedSlug("newsfeed").
WithRanking("etoro").
WithUserId(Guid.NewGuid().ToString());

var response = await Client.GetPersonalizedFeedAsync(options);
Assert.AreEqual(20, response.Limit);
Assert.AreEqual(0, response.Offset);
Assert.AreEqual(response.Results.Count, 0);
}
}
}
}
2 changes: 1 addition & 1 deletion tests/stream-net-tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<Name>stream-net</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup>
<PropertyGroup>
<CodeAnalysisRuleSet>../.stylecop.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
</Project>