This repository has been archived by the owner on Dec 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from kaimallea/refactor
Refactor code
- Loading branch information
Showing
9 changed files
with
436 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,61 @@ | ||
## Installation | ||
## Command-line Usage | ||
|
||
npm install -g imgur | ||
### Installation | ||
|
||
## Command-line Usage | ||
```bash | ||
npm install imgur -g | ||
``` | ||
|
||
**You must set an API key before CLI use; get one at http://imgur.com/register/api_anon** | ||
### Usage | ||
|
||
Pass binary image files, urls, and/or base64-encoded image strings as arguments. Globbing is supported. | ||
|
||
Set your API key once and forget it (saved to ~/.imgurkey) | ||
Upload a single image: | ||
|
||
imgur -k aCs53GSs4tga0ikp | ||
```bash | ||
imgur cat.png | ||
``` | ||
|
||
Upload a single image | ||
Upload all the jpegs in a particular folder: | ||
|
||
imgur GooglePlus.png | ||
```bash | ||
imgur ~/Pictures/kittens/*.jpg | ||
``` | ||
|
||
Upload an entire directory (**not recursive yet**; automatically chooses pics) | ||
Upload an image from another place on the web: | ||
|
||
imgur ~/Pictures/ | ||
```bash | ||
imgur --url http://lolz.pics.com/troll.png | ||
``` | ||
|
||
Upload all .png files in the current directory | ||
Upload a Base-64 encoded image: | ||
|
||
imgur *.png | ||
|
||
```bash | ||
imgur --base64 iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAmUlEQVQ4je2TsQ3CMBBFnxMa08WR2IQKJskIUNwMZAcYwWIQMs65JCUpEEIYW4pJy6v+6e6+/hVnnGsAzsCBMi7AsbbW/rIMsAU2xrnmkeruuzW7zgIw+JGbv6fGQpWzfy3HOsJlDQY/AlCv3jpF9oS5ZBOICKoB1YCIlCdQDR9127qyBHP5Gyw3CBXPr/qi709JHXE1S995AsqoJu8x78GsAAAAAElFTkSuQmCC | ||
``` | ||
|
||
## Module Usage | ||
|
||
```javascript | ||
var imgur = require('imgur'); | ||
### Installation | ||
|
||
imgur.setKey('aCs53GSs4tga0ikp'); | ||
|
||
imgur.upload('/Users/kmallea/Pictures/Manga_Kai.jpg', function (response) { | ||
|
||
if (response.error) { | ||
console.log(response.error); | ||
return; | ||
} | ||
|
||
console.log('Direct link: ' + response.links.original); | ||
console.log('Imgur page: ' + response.links.imgur_page); | ||
}); | ||
```bash | ||
npm install imgur | ||
``` | ||
## Contributors | ||
|
||
- Helge S. Holm (https://github.com/deestan) | ||
- Nicolas Bevacqua (https://github.com/bevacqua) | ||
### Usage | ||
|
||
```javascript | ||
var imgur = require('imgur'); | ||
|
||
// Set a Client ID for your app | ||
imgur.setClientId('aCs53GSs4tga0ikp'); | ||
|
||
// Methods return promises | ||
imgur.uploadFile('/home/kai/*.png') | ||
.then(function(json) { | ||
console.log(json.data.link); | ||
}) | ||
.catch(function(err) { | ||
console.error(err.message); | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/usr/bin/env node | ||
var imgur = require('./lib/imgur.js'); | ||
var commander = require('commander'); | ||
var util = require('util'); | ||
|
||
// Used to collect args for specific options | ||
function collect (val, arr) { | ||
arr.push(val); | ||
return arr; | ||
} | ||
|
||
commander | ||
.version(imgur.VERSION) | ||
.option('-i, --info [id ...]', 'Lookup images by ID', collect, []) | ||
.option('-b, --base64 [string ...]', 'Upload a base64-encoded images', collect, []) | ||
.option('-u, --url [url ...]', 'Upload URLs', collect, []) | ||
.option('-f, --file [file ...]', 'Upload binary image files', collect, []) | ||
.parse(process.argv); | ||
|
||
if (commander.info.length) { | ||
commander.info.forEach(function(id, index, array) { | ||
imgur.info(id) | ||
.then(function (json) { | ||
console.log(json.data); | ||
}) | ||
.catch(function (err) { | ||
console.error(err.message); | ||
}); | ||
}); | ||
} | ||
|
||
|
||
if (commander.url.length) { | ||
commander.url.forEach(function(url, index, array) { | ||
imgur.uploadUrl(url) | ||
.then(function (json) { | ||
var output; | ||
if (commander.url.length > 1) { | ||
output = util.format('%s -> %s', url, json.data.link); | ||
} else { | ||
output = json.data.link; | ||
} | ||
console.log(output); | ||
}) | ||
.catch(function (err) { | ||
console.error(err.message); | ||
}); | ||
}); | ||
} | ||
|
||
|
||
if (commander.base64.length) { | ||
commander.base64.forEach(function(str, index, array) { | ||
imgur.uploadBase64(str) | ||
.then(function (json) { | ||
var output; | ||
if (commander.base64.length > 1) { | ||
output = util.format('%s... -> %s', str.substr(0, 7), json.data.link); | ||
} else { | ||
output = json.data.link; | ||
} | ||
console.log(output); | ||
}) | ||
.catch(function (err) { | ||
console.error(err.message); | ||
}); | ||
}); | ||
} | ||
|
||
|
||
if (commander.file.length || commander.args.length) { | ||
var args = commander.file.concat(commander.args); | ||
args.forEach(function(file, index, array) { | ||
imgur.uploadFile(file) | ||
.then(function (json) { | ||
var output; | ||
if (args.length > 1) { | ||
output = util.format('%s -> %s', file, json.data.link); | ||
} else { | ||
output = json.data.link; | ||
} | ||
console.log(output); | ||
}) | ||
.catch(function (err) { | ||
console.error(err.message); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.