ISettings merge

FeroxRev [2016-07-20 21:21:30]
ISettings merge
Filename
PokemonGo/RocketAPI/Client.cs
PokemonGo/RocketAPI/Console/PokemonGo.RocketAPI.Console.csproj
PokemonGo/RocketAPI/Console/Program.cs
PokemonGo/RocketAPI/Console/Settings.cs
PokemonGo/RocketAPI/ISettings.cs
PokemonGo/RocketAPI/PokemonGo.RocketAPI.csproj
PokemonGo/RocketAPI/Settings.cs
diff --git a/PokemonGo/RocketAPI/Client.cs b/PokemonGo/RocketAPI/Client.cs
index 079c154..474a5db 100644
--- a/PokemonGo/RocketAPI/Client.cs
+++ b/PokemonGo/RocketAPI/Client.cs
@@ -1,31 +1,19 @@
 using System;
-using System.Collections.Generic;
-using System.IO.Compression;
-using System.Linq;
 using System.Net;
 using System.Net.Http;
-using System.Net.Http.Formatting;
-using System.Net.Http.Headers;
-using System.Runtime.InteropServices;
-using System.Text;
 using System.Threading.Tasks;
-using System.Web;
-using System.Windows.Forms;
 using Google.Protobuf;
-using Google.Protobuf.Collections;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
 using PokemonGo.RocketAPI.Enums;
 using PokemonGo.RocketAPI.GeneratedCode;
 using PokemonGo.RocketAPI.Helpers;
 using PokemonGo.RocketAPI.Extensions;
