Skip to content

Instantly share code, notes, and snippets.

@avantassel
Created October 20, 2015 03:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avantassel/4b9903b2c3d09d3a8daf to your computer and use it in GitHub Desktop.
Save avantassel/4b9903b2c3d09d3a8daf to your computer and use it in GitHub Desktop.
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
Copy link
Author

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