Skip to content
Browse files

mongoose v bump make changed to gen

  • Loading branch information...
1 parent 0ca467c commit b77ac98f0a3171813160ac9871981fb27944ff78 Edward Hotchkiss committed
Showing with 14 additions and 20 deletions.
  1. +1 −1 README.md
  2. +4 −4 examples/api.js
  3. +7 −5 lib/short.js
  4. +0 −8 models/ShortURL.js
  5. +2 −2 package.json
View
2 README.md
@@ -19,7 +19,7 @@ mongoose.connect("mongodb://localhost/short");
var URL = "http://nodejs.org/";
-short.make(URL, function(error, shortURL) {
+short.gen(URL, function(error, shortURL) {
if (error) {
console.error(error);
} else {
View
8 examples/api.js
@@ -1,18 +1,18 @@
var mongoose = require("mongoose");
-var short = require("short");
+var short = require("../");
mongoose.connect("mongodb://localhost/short");
var URL = "http://nodejs.org/";
-short.make(URL, function(error, shortURL) {
+short.gen(URL, function(error, shortURL) {
if (error) {
- console.error(error);
+ throw new Error(error);
} else {
short.get(shortURL.hash, function(error, shortURLObject) {
if (error) {
- console.error(error);
+ throw new Error(error);
} else {
var URL = shortURLObject[0].URL
var hash = shortURLObject[0].hash;
View
12 lib/short.js
@@ -3,7 +3,7 @@
var mongoose = require("mongoose");
var base = require("base-converter");
-var ShortURL = require("../models/ShortURL.js");
+var ShortURL = require(__dirname + "/../models/ShortURL.js");
function hesher(URL) {
var id = Math.floor(Math.random() * (100000 - 9999999 + 1) + 9999999);
@@ -14,18 +14,20 @@ function hesher(URL) {
var short = function(){};
// if it exists, use pre-existing
-short.make = function(URL, callback) {
+short.gen = function(URL, callback) {
+ console.log("short.gen");
var hashedURL = hesher(URL);
ShortURL.checkExists(hashedURL, function(error, shortenedURLs) {
+ console.log("shortenedURLS", shortenedURLs);
if (error) {
callback(error, null);
} else {
if (shortenedURLs.length === 0) {
- var shortURLItem = new ShortURL({
+ var item = new ShortURL({
URL : URL,
hash : hashedURL
});
- shortURLItem.save(function(error, item) {
+ item.save(function(error, item) {
if (error) {
callback(error, null);
} else {
@@ -33,7 +35,7 @@ short.make = function(URL, callback) {
};
});
} else {
- short.make(URL, callback);
+ short.gen(URL, callback);
}
}
});
View
8 models/ShortURL.js
@@ -69,14 +69,6 @@ ShortURL.updateHitsById = function(id, callback) {
});
};
-// test
-var nodeTiny = new ShortURL({
- URL : "http://nodejs.org/",
- hash : "kQ4c"
-});
-
-nodeTiny.save();
-
module.exports = ShortURL;
/* EOF */
View
4 package.json
@@ -2,7 +2,7 @@
"author": "Edward Hotchkiss <e@ingk.com>",
"name": "short",
"description": "Generate, retieve short urls over mongoose/mongodb/express",
- "version": "0.0.9",
+ "version": "0.1.0",
"repository": {
"type": "git",
"url": "git://github.com/edwardhotchkiss/short.git"
@@ -13,7 +13,7 @@
"node": "~v0.4.11"
},
"dependencies": {
- "mongoose":"2.2.1",
+ "mongoose":"2.2.2",
"base-converter":"1.1.1"
}
}

0 comments on commit b77ac98

Please sign in to comment.
Something went wrong with that request. Please try again.