-using System.Threading;
 using PokemonGo.RocketAPI.Login;

 namespace PokemonGo.RocketAPI
 {
     public class Client
     {
+        private readonly ISettings _settings;
         private readonly HttpClient _httpClient;
         private AuthType _authType = AuthType.Google;
         private string _accessToken;
@@ -35,9 +23,10 @@ namespace PokemonGo.RocketAPI
         private double _currentLat;
         private double _currentLng;

-        public Client(double lat, double lng)
+        public Client(ISettings settings)
         {
-            SetCoordinates(lat, lng);
+            _settings = settings;
+            SetCoordinates(_settings.DefaultLatitude, _settings.DefaultLongitude);

             //Setup HttpClient and create default headers
             HttpClientHandler handler = new HttpClientHandler()
@@ -63,16 +52,16 @@ namespace PokemonGo.RocketAPI

         public async Task DoGoogleLogin()
         {
-            if (Settings.GoogleRefreshToken == string.Empty)
+            if (_settings.GoogleRefreshToken == string.Empty)
             {
                 var tokenResponse = await GoogleLogin.GetAccessToken();
                 _accessToken = tokenResponse.id_token;
-                Settings.GoogleRefreshToken = tokenResponse.access_token;
-                Console.WriteLine($"Put RefreshToken in settings for direct login: {Settings.GoogleRefreshToken}");
+                _settings.GoogleRefreshToken = tokenResponse.access_token;
+                Console.WriteLine($"Put RefreshToken in settings for direct login: {_settings.GoogleRefreshToken}");
             }
                 else
             {
-                var tokenResponse = await GoogleLogin.GetAccessToken(Settings.GoogleRefreshToken);
+                var tokenResponse = await GoogleLogin.GetAccessToken(_settings.GoogleRefreshToken);
                 _accessToken = tokenResponse.id_token;
                 _authType  = AuthType.Google;
             }
diff --git a/PokemonGo/RocketAPI/Console/PokemonGo.RocketAPI.Console.csproj b/PokemonGo/RocketAPI/Console/PokemonGo.RocketAPI.Console.csproj
index 35d2986..70cf8ed 100644
--- a/PokemonGo/RocketAPI/Console/PokemonGo.RocketAPI.Console.csproj
+++ b/PokemonGo/RocketAPI/Console/PokemonGo.RocketAPI.Console.csproj
@@ -48,6 +48,7 @@
   <ItemGroup>
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Settings.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="App.config" />
diff --git a/PokemonGo/RocketAPI/Console/Program.cs b/PokemonGo/RocketAPI/Console/Program.cs
index ca034df..932444e 100644
--- a/PokemonGo/RocketAPI/Console/Program.cs
+++ b/PokemonGo/RocketAPI/Console/Program.cs
@@ -16,6 +16,9 @@ namespace PokemonGo.RocketAPI.Console
 {
     class Program
     {
+
+        static readonly ISettings ClientSettings = new Settings();
+
         static void Main(string[] args)
         {
             Task.Run(() => Execute());
@@ -24,11 +27,11 @@ namespace PokemonGo.RocketAPI.Console

         static async void Execute()
         {
-            var client = new Client(Settings.DefaultLatitude, Settings.DefaultLongitude);
+            var client = new Client(ClientSettings);

-            if (Settings.AuthType == AuthType.Ptc)
-                await client.DoPtcLogin(Settings.PtcUsername, Settings.PtcPassword);
-            else if (Settings.AuthType == AuthType.Google)
+            if (ClientSettings.AuthType == AuthType.Ptc)
+                await client.DoPtcLogin(ClientSettings.PtcUsername, ClientSettings.PtcPassword);
+            else if (ClientSettings.AuthType == AuthType.Google)
                 await client.DoGoogleLogin();

             await client.SetServer();
diff --git a/PokemonGo/RocketAPI/Console/Settings.cs b/PokemonGo/RocketAPI/Console/Settings.cs
new file mode 100644
index 0000000..29314d4
--- /dev/null
+++ b/PokemonGo/RocketAPI/Console/Settings.cs
@@ -0,0 +1,17 @@
+using PokemonGo.RocketAPI.Enums;
+using PokemonGo.RocketAPI.GeneratedCode;
+
+namespace PokemonGo.RocketAPI.Console
+{
+    public class Settings : ISettings
+    {
+        //Fetch these settings from intercepting the /auth call in headers and body (only needed for google auth)
+        public AuthType AuthType { get;  } = Enums.AuthType.Google;
+        public  string PtcUsername { get; } = "User";
+        public  string PtcPassword { get; } = "alligator2";
+        public  string GoogleRefreshToken { get; set; } = string.Empty;
+        public  double DefaultLatitude { get; } = 10;
+        public  double DefaultLongitude { get; } = 10;
+        public MiscEnums.Item UsedBall { get; } = MiscEnums.Item.ITEM_POKE_BALL;
+    }
+}
diff --git a/PokemonGo/RocketAPI/ISettings.cs b/PokemonGo/RocketAPI/ISettings.cs
new file mode 100644
index 0000000..bf51c69
--- /dev/null
+++ b/PokemonGo/RocketAPI/ISettings.cs
@@ -0,0 +1,16 @@
+using PokemonGo.RocketAPI.Enums;
+using PokemonGo.RocketAPI.GeneratedCode;
+
+namespace PokemonGo.RocketAPI
+{
+    public interface ISettings
+    {
+        AuthType AuthType { get; }
+        double DefaultLatitude { get; }
+        double DefaultLongitude { get; }
+        string GoogleRefreshToken { get; set; }
+        string PtcPassword { get; }
+        string PtcUsername { get; }
+        MiscEnums.Item UsedBall { get; }
+    }
+}
\ No newline at end of file
diff --git a/PokemonGo/RocketAPI/PokemonGo.RocketAPI.csproj b/PokemonGo/RocketAPI/PokemonGo.RocketAPI.csproj
index 15c9b54..95b3426 100644
--- a/PokemonGo/RocketAPI/PokemonGo.RocketAPI.csproj
+++ b/PokemonGo/RocketAPI/PokemonGo.RocketAPI.csproj
@@ -89,9 +89,9 @@
     <Compile Include="Helpers\RetryHandler.cs" />
     <Compile Include="Helpers\S2Helper.cs" />
     <Compile Include="Helpers\Utils.cs" />
+    <Compile Include="ISettings.cs" />
     <Compile Include="Login\GoogleLogin.cs" />
     <Compile Include="Login\PtcLogin.cs" />
-    <Compile Include="Settings.cs" />
     <None Include="app.config" />
     <Compile Include="Client.cs" />
     <Compile Include="Extensions\HttpClientExtensions.cs" />
diff --git a/PokemonGo/RocketAPI/Settings.cs b/PokemonGo/RocketAPI/Settings.cs
deleted file mode 100644
index 3d374b7..0000000
--- a/PokemonGo/RocketAPI/Settings.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using PokemonGo.RocketAPI.Enums;
-using PokemonGo.RocketAPI.GeneratedCode;
-using PokemonGo.RocketAPI.Helpers;
-using PokemonGo.RocketAPI.Extensions;
-
-namespace PokemonGo.RocketAPI
-{
-    public static class Settings
-    {
-        //Fetch these settings from intercepting the /auth call in headers and body (only needed for google auth)
-        public const AuthType AuthType = Enums.AuthType.Google;
-        public const string PtcUsername = "username";
-        public const string PtcPassword = "pw";
-        public static string GoogleRefreshToken = string.Empty;
-        public const double DefaultLatitude = 10;
-        public const double DefaultLongitude = 10;
-    }
-}
You may download the files in Public Git.