55
55
import com .pokegoapi .util .ClientInterceptor ;
56
56
import com .pokegoapi .util .SystemTimeImpl ;
57
57
import com .pokegoapi .util .Time ;
58
+ import com .pokegoapi .util .hash .HashProvider ;
58
59
import lombok .Getter ;
59
60
import lombok .Setter ;
60
61
import okhttp3 .OkHttpClient ;
@@ -128,6 +129,9 @@ public class PokemonGo {
128
129
@ Getter
129
130
private Heartbeat heartbeat = new Heartbeat (this );
130
131
132
+ @ Getter
133
+ private HashProvider hashProvider ;
134
+
131
135
/**
132
136
* Instantiates a new Pokemon go.
133
137
*
@@ -186,17 +190,22 @@ public PokemonGo(OkHttpClient client) {
186
190
* Login user with the provided provider
187
191
*
188
192
* @param credentialProvider the credential provider
193
+ * @param hashProvider to provide hashes
189
194
* @throws LoginFailedException When login fails
190
195
* @throws RemoteServerException When server fails
191
196
* @throws CaptchaActiveException if a captcha is active and the message can't be sent
192
197
*/
193
- public void login (CredentialProvider credentialProvider )
198
+ public void login (CredentialProvider credentialProvider , HashProvider hashProvider )
194
199
throws LoginFailedException , CaptchaActiveException , RemoteServerException {
195
200
this .loggingIn = true ;
196
201
if (credentialProvider == null ) {
197
- throw new NullPointerException ("Credential Provider is null" );
202
+ throw new NullPointerException ("Credential Provider can not be null!" );
203
+ } else if (hashProvider == null ) {
204
+ throw new NullPointerException ("Hash Provider can not be null!" );
198
205
}
199
206
this .credentialProvider = credentialProvider ;
207
+ this .hashProvider = hashProvider ;
208
+
200
209
startTime = currentTimeMillis ();
201
210
inventories = new Inventories (this );
202
211
settings = new Settings (this );
@@ -209,7 +218,7 @@ private void initialize() throws RemoteServerException, CaptchaActiveException,
209
218
playerProfile .updateProfile ();
210
219
211
220
ServerRequest downloadConfigRequest = new ServerRequest (RequestType .DOWNLOAD_REMOTE_CONFIG_VERSION ,
212
- CommonRequests .getDownloadRemoteConfigVersionMessageRequest ());
221
+ CommonRequests .getDownloadRemoteConfigVersionMessageRequest (this ));
213
222
fireRequestBlock (downloadConfigRequest , RequestType .GET_BUDDY_WALKED );
214
223
getAssetDigest ();
215
224
@@ -310,7 +319,7 @@ private void fireRequestBlock(ServerRequest request, RequestType... exclude)
310
319
*/
311
320
public void getAssetDigest () throws RemoteServerException , CaptchaActiveException , LoginFailedException {
312
321
fireRequestBlock (new ServerRequest (RequestType .GET_ASSET_DIGEST ,
313
- CommonRequests .getGetAssetDigestMessageRequest ()).exclude (RequestType .GET_BUDDY_WALKED ));
322
+ CommonRequests .getGetAssetDigestMessageRequest (this )).exclude (RequestType .GET_BUDDY_WALKED ));
314
323
}
315
324
316
325
/**
@@ -625,4 +634,11 @@ public void awaitChallenge() throws InterruptedException {
625
634
public void enqueueTask (Runnable task ) {
626
635
heartbeat .enqueueTask (task );
627
636
}
637
+
638
+ /**
639
+ * @return the version of the API being used
640
+ */
641
+ public int getVersion () {
642
+ return hashProvider .getHashVersion ();
643
+ }
628
644
}
0 commit comments