Skip to content

Instantly share code, notes, and snippets.

@matejuh
Last active December 30, 2015 18:59
Show Gist options
  • Save matejuh/7871449 to your computer and use it in GitHub Desktop.
Save matejuh/7871449 to your computer and use it in GitHub Desktop.
Worklight showcase
function getMyAddress() {
var input = {
method : 'get',
returnedContentType : 'json',
path : "json"
};
return WL.Server.invokeHttp(input);
}
<?xml version="1.0" encoding="UTF-8"?>
<wl:adapter name="IPAdapter"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wl="http://www.worklight.com/integration"
xmlns:http="http://www.worklight.com/integration/http">
<displayName>IPAdapter</displayName>
<description>IPAdapter</description>
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>http</protocol>
<domain>freegeoip.net</domain>
<port>80</port>
</connectionPolicy>
<loadConstraints maxConcurrentConnectionsPerNode="2" />
</connectivity>
<procedure name="getMyAddress"/>
</wl:adapter>
function getDataFromAdapter(){
WL.Logger.info("get data from adapter");
var invocationData = {
adapter : "IPAdapter",
procedure : "getMyAddress",
parameters : []
};
WL.Client.invokeProcedure(invocationData, {
onSuccess : function(response){WL.Logger.info("OK: " + JSON.stringify(response.invocationResult)); alert(response.invocationResult.country_name + " " + response.invocationResult.city);},
onFailure : function(response){WL.Logger.info("fail: " + JSON.stringify(response.invocationResult));}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment