.render().cast();
/* simple YQL query weather.forecast */
YQLParams params1 = YQLParams.create()
.format("json").diagnostics("true");
YQL yql1 = Y.newYQL("select * from weather.forecast where location=90210", new YQLCallback() {
@Override
public void call(YQLResult r) {
// console.log(Y.JSON().stringify(r));
WheatherForecastResult fresult = r.query().results().cast();
Channel channel = fresult.channel();
parent.append(
"<a href=\""+channel.link()+"\">"+
channel.title()+"</a> - Wind speed: "+channel.wind().speed()+" kph. " +
//or not using any Java API at all, just the js object api
"Direction: "+r.query().results().objGetObj("channel").
objGetObj("wind").objGetString("direction")+
//and because we use diagnostics("true"), we can access diagnostic info
"<p>Diagnostic - servicetime: "+r.query().diagnostics().serviceTime()+" ms."
);
}
}, params1);
/* an example using datatables.org, this time yui.gallery.all for information
* about yui gallery modules. We use the parameter "env". */
String query2 = "select * from yui.gallery.all";
YQLCallback yqlCallback2 = new YQLCallback() {
@Override
public void call(YQLResult r) {
JsObject o = r.query().results().objGetObj("json"); //type, count, modules, }
JsArray<JsObject> modules = o.objGetObj("modules").cast();
JsObject module0 = modules.get(0);
console.log("first module title is "+module0.objGetString("title"));
}
};
YQLParams yqlParams2 = YQLParams.create().env("http://datatables.org/alltables.env");
yqlParams2.format("json");
YQL yql2 = Y.newYQL(query2, yqlCallback2, yqlParams2);
/* handle an yql request that gives error */
YQL yql3 = Y.newYQL("select * from weather.nonexist123 where nonexists=90210", new YQLCallback() {
@Override
public void call(YQLResult r) {
if(r.error()!=null)
console.log("ERROR (it is ok..):"+r.error().description());
}