diff --git a/SteamAccountManager.AvaloniaUI/ViewModels/SettingsViewModel.cs b/SteamAccountManager.AvaloniaUI/ViewModels/SettingsViewModel.cs
index 94a958d..c50de03 100644
--- a/SteamAccountManager.AvaloniaUI/ViewModels/SettingsViewModel.cs
+++ b/SteamAccountManager.AvaloniaUI/ViewModels/SettingsViewModel.cs
@@ -1,18 +1,32 @@
-using ReactiveUI;
-using SteamAccountManager.AvaloniaUI.ViewModels.Commands;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Input;
+using System.Windows.Input;
+using ReactiveUI;
+using SteamAccountManager.Infrastructure.Steam.Local.Storage;
namespace SteamAccountManager.AvaloniaUI.ViewModels
{
public class SettingsViewModel : RoutableViewModel
{
- public SettingsViewModel(IScreen screen) : base(screen)
+ private readonly SteamApiKeyStorage _steamApiKeyStorage;
+
+ public ICommand SaveApiKeyCommand { get; }
+ public string WebApiKey { get; set; }
+
+ public SettingsViewModel(IScreen screen, SteamApiKeyStorage apiKeyStorage) : base(screen)
+ {
+ _steamApiKeyStorage = apiKeyStorage;
+ SaveApiKeyCommand = ReactiveCommand.Create((string key) => SaveApiKey(key));
+
+ PrefillFields();
+ }
+
+ private void PrefillFields()
+ {
+ WebApiKey = _steamApiKeyStorage.Get();
+ }
+
+ private void SaveApiKey(string key)
{
+ _steamApiKeyStorage.Set(key);
}
}
-}
+}
\ No newline at end of file
diff --git a/SteamAccountManager.AvaloniaUI/Views/SettingsView.axaml b/SteamAccountManager.AvaloniaUI/Views/SettingsView.axaml
index 6279f1e..fb5fcdd 100644
--- a/SteamAccountManager.AvaloniaUI/Views/SettingsView.axaml
+++ b/SteamAccountManager.AvaloniaUI/Views/SettingsView.axaml
@@ -4,6 +4,24 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SteamAccountManager.AvaloniaUI.Views.SettingsView">
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/SteamAccountManager.Infrastructure/Steam/Local/Storage/SteamApiKeyStorage.cs b/SteamAccountManager.Infrastructure/Steam/Local/Storage/SteamApiKeyStorage.cs
index e6cadf8..a8d7ce9 100644
--- a/SteamAccountManager.Infrastructure/Steam/Local/Storage/SteamApiKeyStorage.cs
+++ b/SteamAccountManager.Infrastructure/Steam/Local/Storage/SteamApiKeyStorage.cs
@@ -1,13 +1,12 @@
-using Newtonsoft.Json;
-using SteamAccountManager.Application.Steam.Local.Logger;
-using SteamAccountManager.Infrastructure.Steam.Local.Dto;
-using System;
+using System;
using System.IO;
using System.Text;
+using Newtonsoft.Json;
+using SteamAccountManager.Application.Steam.Local.Logger;
+using SteamAccountManager.Infrastructure.Steam.Local.Dto;
namespace SteamAccountManager.Infrastructure.Steam.Local.Storage
{
-
public class SteamApiKeyStorage : IStorage
{
private const string FileName = "api_key.json";
@@ -38,7 +37,6 @@ private void Load()
_logger.LogException("File doesn't exist", e);
Save();
}
-
}
private void Save()
@@ -70,4 +68,4 @@ public void Set(string value)
Save();
}
}
-}
+}
\ No newline at end of file
diff --git a/SteamAccountManager.Infrastructure/Steam/Remote/Dao/SteamWebClient.cs b/SteamAccountManager.Infrastructure/Steam/Remote/Dao/SteamWebClient.cs
index 1fbed62..622ab11 100644
--- a/SteamAccountManager.Infrastructure/Steam/Remote/Dao/SteamWebClient.cs
+++ b/SteamAccountManager.Infrastructure/Steam/Remote/Dao/SteamWebClient.cs
@@ -1,27 +1,26 @@
-using Newtonsoft.Json;
+using System.Threading.Tasks;
+using Newtonsoft.Json;
using RestSharp;
using SteamAccountManager.Application.Steam.Local.Logger;
using SteamAccountManager.Infrastructure.Steam.Local.Storage;
-using System.Threading.Tasks;
namespace SteamAccountManager.Infrastructure.Steam.Remote.Dao
{
public class SteamWebClient : RestClient, ISteamWebClient
{
private readonly ILogger _logger;
+ private readonly SteamApiKeyStorage _steamApiKeyStorage;
public SteamWebClient(ILogger logger, SteamApiKeyStorage apiKeyStorage) : base("https://api.steampowered.com")
{
- // TODO: retrieve the key from a file (I would do it now, but I don't wanna bother with it yet)
- AddDefaultParameter(Parameter.CreateParameter(
- name: "key",
- value: apiKeyStorage.Get(),
- ParameterType.QueryString));
+ _steamApiKeyStorage = apiKeyStorage;
_logger = logger;
}
public async Task ExecuteAsync(RestRequest request) where T : new()
{
+ request.AddParameter(name: "key", value: _steamApiKeyStorage.Get());
+
var response = await ExecuteAsync(request: request);
if (response.ErrorException != null)
@@ -33,7 +32,6 @@ public async Task ExecuteAsync(RestRequest request) where T : new()
_logger.LogInformation(responseString);
- // TODO: extract the deserialization part out of this class
return JsonConvert.DeserializeObject(responseString);
}
}