So, I just returned from #Gluecon in Broomfield, CO. What a great tech conference focused on Dev-ops, APIs, cloud, micro services and much more.
I walked away with a lot of homework and a few new tools and APIs. One API mentioned in a talk and one that I built right into an existing app I’m working on is what 3 words, which translates 3 words into a lat/long position and what I thought was a really cool concept.
I’ve also been working on a Strongloop API and wanted to share a rest datasource that I created for connecting to what 3 words.
Available on Github gist
Add this to your server/datasources.json
(fill in your API key under query.key)
"w3w": {
"name": "w3w",
"connector": "rest",
"operations": [
{
"template": {
"method": "GET",
"url": "http://api.what3words.com/position/",
"headers": {
"accepts": "application/json",
"content-type": "application/json"
},
"query": {
"position": "{lat},{lng}",
"lang": "en",
"key": ""
},
"responsePath": "$.words"
},
"functions": {
"geoword": [
"lat",
"lng"
]
}
}
]
}
And call it from any model,
function getGeoWords(lat, lng){
var deferred = vow.defer()
, w3wDS = Model.app.dataSources.w3w
, w3w_url = '';
w3wDS.geoword(lat, lng ,function(err, result) {
if(result
&& result[0]
&& result[0].length === 3) {
w3w_url = 'http://w3w.co/'+result[0].join('.');
deferred.resolve(w3w_url);
} else {
deferred.reject('No w3w Found: '+err);
}
});
return deferred.promise();
}