Skip to content

Instantly share code, notes, and snippets.

@DinisCruz-Dev
Last active October 10, 2015 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DinisCruz-Dev/9193091 to your computer and use it in GitHub Desktop.
Save DinisCruz-Dev/9193091 to your computer and use it in GitHub Desktop.
Misc Groovy Scripts that invoke the Firebase APIs
def firebaseJsonData = "https://incandescent-fire-1320.firebaseio.com/.json?print=pretty"
def data = firebaseJsonData.toURL().getText()
return data;
def firebaseJsonData = "https://incandescent-fire-1320.firebaseio.com/.json?print=pretty"
def data = firebaseJsonData.toURL().getText()
def javascriptEditor = eclipse.registry.editor("JavaScript Editor");
eclipse.editors.open_String_in_Editor(javascriptEditor,data);
return javascriptEditor;
<!DOCTYPE html>
<html>
<head>
<meta charset="US-ASCII">
<title>Firebase test</title>
<script src='https://cdn.firebase.com/js/client/1.0.6/firebase.js' ></script>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js'></script>
</head>
<script>
var myRootRef = new Firebase('https://incandescent-fire-1320.firebaseio.com');
//myRootRef.push({name: 'Now using PUSH', text: 'Hello World Again!'});
//myRootRef.set("Value from Javascript");
myRootRef.on('child_added', function(snapshot)
{
//message = snapshot.valueOf().val();
//displayChatMessage("message", message);
message = snapshot.val();
displayChatMessage(message.name, message.text);
});
function displayChatMessage(name, text)
{
$('<div/>').html(text).prepend($('<em/>').text(name+': '))
.appendTo($('#messagesDiv'));
};
</script>
<body>
Messages:
<div id="messagesDiv"></div>
</body>
</html>
def firebaseUrl = "https://incandescent-fire-1320.firebaseio.com/.json";
dataToSubmit = ' { "name" : "Groovy" , ' +
' "text" : "Hello there from Groovy" }'
def connection = firebaseUrl.toURL().openConnection()
connection.setDoOutput(true)
connection.setRequestMethod("POST");
connection.outputStream.withWriter {
Writer writer -> writer << dataToSubmit;
};
def response = connection.inputStream.withReader { Reader reader -> reader.text }
return response;
@anselmoshim
Copy link

How do I fix an issue with "java.lang.SecurityException: Invoking methods on class java.net.URL is not allowed"? for

def connection = firebaseUrl.toURL().openConnection()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment