Skip to content

Commit

Permalink
#1066 Tweets and users can now be retrieved by string id from the cli…
Browse files Browse the repository at this point in the history
…ents
  • Loading branch information
linvi committed Oct 5, 2020
1 parent 8b95830 commit a0c5973
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 84 deletions.
4 changes: 2 additions & 2 deletions src/Tweetinvi.Controllers/User/UsersV2Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public Task<ITwitterResult<UsersV2Response>> GetUsersAsync(IGetUsersByIdV2Parame
return _queryExecutor.GetUsersAsync(parameters, request);
}

public Task<ITwitterResult<UserV2Response>> GetUserAsync(IGetUserByUsernameV2Parameters parameters, ITwitterRequest request)
public Task<ITwitterResult<UserV2Response>> GetUserAsync(IGetUserByNameV2Parameters parameters, ITwitterRequest request)
{
return _queryExecutor.GetUserAsync(parameters, request);
}

public Task<ITwitterResult<UsersV2Response>> GetUsersAsync(IGetUsersByUsernameV2Parameters parameters, ITwitterRequest request)
public Task<ITwitterResult<UsersV2Response>> GetUsersAsync(IGetUsersByNameV2Parameters parameters, ITwitterRequest request)
{
return _queryExecutor.GetUsersAsync(parameters, request);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Tweetinvi.Controllers/User/UsersV2QueryExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public interface IUsersV2QueryExecutor
{
Task<ITwitterResult<UserV2Response>> GetUserAsync(IGetUserByIdV2Parameters parameters, ITwitterRequest request);
Task<ITwitterResult<UsersV2Response>> GetUsersAsync(IGetUsersByIdV2Parameters parameters, ITwitterRequest request);
Task<ITwitterResult<UserV2Response>> GetUserAsync(IGetUserByUsernameV2Parameters parameters, ITwitterRequest request);
Task<ITwitterResult<UsersV2Response>> GetUsersAsync(IGetUsersByUsernameV2Parameters parameters, ITwitterRequest request);
Task<ITwitterResult<UserV2Response>> GetUserAsync(IGetUserByNameV2Parameters parameters, ITwitterRequest request);
Task<ITwitterResult<UsersV2Response>> GetUsersAsync(IGetUsersByNameV2Parameters parameters, ITwitterRequest request);
}

public class UsersV2QueryExecutor : IUsersV2QueryExecutor
Expand Down Expand Up @@ -39,13 +39,13 @@ public Task<ITwitterResult<UsersV2Response>> GetUsersAsync(IGetUsersByIdV2Parame
return _twitterAccessor.ExecuteRequestAsync<UsersV2Response>(request);
}

public Task<ITwitterResult<UserV2Response>> GetUserAsync(IGetUserByUsernameV2Parameters parameters, ITwitterRequest request)
public Task<ITwitterResult<UserV2Response>> GetUserAsync(IGetUserByNameV2Parameters parameters, ITwitterRequest request)
{
request.Query.Url = _tweetQueryGenerator.GetUserQuery(parameters);
return _twitterAccessor.ExecuteRequestAsync<UserV2Response>(request);
}

public Task<ITwitterResult<UsersV2Response>> GetUsersAsync(IGetUsersByUsernameV2Parameters parameters, ITwitterRequest request)
public Task<ITwitterResult<UsersV2Response>> GetUsersAsync(IGetUsersByNameV2Parameters parameters, ITwitterRequest request)
{
request.Query.Url = _tweetQueryGenerator.GetUsersQuery(parameters);
return _twitterAccessor.ExecuteRequestAsync<UsersV2Response>(request);
Expand Down
8 changes: 4 additions & 4 deletions src/Tweetinvi.Controllers/User/UsersV2QueryGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public interface IUsersV2QueryGenerator
string GetUserQuery(IGetUserByIdV2Parameters parameters);
string GetUsersQuery(IGetUsersByIdV2Parameters parameters);

string GetUserQuery(IGetUserByUsernameV2Parameters parameters);
string GetUsersQuery(IGetUsersByUsernameV2Parameters parameters);
string GetUserQuery(IGetUserByNameV2Parameters parameters);
string GetUsersQuery(IGetUsersByNameV2Parameters parameters);
}

public class UsersV2QueryGenerator : IUsersV2QueryGenerator
Expand All @@ -35,15 +35,15 @@ public string GetUsersQuery(IGetUsersByIdV2Parameters parameters)
return query.ToString();
}

