Skip to content

Commit 8bf31f5

Browse files
authored
Development (#248)
* Refresh the OAuth token when it expires * Fix my siliness and provide API consumers a way to provide their refresh token when using static auth * add query from hatched eggs + rewrite stuff around EggPokemon * fix the explaination for eclipse user * Level enum public for custom loggers * Publish sources jar Fixes #128 * add license to GoogleLoginSecrets * Use a reset instead of using another instance * Fix the checkstyle config to not break other modules * find Pokemon by ID update inventory after hatching eggs add missing license * Meta info on pokemon * add method the incubator * fix typo * Add a callback for when the Initial oAuth completes so that the app can automate the flow * Power up pokemon API * Add info about native google sign in * REAME.md: fix Usefull->Useful typo * README.md: fix PtcLogin classname type * fix force updating inventories * Fix incorrect static statements on point * Added iv calculator (#207) * Added iv calculator * checkstyleMain fix * Fix @returns in doc of getIVRatio() * take care that the candies actually are in the map * forgot that cancerous check style * tweak checkstyle config to be friendly (#226) * Add cause to LoginFailedExceptions. (#220) Signed-off-by: Niklas Walter <[email protected]> * Remove printStackTrace from updateProfile (#221) updateProfile, in case of failure, would dump stacktraces to the console and then crash in the next line with a NullPointerException * Added request to add modifiers to forts, for example a lure-module on a pokestop (#217) * implemented request to add fort modifier * added @throws to javadoc for addModifier in Pokestop.java * Added SetFavoritePokemon method (#222) * add lombok to more objects (#212) * add lombok to more objects * add lombok to GoogleAuthJson * add lombok to Team * getItemsCount function (#224) * get total space used by items * get total space used by items * add javadoc * Rewrote and Refactored login logic. Now the credential providers transparently handle providing credentials and refreshing tokens. * Update the protobuf dependency (#235) Includes fix for hatched eggs IndexOutOfBoundsException * WIP: Gym/Battle (#203) * Add info about native google sign in * fix force updating inventories * REAME.md: fix Usefull->Useful typo * README.md: fix PtcLogin classname type * Start Gym + Battle API * Battle API - Example included, utility functions to get state of battle. Can only spam attack right now. * Deprecate pokemon.getFavorite, rename to pokemon.isFavorite (#230) * deprecate getFavorite, rename to isFavorite * Adhere to checkstyle * Use gradle-wrapper instead (#200) * Use gradle-wrapper instead * Changed second gradle usage to use gradlew aswell * Fix typos (#218) * Fix UTF-8 encoding * Fix typo recieved -> received * fix example * Consistently use RemoteServerException for network/server errors (#243) * Redone meta pm, lots of info available, several enums for pokemon (some may be duplicates of proto enums), fix catchable pokemon (#246) * fix #237 + #227 (#240) * Update protobufs to latest version
1 parent f21ab72 commit 8bf31f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+7387
-872
lines changed

.github/CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ You may open an issue also to request new features. Make sure you describe what
1111
If you consider submitting a pull request, please note the following:
1212

1313
1. All pull requests **must** be submitted to the `Development` branch. The `master` branch is exclusively mutable by release. PRs against `master` will not be merged.
14-
2. Pleae make sure you follow the projects code style. To make sure you did, you can use `./gradlew checkstyleMain`.
14+
2. Please make sure you follow the projects code style. To make sure you did, you can use `./gradlew checkstyleMain`.
1515
3. The project is licensed under [GNU GPLv3](../LICENSE.txt) thus all code you submit will be subject to this license.
1616

1717
## Contact
18-
If you have any questions regarding the library you can ask those on the `#javaapi` channel on the [Pokemon GO Reverse Engineering Slack](https://pkre.slack.com/). You can [get your invite here](https://shielded-earth-81203.herokuapp.com/).
18+
If you have any questions regarding the library you can ask those on the `#javaapi` channel on the [Pokemon GO Reverse Engineering Slack](https://pkre.slack.com/). You can [get your invite here](https://shielded-earth-81203.herokuapp.com/).

.github/ISSUE_TEMPLATE.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
**Description:**
2-
[Short description of the issue observed. If this ia feature request you can modify the template as required.]
2+
[Short description of the issue observed. If this is a feature request you can modify the template as required.]
33

44
**Steps to reproduce:**
55

@@ -16,4 +16,4 @@
1616
[Please use pastebin if it's too long]
1717

1818
**Version:**
19-
[The version of the lib you used]
19+
[The version of the lib you used]

README.md

+17-8
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,29 @@ ___
2727
# Build
2828
- Clone the repo and cd into the folder
2929
- `` git submodule update --init ``
30-
- verify that you have gradle in your path
31-
- `` gradle build bundle ``
30+
- compile and package
31+
- `` ./gradlew build bundle ``
3232
- you should have the api bundled in ``build/libs/PokeGOAPI-Java_bundle-0.0.1-SNAPSHOT.jar``
3333

34-
PS : To eclipse user, you may build one time and add the generated java class for proto into eclipse path : Right click on the project > Build path > New Source Folder > Type 'build/generated/source/proto/main/java' > Finish
34+
PS : To Eclipse user, you must build once : `` ./gradlew build `` and add the generated java class for proto into eclipse source path : Right click on the project > Build path > Configure Build Path > Source > Add Folder > Select `build/generated/source/proto/main/java` > Finish
3535

3636
# Usage
3737
Include the API as jar from your own build, or use Maven/Gradle/SBT/Leiningen: https://jitpack.io/#Grover-c13/PokeGOAPI-Java/master-SNAPSHOT
3838

3939
Mostly everything is accessed through the PokemonGo class in the API package.
4040

41-
The constructor of PokemonGo class requires a AuthInfo object which can be obtained from GoogleLogin().login or PTCLogin().login, and a OkHttpClient object.
41+
The constructor of PokemonGo class requires a AuthInfo object which can be obtained from GoogleLogin().login or PtcLogin().login, and a OkHttpClient object.
4242

4343
EG:
4444
```java
4545
OkHttpClient httpClient = new OkHttpClient();
46-
AuthInfo auth = new GoogleLogin(httpClient).login("token");
47-
PokemonGo go = new PokemonGo(auth,httpClient);
46+
//Use Google
47+
//First Ever Login. Persist info when you recieve callback
48+
PokemonGo go = new PokemonGo(new GoogleCredentialProvider(httpClient,listner),httpClient);
49+
//Subsequently
50+
PokemonGo go = new PokemonGo(new GoogleCredentialProvider(httpClient,refreshToken),httpClient);
51+
//Or use PTC
52+
PokemonGo go = new PokemonGo(new PtcCredentialProvider(httpClient,username,password),httpClient);
4853
Log.v(go.getPlayerProfile());
4954
```
5055
##Android Dev FAQ
@@ -57,13 +62,17 @@ You're running the sample code on the UI thread. Strict mode policy will throw a
5762

5863
This library is meant to be a Java implementation of the API. Google Volley is specific to Android and should not be introduced in this library. However, if you still want to refactor it, you should create it as a separate project.
5964

65+
- How can I use Android's native Google sign in with this library?
66+
67+
You can't. The Google Identity Platform uses the SHA1 fingerprint and package name to authenticate the caller of all sign in requests. This means that Niantic would need to add your app's SHA1 fingerprint and package name to their Google API Console. If you ever requested a Google Maps API key, you went through the same process. An alternative would be using a WebView to access the web based OAuth flow. This will work with the client ID and secret provided by this library.
68+
6069

6170
## Contributing
6271
- Fork it!
6372
- Create your feature branch: `git checkout -b my-new-feature`
64-
- Commit your changes: `git commit -am 'Usefull information about your new features'`
73+
- Commit your changes: `git commit -am 'Useful information about your new features'`
6574
- Push to the branch: `git push origin my-new-feature`
66-
- Submit a pull request :D
75+
- Submit a pull request on the `Development` branch :D
6776

6877
## Contributors
6978
- Grover-c13

build.gradle

+12-2
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@ protobuf {
6262
}
6363
}
6464

65-
def checkstyleOutputDir = "${project.rootDir}/build/reports/checkstyle/"
65+
def checkstyleOutputDir = "${project.projectDir}/build/reports/checkstyle/"
6666

6767
checkstyle {
6868
toolVersion = '7.0'
69-
configFile = file("${project.rootDir}/config/checkstyle.xml")
69+
configFile = file("${project.projectDir}/config/checkstyle.xml")
70+
configProperties = [ "suppressionFile" : file("${project.projectDir}/config/suppressions.xml")]
7071
reportsDir = file(checkstyleOutputDir)
7172

7273
ignoreFailures = false
@@ -107,3 +108,12 @@ idea {
107108
sourceDirs += file("${protobuf.generatedFilesBaseDir}/main/java");
108109
}
109110
}
111+
112+
task sourcesJar(type: Jar) {
113+
from sourceSets.main.java.srcDirs
114+
classifier = 'sources'
115+
}
116+
117+
artifacts {
118+
archives sourcesJar
119+
}

config/checkstyle.xml

+5-18
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<module name = "Checker">
1818
<module name="SuppressionFilter">
19-
<property name="file" value="config/suppressions.xml"/>
19+
<property name="file" value="${suppressionFile}"/>
2020
</module>
2121

2222
<property name="charset" value="UTF-8"/>
@@ -57,7 +57,6 @@
5757
<property name="option" value="TEXT"/>
5858
<property name="tokens" value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/>
5959
</module>
60-
<module name="NeedBraces"/>
6160
<module name="LeftCurly">
6261
<property name="maxLineLength" value="120"/>
6362
</module>
@@ -67,10 +66,10 @@
6766
<property name="tokens" value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO, STATIC_INIT, INSTANCE_INIT"/>
6867
</module>
6968
<module name="WhitespaceAround">
70-
<property name="allowEmptyConstructors" value="true"/>
71-
<property name="allowEmptyMethods" value="true"/>
69+
<property name="allowEmptyConstructors" value="false"/>
70+
<property name="allowEmptyMethods" value="false"/>
7271
<property name="allowEmptyTypes" value="true"/>
73-
<property name="allowEmptyLoops" value="true"/>
72+
<property name="allowEmptyLoops" value="false"/>
7473
<message key="ws.notFollowed"
7574
value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/>
7675
<message key="ws.notPreceded"
@@ -149,17 +148,8 @@
149148
<property name="lineWrappingIndentation" value="4"/>
150149
<property name="arrayInitIndent" value="2"/>
151150
</module>
152-
<module name="AbbreviationAsWordInName">
153-
<property name="ignoreFinal" value="false"/>
154-
<property name="allowedAbbreviationLength" value="1"/>
155-
</module>
156151
<module name="OverloadMethodsDeclarationOrder"/>
157152
<module name="VariableDeclarationUsageDistance"/>
158-
<module name="CustomImportOrder">
159-
<property name="specialImportsRegExp" value="com.google"/>
160-
<property name="sortImportsInGroupAlphabetically" value="true"/>
161-
<property name="customImportOrderRules" value="STATIC###THIRD_PARTY_PACKAGE###STANDARD_JAVA_PACKAGE"/>
162-
</module>
163153
<module name="MethodParamPad"/>
164154
<module name="OperatorWrap">
165155
<property name="option" value="NL"/>
@@ -174,9 +164,6 @@
174164
</module>
175165
<module name="NonEmptyAtclauseDescription"/>
176166
<module name="JavadocTagContinuationIndentation"/>
177-
<module name="SummaryJavadocCheck">
178-
<property name="forbiddenSummaryFragments" value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )"/>
179-
</module>
180167
<module name="JavadocParagraph"/>
181168
<module name="AtclauseOrder">
182169
<property name="tagOrder" value="@param, @return, @throws, @deprecated"/>
@@ -204,4 +191,4 @@
204191
</module>
205192
<module name="CommentsIndentation"/>
206193
</module>
207-
</module>
194+
</module>
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Sun Jul 17 19:51:46 PDT 2016
1+
#Sat Jul 23 04:51:41 PDT 2016
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-all.zip

src/main/java/com/pokegoapi/api/PokemonGo.java

+25-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.pokegoapi.api.inventory.Inventories;
2020
import com.pokegoapi.api.map.Map;
2121
import com.pokegoapi.api.player.PlayerProfile;
22+
import com.pokegoapi.auth.CredentialProvider;
2223
import com.pokegoapi.exceptions.LoginFailedException;
2324
import com.pokegoapi.exceptions.RemoteServerException;
2425
import com.pokegoapi.main.RequestHandler;
@@ -49,31 +50,50 @@ public class PokemonGo {
4950
@Setter
5051
private double altitude;
5152

53+
private CredentialProvider credentialProvider;
54+
55+
private RequestEnvelopeOuterClass.RequestEnvelope.AuthInfo authInfo;
5256

5357
/**
5458
* Instantiates a new Pokemon go.
5559
*
56-
* @param auth the auth
5760
* @param client the client
5861
*/
59-
public PokemonGo(RequestEnvelopeOuterClass.RequestEnvelope.AuthInfo auth, OkHttpClient client)
62+
public PokemonGo(CredentialProvider credentialProvider, OkHttpClient client)
6063
throws LoginFailedException, RemoteServerException {
64+
65+
if (credentialProvider == null) {
66+
throw new LoginFailedException("Credential Provider is null");
67+
} else {
68+
this.credentialProvider = credentialProvider;
69+
}
70+
6171
playerProfile = null;
6272

6373
// send profile request to get the ball rolling
64-
requestHandler = new RequestHandler(this, auth, client);
65-
74+
requestHandler = new RequestHandler(this, client);
6675
playerProfile = new PlayerProfile(this);
6776
inventories = new Inventories(this);
6877

6978
playerProfile.updateProfile();
7079
inventories.updateInventories();
7180

7281
// should have proper end point now.
73-
7482
map = new Map(this);
7583
}
7684

85+
/**
86+
* Fetches valid AuthInfo
87+
*
88+
* @return AuthInfo object
89+
* @throws LoginFailedException when login fails
90+
*/
91+
public RequestEnvelopeOuterClass.RequestEnvelope.AuthInfo getAuthInfo()
92+
throws LoginFailedException, RemoteServerException {
93+
return credentialProvider.getAuthInfo();
94+
}
95+
96+
7797
/**
7898
* Gets player profile.
7999
*

0 commit comments

Comments
 (0)