Skip to content

Commit

Permalink
Development (#248)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Grover-c13 authored Jul 26, 2016
1 parent f21ab72 commit 8bf31f5
Show file tree
Hide file tree
Showing 49 changed files with 7,387 additions and 872 deletions.
4 changes: 2 additions & 2 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ You may open an issue also to request new features. Make sure you describe what
If you consider submitting a pull request, please note the following:

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.
2. Pleae make sure you follow the projects code style. To make sure you did, you can use `./gradlew checkstyleMain`.
2. Please make sure you follow the projects code style. To make sure you did, you can use `./gradlew checkstyleMain`.
3. The project is licensed under [GNU GPLv3](../LICENSE.txt) thus all code you submit will be subject to this license.

## Contact
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/).
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/).
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
**Description:**
[Short description of the issue observed. If this ia feature request you can modify the template as required.]
[Short description of the issue observed. If this is a feature request you can modify the template as required.]

**Steps to reproduce:**

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

**Version:**
[The version of the lib you used]
[The version of the lib you used]
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,29 @@ ___
# Build
- Clone the repo and cd into the folder
- `` git submodule update --init ``
- verify that you have gradle in your path
- `` gradle build bundle ``
- compile and package
- `` ./gradlew build bundle ``
- you should have the api bundled in ``build/libs/PokeGOAPI-Java_bundle-0.0.1-SNAPSHOT.jar``

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
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

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

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

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

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

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.

- How can I use Android's native Google sign in with this library?

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.


## Contributing
- Fork it!
- Create your feature branch: `git checkout -b my-new-feature`
- Commit your changes: `git commit -am 'Usefull information about your new features'`
- Commit your changes: `git commit -am 'Useful information about your new features'`
- Push to the branch: `git push origin my-new-feature`
- Submit a pull request :D
- Submit a pull request on the `Development` branch :D

## Contributors
- Grover-c13
Expand Down
14 changes: 12 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ protobuf {
}
}

def checkstyleOutputDir = "${project.rootDir}/build/reports/checkstyle/"
def checkstyleOutputDir = "${project.projectDir}/build/reports/checkstyle/"

checkstyle {
toolVersion = '7.0'
configFile = file("${project.rootDir}/config/checkstyle.xml")
configFile = file("${project.projectDir}/config/checkstyle.xml")
configProperties = [ "suppressionFile" : file("${project.projectDir}/config/suppressions.xml")]
reportsDir = file(checkstyleOutputDir)

ignoreFailures = false
Expand Down Expand Up @@ -107,3 +108,12 @@ idea {
sourceDirs += file("${protobuf.generatedFilesBaseDir}/main/java");
}
}

task sourcesJar(type: Jar) {
from sourceSets.main.java.srcDirs
classifier = 'sources'
}

artifacts {
archives sourcesJar
}
23 changes: 5 additions & 18 deletions config/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<module name = "Checker">
<module name="SuppressionFilter">
<property name="file" value="config/suppressions.xml"/>
<property name="file" value="${suppressionFile}"/>
</module>

<property name="charset" value="UTF-8"/>
Expand Down Expand Up @@ -57,7 +57,6 @@
<property name="option" value="TEXT"/>
<property name="tokens" value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/>
</module>
<module name="NeedBraces"/>
<module name="LeftCurly">
<property name="maxLineLength" value="120"/>
</module>
Expand All @@ -67,10 +66,10 @@
<property name="tokens" value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO, STATIC_INIT, INSTANCE_INIT"/>
</module>
<module name="WhitespaceAround">
<property name="allowEmptyConstructors" value="true"/>
<property name="allowEmptyMethods" value="true"/>
<property name="allowEmptyConstructors" value="false"/>
<property name="allowEmptyMethods" value="false"/>
<property name="allowEmptyTypes" value="true"/>
<property name="allowEmptyLoops" value="true"/>
<property name="allowEmptyLoops" value="false"/>
<message key="ws.notFollowed"
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)"/>
<message key="ws.notPreceded"
Expand Down Expand Up @@ -149,17 +148,8 @@
<property name="lineWrappingIndentation" value="4"/>
<property name="arrayInitIndent" value="2"/>
</module>
<module name="AbbreviationAsWordInName">
<property name="ignoreFinal" value="false"/>
<property name="allowedAbbreviationLength" value="1"/>
</module>
<module name="OverloadMethodsDeclarationOrder"/>
<module name="VariableDeclarationUsageDistance"/>
<module name="CustomImportOrder">
<property name="specialImportsRegExp" value="com.google"/>
<property name="sortImportsInGroupAlphabetically" value="true"/>
<property name="customImportOrderRules" value="STATIC###THIRD_PARTY_PACKAGE###STANDARD_JAVA_PACKAGE"/>
</module>
<module name="MethodParamPad"/>
<module name="OperatorWrap">
<property name="option" value="NL"/>
Expand All @@ -174,9 +164,6 @@
</module>
<module name="NonEmptyAtclauseDescription"/>
<module name="JavadocTagContinuationIndentation"/>
<module name="SummaryJavadocCheck">
<property name="forbiddenSummaryFragments" value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )"/>
</module>
<module name="JavadocParagraph"/>
<module name="AtclauseOrder">
<property name="tagOrder" value="@param, @return, @throws, @deprecated"/>
Expand Down Expand Up @@ -204,4 +191,4 @@
</module>
<module name="CommentsIndentation"/>
</module>
</module>
</module>
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Jul 17 19:51:46 PDT 2016
#Sat Jul 23 04:51:41 PDT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-all.zip
30 changes: 25 additions & 5 deletions src/main/java/com/pokegoapi/api/PokemonGo.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.pokegoapi.api.inventory.Inventories;
import com.pokegoapi.api.map.Map;
import com.pokegoapi.api.player.PlayerProfile;
import com.pokegoapi.auth.CredentialProvider;
import com.pokegoapi.exceptions.LoginFailedException;
import com.pokegoapi.exceptions.RemoteServerException;
import com.pokegoapi.main.RequestHandler;
Expand Down Expand Up @@ -49,31 +50,50 @@ public class PokemonGo {
@Setter
private double altitude;

private CredentialProvider credentialProvider;

private RequestEnvelopeOuterClass.RequestEnvelope.AuthInfo authInfo;

/**
* Instantiates a new Pokemon go.
*
* @param auth the auth
* @param client the client
*/
public PokemonGo(RequestEnvelopeOuterClass.RequestEnvelope.AuthInfo auth, OkHttpClient client)
public PokemonGo(CredentialProvider credentialProvider, OkHttpClient client)
throws LoginFailedException, RemoteServerException {

if (credentialProvider == null) {
throw new LoginFailedException("Credential Provider is null");
} else {
this.credentialProvider = credentialProvider;
}

playerProfile = null;

// send profile request to get the ball rolling
requestHandler = new RequestHandler(this, auth, client);

requestHandler = new RequestHandler(this, client);
playerProfile = new PlayerProfile(this);
inventories = new Inventories(this);

playerProfile.updateProfile();
inventories.updateInventories();

// should have proper end point now.

map = new Map(this);
}

/**
* Fetches valid AuthInfo
*
* @return AuthInfo object
* @throws LoginFailedException when login fails
*/
public RequestEnvelopeOuterClass.RequestEnvelope.AuthInfo getAuthInfo()
throws LoginFailedException, RemoteServerException {
return credentialProvider.getAuthInfo();
}


/**
* Gets player profile.
*
Expand Down
Loading

0 comments on commit 8bf31f5

Please sign in to comment.