network API examples

Following listings presents how to use network features of the robot's modules using robot structure. First one presents how to check weather and news utilizing UBrowser module.

//example shows how to weather forecast or news can be easily read thanks to robot structure
robot.network.weather.Get();//we simpy call robot.network.weather.Get() to get new weather forecast
//now we can access the forecast by reading consecutive weather parameters, e.g.
echo(robot.network.weather.wind.speed);
echo(robot.network.weather.wind.direction);
echo(robot.network.weather.wind.chill);
//we can also read overall weather forecast for next days
var tmp_forecast = robot.network.weather.forecast.day1;//for the next day
echo("Day "+ tmp_forecast[0]);
echo("Date "+ tmp_forecast[1]);
echo("Lowest temp "+ tmp_forecast[2]);
echo("Highest temp "+ tmp_forecast[3]);
echo("Condition "+ tmp_forecast[4]);
echo("Condition code "+ tmp_forecast[5]);
//in similar matter we read news from rss channels:
//we get news from desired address
robot.network.news.Get("http://www.skynews.com.au/rss/");//get news from Sky News 
//Now we can simply check if there are some news
if (robot.network.news.count!=0)
echo(robot.network.news.title[0]);//and read their title
echo(robot.network.news.description[0]);//and content
 

The following listing presents how to send and receive e-mails via robot structure.

//the examples show how to use robot mail box, in case of using user mail box instead, replace "robot" with "user"
//fill the standard e-mail fields:
robot.network.mail["robot"].send.From("I Robot");
robot.network.mail["robot"].send.To(["example.name[at]gmail.com","another.example[at]gmail.com"]);
robot.network.mail["robot"].send.Cc([]);
robot.network.mail["robot"].send.Bcc([]);
robot.network.mail["robot"].send.Subject("Hi! It's me");
robot.network.mail["robot"].send.Content("I am a funny robot!<br /> Please check my attachment.<br /><br /><strong><em>I Robot</em></strong>");
robot.network.mail["robot"].send.Attachment(["me.jpg"]);
robot.network.mail["robot"].Send();
//the above procedure is standard regardless the utilized mail module - UMail (POCO)/UMail (CURL)
//when using UMAIL (CURL) you can give your attachments unique ID and add them to mail content (e.g. picture will be displayed inside the e-mail, not presented as a file in attachment list)
robot.network.mail["robot"].send.Content("<img src="cid:ID_XXX_XXX" alt="" /><br /><br /><b><i>My Robot</i></b>");
robot.network.mail["robot"].send.Attachment(["saved/photo.jpg"]);
robot.network.mail["robot"].send.AttachmentID(["ID_XXX_XXX"]);
//Receiving e-mail utilizing POCO module
var tmp_number = robot.network.mail["robot"].receive.newNo;//number of new emails
robot.network.mail["robot"].Receive(); //we download all new e-mails
robot.network.mail["robot"].receive.SaveAttachments("path/to/save/");//and save attachments
//all fields of robot.network.mail["robot"].receive receive vectors of information - we read them one by one
for(var i = 0; iter<tmp_number; i++)
{
echo ("E-mail no: " + i);
echo ("From: "+ robot.network.mail["robot"].receive.From[i]);
echo ("Subject: "+ robot.network.mail["robot"].receive.Subject[i]);
echo ("Content: "+ robot.network.mail["robot"].receive.Content[i]);
};
//Receiving e-mail utilizing CURL module
var tmp_ids = robot.network.mail["robot"].receive.ID; //vector of IDs of new e-mails in mailbox
var tmp_number = ids.size();//number of new e-mails
for(var i = 0; iter<tmp_number; i++)
{
robot.network.mail["robot"].Receive(tmp_ids[i]);//we download from server one e-mail with ID from vector of avaliable IDs
robot.network.mail["robot"].receive.SaveAttachments(tmp_ids[i],"path/to/save/");//we also save attachments
echo ("E-mail no: " + i);
//this time fields contain information only about last downloaded e-mail
echo ("From: "+ robot.network.mail["robot"].receive.From);
echo ("Subject: "+ robot.network.mail["robot"].receive.Subject);
echo ("Content: "+ robot.network.mail["robot"].receive.Content);
};
 

The following listing presents how to use features of Facebook module using robot structure

//the examples show how to use robot Facebook, in case of using user Facebook instead, simply replace "robot" with "user"
robot.network.facebook["robot"].notification.Get(); //get robot notifications
echo(robot.network.facebook["robot"].notification.fromName[0]);//print the full information about source of first notification
echo(robot.network.facebook["robot"].notification.title[0]);//print the title of first notification
robot.network.facebook["robot"].album.Get();//get all robot's albums
robot.network.facebook["robot"].photo.Get(robot.network.facebook["robot"].album.ID[0]);//get all photos from the first album
robot.network.facebook["robot"].photo.Put(robot.network.facebook["robot"].album.ID[0]),"It's me.","image.jpg");//put photo "image.jpg" in first album with description "It's me."
robot.network.facebook["robot"].post.GetFeed();//get all things that robot might see on his own wall
echo(robot.network.facebook["robot"].post.fromName[0]);//print the user full name who posted first post
echo(robot.network.facebook["robot"].post.message[0]);//print the content of first message
robot.network.facebook["robot"].post.PutPost("Hello");//put post on robots wall
robot.network.facebook["robot"].like.Put(robot.network.facebook["robot"].post.ID[0]);//like the first of the read posts
robot.network.facebook["robot"].comment.Put(robot.network.facebook["robot"].post.ID[0],"It's me!");//comment the first post on Facebook
 

The following listing presents how to access Google calendar and contacts features via robot structure.

//examples show how to use user calendar and contacts
robot.network.gcalendar["user"].calendar.Get();//we get information about robot calendars
robot.network.gcalendar["user"].event.Get(robot.network.gcalendar["user"].calendar.ID,Date.now.asString.split(".")[0],"");//we get all events from the first calendar which are starting today or later
//we display info about first event 
echo(robot.network.gcalendar["user"].event.ID[0]);
echo(robot.network.gcalendar["user"].event.description[0]);
echo(robot.network.gcalendar["user"].event.location[0]);
echo(robot.network.gcalendar["user"].event.startTime[0]);
echo(robot.network.gcalendar["user"].event.endTime[0]);
//we set event in primary calendar
robot.network.gcalendar["user"].event.set("primary","Meeting","Wroclaw","2014-08-22 08:00:00","2014-08-22 10:00:00",15,-1,-1);//send e-mail 15 minutes before meeting, do not remind via popup or sms
//we set whole day event in primary calendar
robot.network.gcalendar["user"].event.set("primary","Delegation","London","2014-08-01","2014-08-10",-1,-1,-1);//-1,-1,-1 means that we do not want any reminder of event
 
//accessing Google contacts 
robot.network.gcontact["user"].group.Get();//get user contacts groups
robot.network.gcontact["user"].contact.Get(robot.network.gcontact["user"].group.ID[0]);//get contacts from first group
//print data of first contact from first group
echo(robot.network.gcontact["user"].contact.title[0]);
echo(robot.network.gcontact["user"].contact.email[0]);
echo(robot.network.gcontact["user"].contact.phone[0]);

 

 

EMYS and FLASH are Open Source and distributed according to the GPL v2.0 © Rev. 0.9.1, 15.05.2017

FLASH Documentation