Merge pull request #2299 from collinjackson/moar_firebase

Android implementation of the remaining ::firebase::Firebase Mojo APIs
This commit is contained in:
Collin Jackson 2016-01-26 17:26:41 -08:00
commit b0c93a2bee
2 changed files with 174 additions and 19 deletions

View File

@ -45,12 +45,24 @@ interface ChildEventListener {
[ServiceName="firebase::Firebase"]
interface Firebase {
InitWithUrl(string url);
GetRoot(Firebase& root);
GetChild(string path, Firebase& child);
AddValueEventListener(ValueEventListener listener);
AddChildEventListener(ChildEventListener listener);
ObserveSingleEventOfType(EventType eventType) => (DataSnapshot snapshot);
AuthWithCustomToken(string token) => (Error? error, AuthData? authData);
AuthAnonymously() => (Error? error, AuthData? authData);
AuthWithOAuthToken(string provider, string credentials) => (Error? error, AuthData? authData);
AuthWithPassword(string email, string password) => (Error? error, AuthData? authData);
SetValue(string jsonValue) => (Error? error);
Unauth() => (Error? error);
GetChild(string path, Firebase& child);
GetParent(Firebase& parent);
GetRoot(Firebase& root);
SetValue(string jsonValue, int32 priority, bool hasPriority) => (Error? error);
RemoveValue() => (Error? error);
Push(Firebase& child) => (string key);
SetPriority(int32 priority) => (Error? error);
CreateUser(string email, string password) => (Error? error, string? jsonValue);
ChangeEmail(string oldEmail, string password, string newEmail) => (Error? error);
ChangePassword(string newPassword, string email, string oldPassword) => (Error? error);
RemoveUser(string email, string password) => (Error? error);
ResetPassword(string email) => (Error? error);
};

View File

@ -11,6 +11,8 @@ import com.firebase.client.AuthData;
import com.firebase.client.FirebaseError;
import com.firebase.client.Firebase.AuthResultHandler;
import com.firebase.client.Firebase.CompletionListener;
import com.firebase.client.Firebase.ResultHandler;
import com.firebase.client.Firebase.ValueResultHandler;
import java.io.IOException;
import java.util.ArrayList;
@ -59,20 +61,6 @@ public class FirebaseImpl implements org.chromium.mojom.firebase.Firebase {
mClient = new com.firebase.client.Firebase(url);
}
@Override
public void getRoot(InterfaceRequest<Firebase> request) {
FirebaseImpl root = new FirebaseImpl(mContext);
root.mClient = mClient.getRoot();
Firebase.MANAGER.bind(root, request);
}
@Override
public void getChild(String path, InterfaceRequest<Firebase> request) {
FirebaseImpl child = new FirebaseImpl(mContext);
child.mClient = mClient.child(path);
Firebase.MANAGER.bind(child, request);
}
@Override
public void addValueEventListener(org.chromium.mojom.firebase.ValueEventListener listener) {
final org.chromium.mojom.firebase.ValueEventListener.Proxy proxy =
@ -148,6 +136,32 @@ public class FirebaseImpl implements org.chromium.mojom.firebase.Firebase {
});
}
@Override
public void authWithCustomToken(String token, final AuthWithCustomTokenResponse response) {
mClient.authWithCustomToken(token, new AuthResultHandler() {
@Override
public void onAuthenticated(AuthData authData) {
response.call(null, toMojoAuthData(authData));
}
public void onAuthenticationError(FirebaseError error) {
response.call(toMojoError(error), null);
}
});
}
@Override
public void authAnonymously(final AuthAnonymouslyResponse response) {
mClient.authAnonymously(new AuthResultHandler() {
@Override
public void onAuthenticated(AuthData authData) {
response.call(null, toMojoAuthData(authData));
}
public void onAuthenticationError(FirebaseError error) {
response.call(toMojoError(error), null);
}
});
}
@Override
public void authWithOAuthToken(String provider, String credentials, final AuthWithOAuthTokenResponse response) {
mClient.authWithOAuthToken(provider, credentials, new AuthResultHandler() {
@ -175,11 +189,42 @@ public class FirebaseImpl implements org.chromium.mojom.firebase.Firebase {
}
@Override
public void setValue(String jsonValue, final SetValueResponse response) {
public void unauth(final UnauthResponse response) {
mClient.unauth(new CompletionListener() {
@Override
public void onComplete(FirebaseError error, com.firebase.client.Firebase ref) {
response.call(toMojoError(error));
}
});
}
@Override
public void getChild(String path, InterfaceRequest<Firebase> request) {
FirebaseImpl child = new FirebaseImpl(mContext);
child.mClient = mClient.child(path);
Firebase.MANAGER.bind(child, request);
}
@Override
public void getParent(InterfaceRequest<Firebase> request) {
FirebaseImpl parent = new FirebaseImpl(mContext);
parent.mClient = mClient.getParent();
Firebase.MANAGER.bind(parent, request);
}
@Override
public void getRoot(InterfaceRequest<Firebase> request) {
FirebaseImpl root = new FirebaseImpl(mContext);
root.mClient = mClient.getRoot();
Firebase.MANAGER.bind(root, request);
}
@Override
public void setValue(String jsonValue, int priority, boolean hasPriority, final SetValueResponse response) {
try {
JSONObject root = new JSONObject(jsonValue);
Object value = toMap(root).get("value");
mClient.setValue(value, null, new CompletionListener() {
mClient.setValue(value, hasPriority ? priority : null, new CompletionListener() {
@Override
public void onComplete(FirebaseError error, com.firebase.client.Firebase ref) {
response.call(toMojoError(error));
@ -195,6 +240,104 @@ public class FirebaseImpl implements org.chromium.mojom.firebase.Firebase {
}
}
@Override
public void removeValue(final RemoveValueResponse response) {
mClient.removeValue(new CompletionListener() {
@Override
public void onComplete(FirebaseError error, com.firebase.client.Firebase ref) {
response.call(toMojoError(error));
}
});
}
@Override
public void push(InterfaceRequest<Firebase> request, final PushResponse response) {
FirebaseImpl child = new FirebaseImpl(mContext);
child.mClient = mClient.push();
Firebase.MANAGER.bind(child, request);
response.call(child.mClient.getKey());
}
@Override
public void setPriority(int priority, final SetPriorityResponse response) {
mClient.setPriority(priority, new CompletionListener() {
@Override
public void onComplete(FirebaseError error, com.firebase.client.Firebase ref) {
response.call(toMojoError(error));
}
});
}
@Override
public void createUser(String email, String password, final CreateUserResponse response) {
mClient.createUser(email, password, new ValueResultHandler<Map<String,Object>>() {
@Override
public void onError(FirebaseError error) {
response.call(toMojoError(error), null);
}
@Override
public void onSuccess(Map<String,Object> result) {
response.call(null, new JSONObject(result).toString());
}
});
}
@Override
public void changeEmail(String oldEmail, String password, String newExample, final ChangeEmailResponse response) {
mClient.changeEmail(oldEmail, password, newExample, new ResultHandler() {
@Override
public void onError(FirebaseError error) {
response.call(toMojoError(error));
}
@Override
public void onSuccess() {
response.call(null);
}
});
}
@Override
public void changePassword(String newPassword, String email, String oldPassword, final ChangePasswordResponse response) {
mClient.changePassword(newPassword, email, oldPassword, new ResultHandler() {
@Override
public void onError(FirebaseError error) {
response.call(toMojoError(error));
}
@Override
public void onSuccess() {
response.call(null);
}
});
}
@Override
public void removeUser(String email, String password, final RemoveUserResponse response) {
mClient.removeUser(email, password, new ResultHandler() {
@Override
public void onError(FirebaseError error) {
response.call(toMojoError(error));
}
@Override
public void onSuccess() {
response.call(null);
}
});
}
@Override
public void resetPassword(String email, final ResetPasswordResponse response) {
mClient.resetPassword(email, new ResultHandler() {
@Override
public void onError(FirebaseError error) {
response.call(toMojoError(error));
}
@Override
public void onSuccess() {
response.call(null);
}
});
}
DataSnapshot toMojoSnapshot(com.firebase.client.DataSnapshot snapshot) {
DataSnapshot mojoSnapshot = new DataSnapshot();
mojoSnapshot.key = snapshot.getKey();