Justin Lennox • almost 11 years ago
Retrieve Anything from Clusterpoint!
Hello,
I've never used a database like Clusterpoint before and I don't know anything about NoSQL and the like. I've used simpler services like Parse. I'm trying to just figure out how to retrieve a simple string from my Clusterpoint database in Unity. Can anyone give me any direction for how to do this? I've been scavenging online but I'm coming up short. Any help at all is welcome!!
Thank you,
Justin
Comments are closed.

2 comments
Jurgis Orups • almost 11 years ago
Hi, I'm not expert in Unity but have some knowledge about Clusterpoint :)
In your case most likely you will have to use REST API over http/https to talk to Clusterpoint database.
To make https requests in Unity you should use WWW class (http://docs.unity3d.com/ScriptReference/WWW.html).
As for Clusterpoint REST API you can take a look in examples: http://docs.clusterpoint.com/examples.
Here I tried to compose my first lines in Unity, so code is not tested but will give you something to start from:
//return first 100 records starting from offset 0
var rawData = "{\"query\": \"*\", \"docs\" : \"100\", \"offset\" : \"0\"}';
//Replace ACCOUNT_ID and DATABASE with yours
var url = "https://api-us.clusterpoint.com/ACCOUNT_ID/DATABASE/_search.json";
var headers = new Hashtable();
// In this case a basic authentication to access a password protected resource.
// Replace USERNAME:PASSWORD
headers.Add("Authorization", "Basic " + System.Convert.ToBase64String(
System.Text.Encoding.ASCII.GetBytes("USERNAME:PASSWORD")));
headers.Add("Content-Type", "text/json");
headers.Add("Content-Length", rawData.Length);
// Post a request to an URL
var www = new WWW(url, System.Text.Encoding.UTF8.GetBytes(rawData), headers);
yield www;
//.. process results from WWW request here...
if(www.error) {
print("There was an error posting the high score: " + www.error);
}else{
//here you should get JSON string returned from database
print(www.text);
}
Hope it helps
Justin Lennox • almost 11 years ago
Thank you so much! That helped immensely!