Reputation: 89
The following is a demo java code provided by firebase API. How do I use it? There seems to be no way to import the maven packages into my own project.
package net.thegreshams.firebase4j.demo;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import net.thegreshams.firebase4j.error.FirebaseException;
import net.thegreshams.firebase4j.error.JacksonUtilityException;
import net.thegreshams.firebase4j.model.FirebaseResponse;
import net.thegreshams.firebase4j.service.Firebase;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
public class Demo {
public static void main(String[] args) throws FirebaseException, JsonParseException, JsonMappingException, IOException, JacksonUtilityException {
// get the base-url (ie: 'http://gamma.firebase.com/username')
String firebase_baseUrl = null;
for( String s : args ) {
if( s == null || s.trim().isEmpty() ) continue;
if( s.trim().split( "=" )[0].equals( "baseUrl" ) ) {
firebase_baseUrl = s.trim().split( "=" )[1];
}
}
if( firebase_baseUrl == null || firebase_baseUrl.trim().isEmpty() ) {
throw new IllegalArgumentException( "Program-argument 'baseUrl' not found but required" );
}
// create the firebase
Firebase firebase = new Firebase( firebase_baseUrl );
// "DELETE" (the fb4jDemo-root)
FirebaseResponse response = firebase.delete();
// "PUT" (test-map into the fb4jDemo-root)
Map<String, Object> dataMap = new LinkedHashMap<String, Object>();
dataMap.put( "PUT-root", "This was PUT into the fb4jDemo-root" );
response = firebase.put( dataMap );
System.out.println( "\n\nResult of PUT (for the test-PUT to fb4jDemo-root):\n" + response );
System.out.println("\n");
// "GET" (the fb4jDemo-root)
response = firebase.get();
System.out.println( "\n\nResult of GET:\n" + response );
System.out.println("\n");
// "PUT" (test-map into a sub-node off of the fb4jDemo-root)
dataMap = new LinkedHashMap<String, Object>();
dataMap.put( "Key_1", "This is the first value" );
dataMap.put( "Key_2", "This is value #2" );
Map<String, Object> dataMap2 = new LinkedHashMap<String, Object>();
dataMap2.put( "Sub-Key1", "This is the first sub-value" );
dataMap.put( "Key_3", dataMap2 );
response = firebase.put( "test-PUT", dataMap );
System.out.println( "\n\nResult of PUT (for the test-PUT):\n" + response );
System.out.println("\n");
// "GET" (the test-PUT)
response = firebase.get( "test-PUT" );
System.out.println( "\n\nResult of GET (for the test-PUT):\n" + response );
System.out.println("\n");
// "POST" (test-map into a sub-node off of the fb4jDemo-root)
response = firebase.post( "test-POST", dataMap );
System.out.println( "\n\nResult of POST (for the test-POST):\n" + response );
System.out.println("\n");
// "DELETE" (it's own test-node)
dataMap = new LinkedHashMap<String, Object>();
dataMap.put( "DELETE", "This should not appear; should have been DELETED" );
response = firebase.put( "test-DELETE", dataMap );
System.out.println( "\n\nResult of PUT (for the test-DELETE):\n" + response );
response = firebase.delete( "test-DELETE");
System.out.println( "\n\nResult of DELETE (for the test-DELETE):\n" + response );
response = firebase.get( "test-DELETE" );
System.out.println( "\n\nResult of GET (for the test-DELETE):\n" + response );
}
}
The API developers also gave the following message for the firebase_url which is null in the above code:
"In order to use this project, you must first acquire a Firebase workspace-url. You can obtain a workspace-url by signing up for early-access to their private-beta."
Question: what does the second sentence mean? Could someone make that clearer? I really need the workspace-url
Upvotes: 1
Views: 2234
Reputation: 1782
I am the author of firebase4j.
As much as I love seeing people's interest in my project, it is very dated and not well-supported (for lack of time and interest); I approve other people's pull-requests to it but otherwise am not really maintaining it much. It was started as a POC and then one day I woke up and people were just using it (totally fine by me, but buyer-beware and all that). If this project actually fills a gap that is not provided by the official tooling, then I am totally open to people submitting pull-requests for new features and keeping the project going; but when I created this project I wrapped the Firebase REST API because they had no official Java support -- however, these days, that is no longer true (they do!).
Nevertheless, to answer the actual question asked here, I cite from the project's README:
In order to use this project, you must first acquire a Firebase workspace-url. You can obtain a workspace-url by signing up for early-access to their private-beta.
Alternatively, you can run through their tutorial and then use the auto-generated workspace-url the tutorial provides you with. This url, however, is transient so don't put any data in there you want to keep around.
You should also review the Firebase documentation and tutorial, as this interface is only meant to provide a thin wrapper around their REST API.
So, first consider that the documentation refers to Firebase's "early-access to their private-beta" -- that condition is no longer relevant. But basically it's just telling you to go to Firebase and sign-up for a developer-account; you can do that by signing into Firebase at firebase.google.com.
Regarding the workspace-url, that's just a reference to your Firebase-workspace that gets created when you define a Firebase-project at firebase.google.com. It is not in scope here to walk you through that, but I'm sure the tutorials cover it -- and by the time you are done reading their tutorials, you will probably decide to use the tooling that they provide today (which they did not when I wrote Firebase4j).
https://firebase.google.com/docs/admin/setup
Upvotes: 1