Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 130 lines (95 sloc) 2.877 kb
0cd66ff @edwardhotchkiss basic ripping it out from my /lib
authored
1
beb0bec [docs] stylize
Edward Hotchkiss authored
2 # short [![Build Status](https://secure.travis-ci.org/edwardhotchkiss/short.png)](http://travis-ci.org/edwardhotchkiss/short)
5b0fd33 @edwardhotchkiss updated documentation and removed some test logging
authored
3
beb0bec [docs] stylize
Edward Hotchkiss authored
4 > Node.JS URL Shortener backed by Mongoose.JS w/ Examples
f343619 @edwardhotchkiss travis in readme
authored
5
4e020b8 @edwardhotchkiss [cleanup] remove examples/, single file already in README
authored
6 ## Notes migrating to 1.0.0+
28b5cc8 @edwardhotchkiss remove `base-converter` as a dependency
authored
7
add213e @edwardhotchkiss readme notes on version 1.0.0 plus more descriptive
authored
8 NOTE: If you've used any version of Short before 1.0.0, please note the new API. This is a finalized API & with the previous API structure being incompatible with Short 1.0.0+
28b5cc8 @edwardhotchkiss remove `base-converter` as a dependency
authored
9
4e020b8 @edwardhotchkiss [cleanup] remove examples/, single file already in README
authored
10 ## Running Examples
28b5cc8 @edwardhotchkiss remove `base-converter` as a dependency
authored
11
12 ```bash
13 $ git clone git@github.com:edwardhotchkiss/short.git
14 $ cd short/examples/basic
cc89189 @edwardhotchkiss node api.js vs. API.js
authored
15 $ node api.js
28b5cc8 @edwardhotchkiss remove `base-converter` as a dependency
authored
16 ```
17
4e020b8 @edwardhotchkiss [cleanup] remove examples/, single file already in README
authored
18 ## Installation
0cd66ff @edwardhotchkiss basic ripping it out from my /lib
authored
19
20 ```bash
21 $ npm install short
22 ```
efcf566 @edwardhotchkiss use contributors full name
authored
23
5b0fd33 @edwardhotchkiss updated documentation and removed some test logging
authored
24 ***
25
4e020b8 @edwardhotchkiss [cleanup] remove examples/, single file already in README
authored
26 ## Basic API Usage
0cd66ff @edwardhotchkiss basic ripping it out from my /lib
authored
27
fb25d57 @edwardhotchkiss changelog for 1.0.0
authored
28 Using short within your own project as an API interface
83f3ead @edwardhotchkiss improvements in the readme
authored
29
0cd66ff @edwardhotchkiss basic ripping it out from my /lib
authored
30 ```javascript
5b0fd33 @edwardhotchkiss updated documentation and removed some test logging
authored
31
beb0bec [docs] stylize
Edward Hotchkiss authored
32 /**
33 * @list dependencies
e4246fe [docs] add latest contributors [@cbrammer, @lynchseattle] to README
Edward Hotchkiss authored
34 **/
38a4233 @edwardhotchkiss changes, unstable break time
authored
35
616188d @edwardhotchkiss [minor] update basic example
authored
36 var short = require('short')
37 , URL = 'http://nodejs.org/';
38
beb0bec [docs] stylize
Edward Hotchkiss authored
39 /**
40 * @description connect to mongodb
41 **/
42
616188d @edwardhotchkiss [minor] update basic example
authored
43 short.connect('mongodb://localhost/short');
28b5cc8 @edwardhotchkiss remove `base-converter` as a dependency
authored
44
45 short.connection.on('error', function(error){
46 throw new Error(error);
47 });
48
beb0bec [docs] stylize
Edward Hotchkiss authored
49 /**
50 * @description generate a shortened URL
51 * ... Retrieve URL based on Generated Hash
52 **/
28b5cc8 @edwardhotchkiss remove `base-converter` as a dependency
authored
53
54 short.generate(URL, function(error, shortURL) {
5b0fd33 @edwardhotchkiss updated documentation and removed some test logging
authored
55 if (error) {
56 throw new Error(error);
57 } else {
28b5cc8 @edwardhotchkiss remove `base-converter` as a dependency
authored
58 short.retrieve(shortURL.hash, function(error, shortenedURLObject) {
5b0fd33 @edwardhotchkiss updated documentation and removed some test logging
authored
59 if (error) {
60 throw new Error(error);
61 } else {
28b5cc8 @edwardhotchkiss remove `base-converter` as a dependency
authored
62 console.log('URL:', shortenedURLObject.URL);
63 console.log('hash:', shortenedURLObject.hash);
64 process.exit(0);
616188d @edwardhotchkiss [minor] update basic example
authored
65 }
5b0fd33 @edwardhotchkiss updated documentation and removed some test logging
authored
66 });
67 }
38a4233 @edwardhotchkiss changes, unstable break time
authored
68 });
83f3ead @edwardhotchkiss improvements in the readme
authored
69
beb0bec [docs] stylize
Edward Hotchkiss authored
70 /**
71 * @description Generate a Shortened URL with custom data stored on the hashed URL
72 * Retrieve URL based on Generated Hash and retrieve custom data
73 * Make sure to use obj.data.toObject() for accessing your custom data
74 **/
f4c8e0e @lynchseattle Added support for passing in custom data in the options when creating a ...
lynchseattle authored
75
76 var short = require('short')
77 , URL = 'http://nodejs.org/',
71b1ece [dist] version bump / changelog update
Edward Hotchkiss authored
78 , options = {length: 6, data: {'my':'value','is':2}};
f4c8e0e @lynchseattle Added support for passing in custom data in the options when creating a ...
lynchseattle authored
79
80 short.generate(URL, options, function(error, shortURL) {
81 if (error) {
82 throw new Error(error);
83 } else {
84 short.retrieve(shortURL.hash, function(error, shortenedURLObject) {
85 if (error) {
86 throw new Error(error);
87 } else {
88 console.log('URL:', shortenedURLObject.URL);
89 console.log('hash:', shortenedURLObject.hash);
90 console.log('data:', JSON.stringify(shortenedURLObject.data.toObject()));
91 process.exit(0);
92 }
93 });
94 }
95 });
96
a551de7 @edwardhotchkiss as an api or as a service
authored
97 ```
c077f43 @edwardhotchkiss formating
authored
98
4e020b8 @edwardhotchkiss [cleanup] remove examples/, single file already in README
authored
99 ## Complete Example with Express
fb25d57 @edwardhotchkiss changelog for 1.0.0
authored
100
28cf099 @edwardhotchkiss for full example please see @thinkroth 's work
authored
101 **Please see** https://github.com/thinkroth/shortUrl
fb09cb0 @thinkroth Added express example to readme
thinkroth authored
102
e46c40b @edwardhotchkiss [docs] contribute
authored
103 ## Contribute
fdeba0a @edwardhotchkiss pull requests section on README
authored
104
e46c40b @edwardhotchkiss [docs] contribute
authored
105 1. Fork
106 2. Clone forked repository
107 3. Add some sweet code
108 4. Tests still passing? Run tests with `npm test`
109 5. Add a test if adding a feature
110 6. Pull Request
111 7. **Instant Karma!**
aa81574 @edwardhotchkiss added kevin to readme via contributors, added license and test `npm test...
authored
112
4e020b8 @edwardhotchkiss [cleanup] remove examples/, single file already in README
authored
113 ## License (MIT)
aa81574 @edwardhotchkiss added kevin to readme via contributors, added license and test `npm test...
authored
114
115 Copyright (c) 2011, Edward Hotchkiss.
116
45d9246 @edwardhotchkiss readme formating
authored
117 ### Author: [Edward Hotchkiss][0]
e4246fe [docs] add latest contributors [@cbrammer, @lynchseattle] to README
Edward Hotchkiss authored
118
119 ### Contributors:
120
71b1ece [dist] version bump / changelog update
Edward Hotchkiss authored
121 [Kevin Roth][1],
122 [Chase Brammer][2],
123 [Chris Lynch][3],
aa81574 @edwardhotchkiss added kevin to readme via contributors, added license and test `npm test...
authored
124
e46c40b @edwardhotchkiss [docs] contribute
authored
125 [0]: http://edwardhotchkiss.com/
aa81574 @edwardhotchkiss added kevin to readme via contributors, added license and test `npm test...
authored
126 [1]: http://github.com/thinkroth/
e4246fe [docs] add latest contributors [@cbrammer, @lynchseattle] to README
Edward Hotchkiss authored
127 [2]: https://github.com/cbrammer/
128 [3]: https://github.com/lynchseattle/
129
Something went wrong with that request. Please try again.