Skip to content

Commit

Permalink
Added docs
Browse files Browse the repository at this point in the history
  • Loading branch information
RubbaBoy committed Jun 7, 2019
1 parent 26ca6f7 commit 1e932bd
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/main/java/com/uddernetworks/paintassist/PaintAssist.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,26 @@
import java.util.Optional;

public interface PaintAssist {

/**
* Authenticates via {@link Authenticator#authenticate()} and initializes via {@link ActionListener#init()} the
* current client.
*
* @return The {@link Tokeninfo} generated if successful
*/
Optional<Tokeninfo> activate();

/**
* Gets the {@link Authenticator} used
*
* @return The {@link Authenticator}
*/
Authenticator getAuthenticator();

/**
* Gets the {@link ActionListener} used
*
* @return The {@link ActionListener}
*/
ActionListener getActionListener();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,25 @@

public interface ActionListener {

/**
* Initializes to and connects to the firebase database. Requires authentication via
* {@link com.uddernetworks.paintassist.auth.Authenticator} beforehand.
*
* @throws IOException If an IO exception occurs
*/
void init() throws IOException;

/**
* Adds a listener to activate when database changes happen.
*
* @param onRun The BiConsumer invoked when database changes happening, the parameters being the {@link Action}s
* being ran, and the time they were added to by the server in milliseconds.
*/
void listen(BiConsumer<List<Action>, Long> onRun);

/**
* Clears all listeners added by {@link ActionListener#listen(BiConsumer)}.
*/
void clearListeners();

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public DefaultActionsListener(PaintAssist paintAssist) {

@Override
public void init() throws IOException {
if (!this.paintAssist.getAuthenticator().isAuthenticated()) throw new RuntimeException("Tried to init without authentication.");

FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.getApplicationDefault())
.setDatabaseUrl("https://ms-paint-ide.firebaseio.com")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,41 @@
import com.google.api.services.oauth2.model.Tokeninfo;

import java.util.Optional;
import java.util.function.Consumer;

public interface Authenticator {

/**
* Gets if the client has been authenticated.
*
* @return If the client has been authenticated
*/
boolean isAuthenticated();

/**
* Resets authentication and deletes local token cache files
*/
void unAuthenticate();

/**
* Attempts to authenticate the use, returning the {@link Tokeninfo} if successful. If presented with a code 400
* error for whatever reason, it will try 3 times total. If all times fail, it will accept its fate and return an
* empty {@link Optional} and spit an error message in console.
*
* @return The {@link Tokeninfo} of the client if successful
*/
Optional<Tokeninfo> authenticate();

/**
* Gets the {@link Tokeninfo} made by invoking {@link Authenticator#authenticate()} previously, if existent.
*
* @return The {@link Tokeninfo} previously generated
*/
Optional<Tokeninfo> getTokenInfo();

/**
* Gets the {@link Oauth2} used internally.
*
* @return The {@link Oauth2} used
*/
Oauth2 getOAuth2();
}

0 comments on commit 1e932bd

Please sign in to comment.