Skip to content

Commit

Permalink
Added LoginData class for better handling of data returned from the l…
Browse files Browse the repository at this point in the history
…ogin.
  • Loading branch information
nicktheone committed Jun 17, 2021
1 parent 7a56596 commit f4de3ec
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
13 changes: 9 additions & 4 deletions DuolingoNET/Duolingo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public class Duolingo
#region Properties

/// <summary>
/// A string representing the username or email of the account.
/// A string representing the username or email of the account used for login.
/// </summary>
public string LoginUsername { get; set; }

/// <summary>
/// A string representing the password of the account.
/// A string representing the password of the account used for login.
/// </summary>
public string LoginPassword { get; set; }

Expand All @@ -52,6 +52,11 @@ public class Duolingo
/// </summary>
public HttpClient Client { get; set; }

/// <summary>
/// The <see cref="DuolingoNET.LoginData"/> containing the login data of the user.
/// </summary>
public LoginData LoginData { get; set; }

/// <summary>
/// The <see cref="DuolingoNET.User"/> containing the data of the user.
/// </summary>
Expand Down Expand Up @@ -155,7 +160,7 @@ public async Task GetVocabularyAsync()
public async Task GetUserDataAsync()
{
// Gets the user data using the username extracted from the login data
var getUserDataResult = await Client.GetAsync(string.Format("/users/{0}", User.Username));
var getUserDataResult = await Client.GetAsync(string.Format("/users/{0}", LoginData.Username));
getUserDataResult.EnsureSuccessStatusCode();
var json = await getUserDataResult.Content.ReadAsStringAsync();

Expand Down Expand Up @@ -203,7 +208,7 @@ private async Task LoginAsync()
loginResult.EnsureSuccessStatusCode();

// Reads the username on the website
User = JsonConvert.DeserializeObject<User>(await loginResult.Content.ReadAsStringAsync());
LoginData = JsonConvert.DeserializeObject<LoginData>(await loginResult.Content.ReadAsStringAsync());
}

/// <summary>
Expand Down
35 changes: 35 additions & 0 deletions DuolingoNET/LoginData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace DuolingoNET
{
/// <summary>
/// The login class.
/// Contains the login data returned from the website for the logged in user.
/// </summary>
/// <list type="bullet">
/// <item>
/// <term></term>
/// <description></description>
/// </list>
/// </summary>
/// <remarks>
/// <para></para>
/// </remarks>
public class LoginData
{
/// <summary>
/// A string representing the username of the account.
/// </summary>
[JsonProperty("username")]
public string Username { get; set; }

/// <summary>
/// A string representing the Id of the account.
/// </summary>
[JsonProperty("user_id")]
public string UserId { get; set; }
}
}

0 comments on commit f4de3ec

Please sign in to comment.