get more detailled user data
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using PocketSharp.Models;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
@@ -9,6 +10,14 @@ namespace PocketSharp.Tests
|
||||
public AccountTests() : base() { }
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task IsAuthenticationSuccessful()
|
||||
{
|
||||
string requestCode = await client.GetRequestCode();
|
||||
|
||||
PocketUser user = await client.GetUser(requestCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task IsRegistrationURLSuccessfullyCreated()
|
||||
{
|
||||
|
||||
@@ -114,15 +114,32 @@ namespace PocketSharp
|
||||
}
|
||||
|
||||
// do request
|
||||
PocketUser response = await Request<PocketUser>("oauth/authorize", cancellationToken, new Dictionary<string, string>()
|
||||
GetUserResponse response = await Request<GetUserResponse>("oauth/authorize", cancellationToken, new Dictionary<string, string>()
|
||||
{
|
||||
{"code", RequestCode}
|
||||
{ "code", RequestCode },
|
||||
{ "account", "1" }
|
||||
}, false);
|
||||
|
||||
// save code to client
|
||||
AccessCode = response.Code;
|
||||
string avatar = response.Account?.Profile?.Avatar_url;
|
||||
|
||||
return response;
|
||||
PocketUser user = new PocketUser()
|
||||
{
|
||||
Username = response.Username,
|
||||
Code = response.Access_token,
|
||||
Id = response.Account?.User_id,
|
||||
Email = response.Account?.Email,
|
||||
FirstName = response.Account?.First_name,
|
||||
LastName = response.Account?.Last_name,
|
||||
Followers = response.Account?.Profile?.Follower_count ?? 0,
|
||||
Follows = response.Account?.Profile?.Follow_count ?? 0,
|
||||
Avatar = avatar != null ? new Uri(avatar, UriKind.Absolute) : null,
|
||||
IsDefaultAvatar = avatar == null || avatar.Contains("pocket-profile-images.")
|
||||
};
|
||||
|
||||
// save code to client
|
||||
AccessCode = user.Code;
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
{
|
||||
@@ -9,21 +10,53 @@ namespace PocketSharp.Models
|
||||
public class PocketUser
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the code.
|
||||
/// Pocket user id.
|
||||
/// </summary>
|
||||
public string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The access code.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The code.
|
||||
/// </value>
|
||||
[JsonProperty("access_token")]
|
||||
public string Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the username.
|
||||
/// Pocket username.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The username.
|
||||
/// </value>
|
||||
[JsonProperty("username")]
|
||||
public string Username { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Email address.
|
||||
/// </summary>
|
||||
public string Email { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// First name.
|
||||
/// </summary>
|
||||
public string FirstName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Last name.
|
||||
/// </summary>
|
||||
public string LastName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Profile avatar.
|
||||
/// </summary>
|
||||
public Uri Avatar { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Is default avatar.
|
||||
/// </summary>
|
||||
public bool IsDefaultAvatar { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Follower count.
|
||||
/// </summary>
|
||||
public int Followers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Follow count.
|
||||
/// </summary>
|
||||
public int Follows { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Response from the GetUser() method
|
||||
/// </summary>
|
||||
[JsonObject]
|
||||
internal class GetUserResponse
|
||||
{
|
||||
public string Access_token { get; set; }
|
||||
|
||||
public string Username { get; set; }
|
||||
|
||||
public GetUserAccountResponse Account { get; set; }
|
||||
}
|
||||
|
||||
|
||||
[JsonObject]
|
||||
internal class GetUserAccountResponse
|
||||
{
|
||||
public string Email { get; set; }
|
||||
|
||||
public string First_name { get; set; }
|
||||
|
||||
public string Last_name { get; set; }
|
||||
|
||||
public string User_id { get; set; }
|
||||
|
||||
//public bool Premium_on_trial { get; set; }
|
||||
|
||||
//public bool Premium_status { get; set; }
|
||||
|
||||
public GetUserAccountProfileResponse Profile { get; set; }
|
||||
}
|
||||
|
||||
|
||||
[JsonObject]
|
||||
internal class GetUserAccountProfileResponse
|
||||
{
|
||||
public string Avatar_url { get; set; }
|
||||
|
||||
public int Follow_count { get; set; }
|
||||
|
||||
public int Follower_count { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user