Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

v0.0.1 - initial commit

  • Loading branch information...
commit 8eb725ac7b891e247d7b3a17ba919b68fb95eea5 0 parents
Greg Allen authored
2  .gitignore
@@ -0,0 +1,2 @@
+.DS_Store
+node_modules
4 Makefile
@@ -0,0 +1,4 @@
+test:
+ ./node_modules/.bin/nodeunit test/node.js
+
+.PHONY: test
1  README.md
@@ -0,0 +1 @@
+# Placefinder
1  index.js
@@ -0,0 +1 @@
+module.exports = require('./lib/placefinder');
30 lib/placefinder.js
@@ -0,0 +1,30 @@
+var request = require('request');
+var querystring = require('querystring');
+
+var PlaceFinder = function(appID) {
+ this.baseUrl = "http://where.yahooapis.com/geocode?";
+ this.appID = appID;
+};
+
+PlaceFinder.prototype._makeRequest = function(params, callback) {
+ params.appid = this.appID;
+ params.flags = "J";
+ var qs = querystring.stringify(params);
+ var url = this.baseUrl+qs;
+ request(url, function(error, response, body) {
+ callback(error, JSON.parse(body));
+ });
+};
+
+PlaceFinder.prototype.location = function(name, callback) {
+ this._makeRequest({ location: name }, callback);
+};
+
+PlaceFinder.prototype.placeOfInterest = function(name, callback) {
+ this._makeRequest({ name: name }, callback);
+};
+
+PlaceFinder.prototype.woeid = function(woeid, callback) {
+ this._makeRequest({ woeid: woeid }, callback);
+};
+module.exports = PlaceFinder;
18 package.json
@@ -0,0 +1,18 @@
+{
+ "name": "placefinder",
+ "description": "a yahoo placefinder library",
+ "version": "0.0.1",
+ "homepage": "https://github.com/jgallen23/node-placefinder",
+ "author": "Greg Allen <@jgaui> (http://jga.me)",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/jgallen23/node-placefinder.git"
+ },
+ "dependencies": {
+ "request": "*"
+ },
+ "devDependencies": {
+ "nodeunit": "*"
+ },
+ "keywords": ["geo", "placefinder", "yahoo", "api"]
+}
28 tests/placefinder.test.js
@@ -0,0 +1,28 @@
+var PlaceFinder = require('../');
+var appID = "dUGYBq5g";
+
+exports.location = function(t) {
+ var pf = new PlaceFinder(appID);
+ pf.location('Hermosa Beach, CA', function(err, data) {
+ t.equal(data.ResultSet.Found, 1);
+ t.equal(data.ResultSet.Results[0].city, "Hermosa Beach");
+ t.done();
+ });
+};
+
+exports.placeOfInterest = function(t) {
+ var pf = new PlaceFinder(appID);
+ pf.placeOfInterest('Yosemite National Park', function(err, data) {
+ t.equal(data.ResultSet.Results[0].woeid, 55813396);
+ t.done();
+ });
+};
+
+exports.woeid = function(t) {
+ var pf = new PlaceFinder(appID);
+ var woeid = 12797150;
+ pf.woeid(woeid, function(err, data) {
+ t.equal(data.ResultSet.Results[0].woeid, woeid);
+ t.done();
+ });
+};
Please sign in to comment.
Something went wrong with that request. Please try again.