Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
An alternative to backend services. — Gideros Forum

An alternative to backend services.

Ozkar619Ozkar619 Member
edited April 2013 in User experience
Hello, I'm going to show you this cool service called iKnode. That i just started using and i'm already falling in love with.

iKnode is an API development platform that works as a back end as a service (BaaS).

Last week i was giving it a try, and even though there is no actual SDK to work with gideros, i developed one based on the JavaScript SDK and using urlLoader for http requests. And it works like a charm!

iKnode has a command center, where you develop your apps, and each app has a set of methods that helps you handle the data stored in your service.

For instance, I made this simple score manager, where you can retrieve score and add score from the web service's database.

It consists of two methods: getScore() wich returns a Json containing all the scores in the collection and addScore(string name, string score), it adds a new score ands sets a timestamp for the date.

Her'es the code i wrote on the iKnode's command center with C#
using System;
using iKnode.Applications;
using iKnode.Applications.Data;
using System.Collections.Generic;
 
namespace Applications
{
	[Application]
	public class ScoreManage : BasePackage
	{
 
        private const string CollectionName = "scoreCollection";
 
 
        public List<Document> getScore(){
        return this.Repository.QueryCollection(CollectionName,"{}","id","asc",0,10).List;
        }
 
        public void addScore(string name, string score){
            var date = DateTime.Now.ToString();
            var doc = new Document(CollectionName);
            doc["name"] = name;
            doc["score"] = score;
            doc["date"] = date;
            this.Repository.Save(doc);
        }
 
 
	}
}
Where CollectionName is the name of the database (or in this case, called collection) you are going to use on your documents.

Now, after that, i just called the iKnode service with the SDK i coded, and voilá. I could store and get data from the server.

this was the test code on Gideros:
local iKnodeService = iKnodeSdk.ApplicationClient(
{userId = "MY_ID",
apiKey = "MY_API_KEY", 
appName = "ScoreManage"} --My App Name
)
 
 
--[[
This is an example of a callback function.
 *<a href="https://forum.giderosmobile.com/profile/param" rel="nofollow">@param</a> data: it's what is going to be returned from the service.
]]--
getScoreCallback = function(data)
local scores = data
if (type(scores) == "table") then
print("table")
printTable(scores)
else if (type(scores) ~= "function") then
print(scores)
end
end
return scores
end
--This just prints the table recieved by iknode.
 
--Here we create the function that will call the iKnodeService and retrieve the Scores.
function getScores()
return iKnodeService:execute({
methodName = "getScore",
callback = getScoreCallback
})
end
 
--Here we create the function that will call the iKnodeService and will add score.
function addScore(name, score)
iKnodeService:execute({
methodName = "addScore",
parameters = {
name=name,
score=score
}
})
end
 
--Just a simple recursive function to print the table.
function printTable(tb)
for i,v in pairs(tb) do
if (type(v) == "table") then
printTable(v)
else
print(i..":"..v)
end
end
end
 
--As simple as this, you can get the stored scores by just calling a function.
local scores = getScores();
 
--Also with add score.
addScore("Iwasaddedfromgideros","100")
Here's a video showing how it works.



I think i'm gonna get creative, my next task (besides improving a lot more the score manager) is to create an achievement manager.
rar
rar
iKnodeSdk.rar
7K

Likes: fxone

+1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.