diff --git a/PocketSharp.Tests/AccountTests.cs b/PocketSharp.Tests/AccountTests.cs index 03e2a07..918776f 100644 --- a/PocketSharp.Tests/AccountTests.cs +++ b/PocketSharp.Tests/AccountTests.cs @@ -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() { diff --git a/PocketSharp/Components/Account.cs b/PocketSharp/Components/Account.cs index 60e0c14..ea761b5 100644 --- a/PocketSharp/Components/Account.cs +++ b/PocketSharp/Components/Account.cs @@ -114,15 +114,32 @@ namespace PocketSharp } // do request - PocketUser response = await Request("oauth/authorize", cancellationToken, new Dictionary() + GetUserResponse response = await Request("oauth/authorize", cancellationToken, new Dictionary() { - {"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; } diff --git a/PocketSharp/Models/PocketUser.cs b/PocketSharp/Models/PocketUser.cs index fb7c585..577a062 100644 --- a/PocketSharp/Models/PocketUser.cs +++ b/PocketSharp/Models/PocketUser.cs @@ -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 { /// - /// Gets or sets the code. + /// Pocket user id. + /// + public string Id { get; set; } + + /// + /// The access code. /// - /// - /// The code. - /// - [JsonProperty("access_token")] public string Code { get; set; } /// - /// Gets or sets the username. + /// Pocket username. /// - /// - /// The username. - /// - [JsonProperty("username")] public string Username { get; set; } + + /// + /// Email address. + /// + public string Email { get; set; } + + /// + /// First name. + /// + public string FirstName { get; set; } + + /// + /// Last name. + /// + public string LastName { get; set; } + + /// + /// Profile avatar. + /// + public Uri Avatar { get; set; } + + /// + /// Is default avatar. + /// + public bool IsDefaultAvatar { get; set; } = true; + + /// + /// Follower count. + /// + public int Followers { get; set; } + + /// + /// Follow count. + /// + public int Follows { get; set; } } } diff --git a/PocketSharp/Models/Response/GetUser.cs b/PocketSharp/Models/Response/GetUser.cs new file mode 100644 index 0000000..5c2629b --- /dev/null +++ b/PocketSharp/Models/Response/GetUser.cs @@ -0,0 +1,47 @@ +using Newtonsoft.Json; + +namespace PocketSharp.Models +{ + /// + /// Response from the GetUser() method + /// + [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; } + } +}