On Tuesday, July 23, 2013 7:14:56 PM UTC+2, Manigandan Jegannathan wrote:
> Hi TDI experts,
>
>
>
> why don't we have connector for Google(gmail) managed resource. is it any other way manage Gmail domain except using google API. Would be better if it has something like that.
You could easily script one. There's a YouTube video on how to script Connectors. And then you could use code like this (if you are getting JSON back):
json = makeCall(url, "No parameters returned from Dataset")
This would necessitate the function defined below
------------
// Run once when script is loaded
http = system.getConnector("ibmdi.HTTPClient")
// Make HTTP GET call to the uri/url specified. Throw the errormsg if it fails
function makeCall(uri, errormsg) {
var httpEntry
var jsonStr
var json
// set up the http connector
http.setParam("url", uri)
http.setParam("username", user)
http.setParam("password", password)
http.initialize(null)
// set up the
httpEntry = system.newEntry();
httpEntry["http.content-type"] = "application/json"
//httpEntry["http.method"] = "GET" // this only sets the header prop; setParam("method") changes HTTP verb used
httpEntry["http.accept"] = "application/json"
// Debug output that comes to commandline (or Console tab with Server output)
java.lang.System.out.println("uri: " + uri)
// Make the call
httpEntry = http.queryReply(httpEntry)
// Get the return payload
jsonStr = httpEntry.getString("http.bodyAsString")
// More debug output
java.lang.System.out.println(">>Making call to " + uri + "\n<<Received: " + jsonStr)
if (jsonStr == null)
{
throw errormsg + " - HTTP return:\n" + httpEntry.toString()
}
else
{
try
{
json = fromJson(jsonStr)
}
catch (ex)
{
throw errormsg + " - Error parsing JSON received: " + ex + " JSON: " + jsonStr
}
}
if (typeof(json) == "undefined" || json == null) {
throw errormsg + " - HTTP return:\n" + httpEntry.toString()
} else
if (json.msgSeverity)
throw json.msgText + "\nJSON returned:\n" + jsonStr
return json
}
--------------
So you've got a json object. If you want instead to create an Entry object (like work or conn)
that mirrors the hierarchy of the JSON object, replace the line: json = fromJson(jsonStr)
with: jsonEntry = work.fromJSON(jsonStr)
Then you can use DOM Interface calls to get 'nodes' in the hierarchical tree. For example:
personObjects = jsonEntry.getElementsByTagName("Person")
// note that the above works if you had parsed XML as well, using work.fromXML("*","",xmlStr) instead.
for (var i = 0; i < personObjects.getLength(); i++) {
personNode = personObjects.item(i)
// from here you process your node, e.g. personNode.name, personNode.id
// and handling sub-trees: personNode.mail[0] or personNode.getChildNodes()
// you also have xpath search methods in the Entry class.
}
You can also use the for() approach to iterating through the NodeList:
for (personNode in personObjects) { ...
Hope this helps!