public string GetUserQuery(IGetUserByUsernameV2Parameters parameters)
public string GetUserQuery(IGetUserByNameV2Parameters parameters)
{
var query = new StringBuilder($"{Resources.UserV2_GetBy}/{parameters.By}/{parameters.Username}");
AddTweetFieldsParameters(parameters, query);
query.AddFormattedParameterToQuery(parameters.FormattedCustomQueryParameters);
return query.ToString();
}

public string GetUsersQuery(IGetUsersByUsernameV2Parameters parameters)
public string GetUsersQuery(IGetUsersByNameV2Parameters parameters)
{
var userIds = string.Join(",", parameters.Usernames);
var query = new StringBuilder($"{Resources.UserV2_GetBy}");
Expand Down
4 changes: 2 additions & 2 deletions src/Tweetinvi.Core/Core/Controllers/V2/IUsersV2Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace Tweetinvi.Core.Controllers.V2
public interface IUsersV2Controller
{
Task<ITwitterResult<UserV2Response>> GetUserAsync(IGetUserByIdV2Parameters parameters, ITwitterRequest request);
Task<ITwitterResult<UserV2Response>> GetUserAsync(IGetUserByUsernameV2Parameters parameters, ITwitterRequest request);
Task<ITwitterResult<UserV2Response>> GetUserAsync(IGetUserByNameV2Parameters parameters, ITwitterRequest request);

Task<ITwitterResult<UsersV2Response>> GetUsersAsync(IGetUsersByIdV2Parameters parameters, ITwitterRequest request);
Task<ITwitterResult<UsersV2Response>> GetUsersAsync(IGetUsersByUsernameV2Parameters parameters, ITwitterRequest request);
Task<ITwitterResult<UsersV2Response>> GetUsersAsync(IGetUsersByNameV2Parameters parameters, ITwitterRequest request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public interface ITweetsV2Client
/// <inheritdoc cref="GetTweetAsync(IGetTweetV2Parameters)"/>
Task<TweetV2Response> GetTweetAsync(long tweetId);

/// <inheritdoc cref="GetTweetAsync(IGetTweetV2Parameters)"/>
Task<TweetV2Response> GetTweetAsync(string tweetId);

/// <summary>
/// Get a tweet
/// <para>Read more : https://developer.twitter.com/en/docs/twitter-api/tweets/lookup/api-reference/get-tweets-id </para>
Expand All @@ -17,7 +20,9 @@ public interface ITweetsV2Client
Task<TweetV2Response> GetTweetAsync(IGetTweetV2Parameters parameters);

/// <inheritdoc cref="GetTweetsAsync(IGetTweetsV2Parameters)"/>
Task<TweetsV2Response> GetTweetsAsync(long[] tweetIds);
Task<TweetsV2Response> GetTweetsAsync(params long[] tweetIds);
/// <inheritdoc cref="GetTweetsAsync(IGetTweetsV2Parameters)"/>
Task<TweetsV2Response> GetTweetsAsync(params string[] tweetIds);

/// <summary>
/// Get multiple tweets
Expand Down
28 changes: 16 additions & 12 deletions src/Tweetinvi.Core/Public/Client/Clients/V2/IUsersV2Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,48 @@ namespace Tweetinvi.Client.V2
{
public interface IUsersV2Client
{
/// <inheritdoc cref="GetUserAsync(IGetUserByIdV2Parameters)"/>
Task<UserV2Response> GetUserAsync(long userId);
/// <inheritdoc cref="GetUserByIdAsync(IGetUserByIdV2Parameters)"/>
Task<UserV2Response> GetUserByIdAsync(long userId);
/// <inheritdoc cref="GetUserByIdAsync(IGetUserByIdV2Parameters)"/>
Task<UserV2Response> GetUserByIdAsync(string userId);

/// <summary>
/// Get a user from his id
/// <para>Read more : https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-id </para>
/// </summary>
/// <returns>Returns the requested user</returns>
Task<UserV2Response> GetUserAsync(IGetUserByIdV2Parameters parameters);
Task<UserV2Response> GetUserByIdAsync(IGetUserByIdV2Parameters parameters);

/// <inheritdoc cref="GetUserAsync(IGetUserByUsernameV2Parameters)"/>
Task<UserV2Response> GetUserAsync(string username);
/// <inheritdoc cref="GetUserByNameAsync(IGetUserByNameV2Parameters)"/>
Task<UserV2Response> GetUserByNameAsync(string username);

/// <summary>
/// Get a user from his screen name
/// <para>Read more : https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-by-username-username </para>
/// </summary>
/// <returns>Returns the requested user</returns>
Task<UserV2Response> GetUserAsync(IGetUserByUsernameV2Parameters parameters);
Task<UserV2Response> GetUserByNameAsync(IGetUserByNameV2Parameters parameters);

/// <inheritdoc cref="GetUsersAsync(IGetUsersByIdV2Parameters)"/>
Task<UsersV2Response> GetUsersAsync(long[] userIds);
/// <inheritdoc cref="GetUsersByIdAsync(IGetUsersByIdV2Parameters)"/>
Task<UsersV2Response> GetUsersByIdAsync(params long[] userIds);
/// <inheritdoc cref="GetUsersByIdAsync(IGetUsersByIdV2Parameters)"/>
Task<UsersV2Response> GetUsersByIdAsync(params string[] userIds);

/// <summary>
/// Get users from their ids
/// <para>Read more : https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users </para>
/// </summary>
/// <returns>Returns the requested users</returns>
Task<UsersV2Response> GetUsersAsync(IGetUsersByIdV2Parameters parameters);
Task<UsersV2Response> GetUsersByIdAsync(IGetUsersByIdV2Parameters parameters);

/// <inheritdoc cref="GetUsersAsync(IGetUsersByUsernameV2Parameters)"/>
Task<UsersV2Response> GetUsersAsync(string[] usernames);
/// <inheritdoc cref="GetUsersByNameAsync(IGetUsersByNameV2Parameters)"/>
Task<UsersV2Response> GetUsersByNameAsync(params string[] usernames);

/// <summary>
/// Get users from their screen names
/// <para>Read more : https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-by </para>
/// </summary>
/// <returns>Returns the requested users</returns>
Task<UsersV2Response> GetUsersAsync(IGetUsersByUsernameV2Parameters parameters);
Task<UsersV2Response> GetUsersByNameAsync(IGetUsersByNameV2Parameters parameters);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace Tweetinvi.Client.Requesters.V2
public interface IUsersV2Requester
{
Task<ITwitterResult<UserV2Response>> GetUserAsync(IGetUserByIdV2Parameters parameters);
Task<ITwitterResult<UserV2Response>> GetUserAsync(IGetUserByUsernameV2Parameters parameters);
Task<ITwitterResult<UserV2Response>> GetUserAsync(IGetUserByNameV2Parameters parameters);

Task<ITwitterResult<UsersV2Response>> GetUsersAsync(IGetUsersByIdV2Parameters parameters);
Task<ITwitterResult<UsersV2Response>> GetUsersAsync(IGetUsersByUsernameV2Parameters parameters);
Task<ITwitterResult<UsersV2Response>> GetUsersAsync(IGetUsersByNameV2Parameters parameters);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Tweetinvi.Core.Parameters;

namespace Tweetinvi.Parameters.V2
{
public interface IGetUserByNameV2Parameters : IBaseUsersV2GetByParameters
{
string Username { get; set; }
}

public class GetUserByNameV2Parameters : BaseUsersV2GetByParameters, IGetUserByNameV2Parameters
{
public GetUserByNameV2Parameters(string username) : base("username")
{
Username = username;
this.WithAllFields();
}

public string Username { get; set; }
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
using System.Linq;
using Tweetinvi.Core.Parameters;

namespace Tweetinvi.Parameters.V2
{
public interface IGetUsersByIdV2Parameters : IBaseUsersV2Parameters
{
long[] UserIds { get; set; }
string[] UserIds { get; set; }
}

public class GetUsersByIdV2Parameters : BaseUsersV2Parameters, IGetUsersByIdV2Parameters
{
public GetUsersByIdV2Parameters(params long[] userIds)
{
UserIds = userIds.Select(x => x.ToString()).ToArray();
this.WithAllFields();
}

public GetUsersByIdV2Parameters(params string[] userIds)
{
UserIds = userIds;
this.WithAllFields();
; }
;
}

public long[] UserIds { get; set; }
public string[] UserIds { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Tweetinvi.Core.Parameters;

namespace Tweetinvi.Parameters.V2
{
public interface IGetUsersByNameV2Parameters : IBaseUsersV2GetByParameters
{
string[] Usernames { get; set; }
}

public class GetUsersByNameV2Parameters : BaseUsersV2GetByParameters, IGetUsersByNameV2Parameters
{
public GetUsersByNameV2Parameters(params string[] usernames) : base("username")
{
Usernames = usernames;
this.WithAllFields();
}

public string[] Usernames { get; set; }
}
}

This file was deleted.

10 changes: 10 additions & 0 deletions src/Tweetinvi/Client/Clients/V2/TweetsV2Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public Task<TweetV2Response> GetTweetAsync(long tweetId)
return GetTweetAsync(new GetTweetV2Parameters(tweetId));
}

public Task<TweetV2Response> GetTweetAsync(string tweetId)
{
return GetTweetAsync(new GetTweetV2Parameters(tweetId));
}

public async Task<TweetV2Response> GetTweetAsync(IGetTweetV2Parameters parameters)
{
var twitterResponse = await _tweetsV2Requester.GetTweetAsync(parameters).ConfigureAwait(false);
Expand All @@ -30,6 +35,11 @@ public Task<TweetsV2Response> GetTweetsAsync(long[] tweetIds)
return GetTweetsAsync(new GetTweetsV2Parameters(tweetIds));
}

public Task<TweetsV2Response> GetTweetsAsync(string[] tweetIds)
{
return GetTweetsAsync(new GetTweetsV2Parameters(tweetIds));
}

public async Task<TweetsV2Response> GetTweetsAsync(IGetTweetsV2Parameters parameters)
{
var twitterResponse = await _tweetsV2Requester.GetTweetsAsync(parameters).ConfigureAwait(false);
Expand Down
34 changes: 22 additions & 12 deletions src/Tweetinvi/Client/Clients/V2/UsersV2Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,55 @@ public UsersV2Client(IUsersV2Requester usersV2Requester)
_usersV2Requester = usersV2Requester;
}

Task<UserV2Response> IUsersV2Client.GetUserAsync(long userId)
public Task<UserV2Response> GetUserByIdAsync(long userId)
{
return GetUserAsync(new GetUserByIdV2Parameters(userId));
return GetUserByIdAsync(new GetUserByIdV2Parameters(userId));
}

public Task<UserV2Response> GetUserAsync(string username)
public Task<UserV2Response> GetUserByIdAsync(string userId)
{
return GetUserAsync(new GetUserByUsernameV2Parameters(username));
return GetUserByIdAsync(new GetUserByIdV2Parameters(userId));
}

public async Task<UserV2Response> GetUserAsync(IGetUserByIdV2Parameters parameters)
public Task<UserV2Response> GetUserByNameAsync(string username)
{
return GetUserByNameAsync(new GetUserByNameV2Parameters(username));
}

public async Task<UserV2Response> GetUserByIdAsync(IGetUserByIdV2Parameters parameters)
{
var twitterResponse = await _usersV2Requester.GetUserAsync(parameters).ConfigureAwait(false);
return twitterResponse?.Model;
}

public async Task<UserV2Response> GetUserAsync(IGetUserByUsernameV2Parameters parameters)
public async Task<UserV2Response> GetUserByNameAsync(IGetUserByNameV2Parameters parameters)
{
var twitterResponse = await _usersV2Requester.GetUserAsync(parameters).ConfigureAwait(false);
return twitterResponse?.Model;
}

public Task<UsersV2Response> GetUsersAsync(long[] userIds)
public Task<UsersV2Response> GetUsersByIdAsync(long[] userIds)
{
return GetUsersByIdAsync(new GetUsersByIdV2Parameters(userIds));
}

public Task<UsersV2Response> GetUsersByIdAsync(string[] userIds)
{
return GetUsersAsync(new GetUsersByIdV2Parameters(userIds));
return GetUsersByIdAsync(new GetUsersByIdV2Parameters(userIds));
}

public Task<UsersV2Response> GetUsersAsync(string[] usernames)
public Task<UsersV2Response> GetUsersByNameAsync(string[] usernames)
{
return GetUsersAsync(new GetUsersByUsernameV2Parameters(usernames));
return GetUsersByNameAsync(new GetUsersByNameV2Parameters(usernames));
}

public async Task<UsersV2Response> GetUsersAsync(IGetUsersByIdV2Parameters parameters)
public async Task<UsersV2Response> GetUsersByIdAsync(IGetUsersByIdV2Parameters parameters)
{
var twitterResponse = await _usersV2Requester.GetUsersAsync(parameters).ConfigureAwait(false);
return twitterResponse?.Model;
}

public async Task<UsersV2Response> GetUsersAsync(IGetUsersByUsernameV2Parameters parameters)
public async Task<UsersV2Response> GetUsersByNameAsync(IGetUsersByNameV2Parameters parameters)
{
var twitterResponse = await _usersV2Requester.GetUsersAsync(parameters).ConfigureAwait(false);
return twitterResponse?.Model;
Expand Down
Loading

0 comments on commit a0c5973

Please sign in to comment.