Skip to content

Commit

Permalink
Merge pull request #5 from burkeholland/master
Browse files Browse the repository at this point in the history
Cursor
  • Loading branch information
felipepessoto committed Jun 5, 2014
2 parents cc6e00f + e6576a4 commit 93f7cae
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/InstaSharp.Tests/Relationships.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ public async Task Follows_Id()
Assert.IsTrue(result.Data.Count > 0);
}

[TestMethod, TestCategory("Relationships.Follows")]
public async Task Follows_NextCursor()
{
//This test will fail if testing with an account with less than one page of follows
var result = await relationships.Follows();
result = await relationships.Follows(null, result.Pagination.NextCursor);
Assert.IsTrue(result.Data.Count > 0);
}

[TestMethod, TestCategory("Relationships.FollowedBy")]
public async Task FollowedBy()
{
Expand All @@ -39,6 +48,15 @@ public async Task FollowedBy_Id()
Assert.IsTrue(result.Data.Count > 0);
}

[TestMethod, TestCategory("Relationships.FollowedBy")]
public async Task FollowedBy_NextCursor()
{
//This test will fail if testing with an account with less than one page of followers
var result = await relationships.FollowedBy();
result = await relationships.FollowedBy(null, result.Pagination.NextCursor);
Assert.IsTrue(result.Data.Count > 0);
}

[TestMethod, TestCategory("Relationships.RequestedBy")]
public async Task RequestedBy()
{
Expand Down
7 changes: 7 additions & 0 deletions src/InstaSharp.Tests/Users.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ public async Task Get_Id()
Assert.IsTrue(result.Data.Username == "nasagoddard", "Parameters: userId");
}

[TestMethod, TestCategory("Users.Get")]
public async Task Get_Self()
{
var result = await users.GetSelf();
Assert.IsNotNull(result);
}

[TestMethod, TestCategory("Users.Feed")]
public async Task Feed()
{
Expand Down
15 changes: 13 additions & 2 deletions src/InstaSharp/Endpoints/Relationships.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ public Relationships(InstagramConfig config, OAuthResponse auth)
/// </para>
/// </summary>
/// <param name="userId">The list of users that this user id is following.</param>
public Task<UsersResponse> Follows(int? userId = null) {
/// <param name="cursor">The next cursor id</param>
public Task<UsersResponse> Follows(int? userId = null, string cursor = null)
{
var request = base.Request("{id}/follows");
request.AddUrlSegment("id", userId.HasValue ? userId.ToString() : base.OAuthResponse.User.Id.ToString());
if (cursor != null)
{
request.AddParameter("cursor", cursor);
}
return base.Client.ExecuteAsync<UsersResponse>(request);
}

Expand All @@ -51,8 +57,13 @@ public Relationships(InstagramConfig config, OAuthResponse auth)
/// </para>
/// </summary>
/// <param name="userId">The id of the user to get the followers of.</param>
public Task<UsersResponse> FollowedBy(int? userId = null) {
/// <param name="cursor">The next cursor id</param>
public Task<UsersResponse> FollowedBy(int? userId = null, string cursor = null) {
var request = base.Request(string.Format("{0}/followed-by", userId.HasValue ? userId.ToString() : OAuthResponse.User.Id.ToString()));
if (cursor != null)
{
request.AddParameter("cursor", cursor);
}
return base.Client.ExecuteAsync<UsersResponse>(request);
}

Expand Down
7 changes: 7 additions & 0 deletions src/InstaSharp/Endpoints/Users.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ public Users(InstagramConfig config, OAuthResponse auth = null)
return Client.ExecuteAsync<UserResponse>(request);
}

public Task<UserResponse> GetSelf()
{
var request = base.Request("self");

return Client.ExecuteAsync<UserResponse>(request);
}

/// <summary>
/// See the authenticated user's feed.
/// <para>
Expand Down
2 changes: 2 additions & 0 deletions src/InstaSharp/Models/Pagination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace InstaSharp.Models {
public class Pagination {
[JsonProperty("next_url")]
public string NextUrl { get; set; }
[JsonProperty("next_cursor")]
public string NextCursor { get; set; }
[JsonProperty("next_max_id")]
public string NextMaxId { get; set; }
[JsonProperty("next_min_id")]
Expand Down
1 change: 1 addition & 0 deletions src/InstaSharp/Models/Responses/UsersResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ namespace InstaSharp.Models.Responses {
public class UsersResponse : IResponse {
public Models.Meta Meta { get; set; }
public List<Models.User> Data { get; set; }
public Pagination Pagination { get; set; }
}
}

0 comments on commit 93f7cae

Please sign in to comment.