Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
What 3 Words Strongloop Datasource
"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"
]
}
}
]
}
@avantassel

This comment has been minimized.

Copy link
Owner Author

commented Oct 20, 2015

Here's how to call it from a Strongloop Model with a vow promise

function getGeoWords(lat,lng){
    var deferred = vow.defer();
    var w3wDatasource = Model.app.dataSources.w3w;
    w3wDatasource.geoword(lat, lng,function(err, result) {
         if(result && result[0] && result[0].length === 3) {
           deferred.resolve( {'url':'http://w3w.co/'+result[0].join('.'), 'words': result[0]} );
         } else {
          deferred.reject('No w3w Found');
         }
       });
    return deferred.promise();
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.