Added config for spotify local api

This commit is contained in:
Jonas Dellinger 2017-09-03 14:44:11 +02:00
parent 06adc23abb
commit 451d925d7d
5 changed files with 29 additions and 5 deletions

View File

@ -13,7 +13,12 @@ namespace SpotifyAPI.Local
public string OauthKey { get; private set; } public string OauthKey { get; private set; }
public string CfidKey { get; private set; } public string CfidKey { get; private set; }
public const string Host = "127.0.0.1"; //Localhost since domain fails to resolve on some hosts private SpotifyLocalAPIConfig _config;
public RemoteHandler(SpotifyLocalAPIConfig config)
{
_config = config;
}
internal Boolean Init() internal Boolean Init()
{ {
@ -103,7 +108,7 @@ namespace SpotifyAPI.Local
parameters += "&returnon=login%2Clogout%2Cplay%2Cpause%2Cerror%2Cap"; parameters += "&returnon=login%2Clogout%2Cplay%2Cpause%2Cerror%2Cap";
} }
string address = "https://" + Host + ":4371/" + request + parameters; string address = $"{_config.HostUrl}:{_config.Port}/{request}{parameters}";
string response = ""; string response = "";
try try
{ {
@ -144,7 +149,7 @@ namespace SpotifyAPI.Local
parameters += "&returnon=login%2Clogout%2Cplay%2Cpause%2Cerror%2Cap"; parameters += "&returnon=login%2Clogout%2Cplay%2Cpause%2Cerror%2Cap";
} }
string address = "https://" + Host + ":4371/" + request + parameters; string address = $"{_config.HostUrl}:{_config.Port}/{request}{parameters}";
string response = ""; string response = "";
try try
{ {

View File

@ -65,10 +65,16 @@ namespace SpotifyAPI.Local
public SpotifyLocalAPI(int timerIntervall = 50) public SpotifyLocalAPI(int timerIntervall = 50)
{ {
_rh = new RemoteHandler(); _rh = new RemoteHandler(new SpotifyLocalAPIConfig());
AttachTimer(timerIntervall); AttachTimer(timerIntervall);
} }
public SpotifyLocalAPI(SpotifyLocalAPIConfig config)
{
_rh = new RemoteHandler(config);
AttachTimer(config.TimerInterval);
}
private void AttachTimer(int intervall) private void AttachTimer(int intervall)
{ {
_eventTimer = new Timer _eventTimer = new Timer

View File

@ -0,0 +1,12 @@
namespace SpotifyAPI.Local
{
// ReSharper disable once InconsistentNaming
public class SpotifyLocalAPIConfig
{
public int TimerInterval { get; set; } = 50;
public string HostUrl { get; set; } = "https://127.0.0.1";
public int Port { get; set; } = 4371;
}
}

View File

@ -59,6 +59,7 @@
<SubType>Component</SubType> <SubType>Component</SubType>
</Compile> </Compile>
<Compile Include="Local\Models\SpotifyUri.cs" /> <Compile Include="Local\Models\SpotifyUri.cs" />
<Compile Include="Local\SpotifyLocalAPIConfig.cs" />
<Compile Include="Local\VolumeMixerControl.cs" /> <Compile Include="Local\VolumeMixerControl.cs" />
<Compile Include="Web\Auth\WebAPIFactory.cs" /> <Compile Include="Web\Auth\WebAPIFactory.cs" />
<Compile Include="Web\Enums\RepeatState.cs" /> <Compile Include="Web\Enums\RepeatState.cs" />