Permalink
Browse files

v0.0.1 - initial commit

  • Loading branch information...
jgallen23 committed Nov 1, 2011
0 parents commit 8eb725ac7b891e247d7b3a17ba919b68fb95eea5
Showing with 84 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +4 −0 Makefile
  3. +1 −0 README.md
  4. +1 −0 index.js
  5. +30 −0 lib/placefinder.js
  6. +18 −0 package.json
  7. +28 −0 tests/placefinder.test.js
@@ -0,0 +1,2 @@
+.DS_Store
+node_modules
@@ -0,0 +1,4 @@
+test:
+ ./node_modules/.bin/nodeunit test/node.js
+
+.PHONY: test
@@ -0,0 +1 @@
+# Placefinder
@@ -0,0 +1 @@
+module.exports = require('./lib/placefinder');
@@ -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;
@@ -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"]
+}
@@ -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();
+ });
+};

0 comments on commit 8eb725a

Please sign in to comment.