Permalink
Browse files

imgur service working

  • Loading branch information...
lfkwtz committed Nov 1, 2016
1 parent 7691994 commit 075129eba5dbdffbd38e482ab755b50c81ba1091
Showing with 74 additions and 1 deletion.
  1. +3 −1 app.js
  2. 0 config/db.js
  3. 0 models/history.js
  4. +24 −0 npm-debug.log
  5. +19 −0 routes/index.js
  6. +28 −0 services/imgur.js
View
4 app.js
@@ -1,8 +1,10 @@
const express = require('express');
const app = express();
const routes = require('./routes/index');
app.use('/', routes);
const port = process.env.PORT || 3000;
const server = app.listen(port, function() {
const server = app.listen(port, () => {
console.log(`Server listening on port ${port}`);
});
View
No changes.
View
No changes.
View
@@ -0,0 +1,24 @@
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ]
2 info using npm@3.10.8
3 info using node@v7.0.0
4 verbose stack Error: missing script: start
4 verbose stack at run (/usr/local/lib/node_modules/npm/lib/run-script.js:151:19)
4 verbose stack at /usr/local/lib/node_modules/npm/lib/run-script.js:61:5
4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:356:5
4 verbose stack at checkBinReferences_ (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:320:45)
4 verbose stack at final (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:354:3)
4 verbose stack at then (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:124:5)
4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:311:12
4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16
4 verbose stack at tryToString (fs.js:425:3)
4 verbose stack at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:412:12)
5 verbose cwd /Users/michaellefkowitz/Code/projects/image-search-microservice
6 error Darwin 16.0.0
7 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
8 error node v7.0.0
9 error npm v3.10.8
10 error missing script: start
11 error If you need help, you may report this error at:
11 error <https://github.com/npm/npm/issues>
12 verbose exit [ 1, true ]
View
@@ -0,0 +1,19 @@
const express = require('express');
const router = express.Router();
const imgur = require('../services/imgur');
router.get('/', (req, res) => {
res.send('Hello');
});
router.get('/latest', (req, res) => {
});
router.get('/search/:q', (req, res) => {
imgur.getImage(req.params.q, req.query.offset).then(ans => {
res.json(ans);
})
});
module.exports = router;
View
@@ -0,0 +1,28 @@
const request = require('request');
exports.getImage = function(search, page = 1) {
return new Promise((resolve, reject) => {
let options = {
url: `https://api.imgur.com/3/gallery/search/${page}?q=${search}`,
headers: { Authorization: 'Client-ID c9a6b4a5661c706' },
json: true,
};
function getPics(err, response, body) {
if (!err && response.statusCode == 200) {
body = body.data.filter(image => {
if (!image.is_album) {
return image;
}
}).map(image => {
return {
url: image.link,
snippet: image.title,
context: `https://imgur.com/${image.id}`
};
});
resolve(body)
}
}
request(options, getPics);
});
};

0 comments on commit 075129e

Please sign in to comment.