Skip to content

Commit

Permalink
Added GetUserMediaAsync by user pk method. (#82)
Browse files Browse the repository at this point in the history
* GetTagFeedAsync»InstaMedia»InstaUserShort should be InstaUser
From log: api is proving whole fields of InstaUser

* Make InstaApi instantiable.

* get user media by pk.

* Update InstaApiBuilder.cs
  • Loading branch information
n0ise9914 authored and a-legotin committed Oct 29, 2017
1 parent c42720d commit d138c93
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion InstaSharper/API/Builder/InstaApiBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@ public static IInstaApiBuilder CreateBuilder()
return new InstaApiBuilder();
}
}
}
}
12 changes: 11 additions & 1 deletion InstaSharper/API/IInstaApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,17 @@ public interface IInstaApi
/// <see cref="InstaMediaList" />
/// </returns>
Task<IResult<InstaMediaList>> GetUserMediaAsync(string username, int maxPages = 0);


/// <summary>
/// Get all user media by user pk asynchronously
/// </summary>
/// <param name="pk">User Id</param>
/// <param name="maxPages">Maximum count of pages to retrieve</param>
/// <returns>
/// <see cref="InstaMediaList" />
/// </returns>
Task<IResult<InstaMediaList>> GetUserMediaAsync(long pk, int maxPages = 0);

/// <summary>
/// Get media by its id asynchronously
/// </summary>
Expand Down
20 changes: 13 additions & 7 deletions InstaSharper/API/InstaApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,9 @@ public async Task<IResult<InstaExploreFeed>> GetExploreFeedAsync(int maxPages =
}
}

public async Task<IResult<InstaMediaList>> GetUserMediaAsync(string username, int maxPages = 0)
public async Task<IResult<InstaMediaList>> GetUserMediaAsync(long pk, int maxPages = 0)
{
ValidateUser();
if (maxPages == 0) maxPages = int.MaxValue;
var user = await GetUserAsync(username);
if (!user.Succeeded) return Result.Fail<InstaMediaList>("Unable to get current user");
var instaUri = UriCreator.GetUserMediaListUri(user.Value.Pk);
var instaUri = UriCreator.GetUserMediaListUri(pk.ToString());
var request = HttpHelper.GetDefaultRequest(HttpMethod.Get, instaUri, _deviceInfo);
var response = await _httpRequestProcessor.SendAsync(request);
var json = await response.Content.ReadAsStringAsync();
Expand All @@ -242,7 +238,7 @@ public async Task<IResult<InstaMediaList>> GetUserMediaAsync(string username, in
var nextId = mediaResponse.NextMaxId;
while (moreAvailable && mediaList.Pages < maxPages)
{
instaUri = UriCreator.GetMediaListWithMaxIdUri(user.Value.Pk, nextId);
instaUri = UriCreator.GetMediaListWithMaxIdUri(pk.ToString(), nextId);
var nextMedia = await GetUserMediaListWithMaxIdAsync(instaUri);
mediaList.Pages++;
if (!nextMedia.Succeeded)
Expand All @@ -257,6 +253,16 @@ public async Task<IResult<InstaMediaList>> GetUserMediaAsync(string username, in
return Result.UnExpectedResponse<InstaMediaList>(response, json);
}

public async Task<IResult<InstaMediaList>> GetUserMediaAsync(string username, int maxPages = 0)
{
ValidateUser();
if (maxPages == 0) maxPages = int.MaxValue;
var user = await GetUserAsync(username);
if (!user.Succeeded) return Result.Fail<InstaMediaList>("Unable to get current user");
var medias = await GetUserMediaAsync(user.Value.Pk, maxPages);
return medias;
}

public async Task<IResult<InstaMedia>> GetMediaByIdAsync(string mediaId)
{
ValidateUser();
Expand Down

0 comments on commit d138c93

Please sign in to comment.