Skip to content

Commit

Permalink
Pinterest api now uses axios
Browse files Browse the repository at this point in the history
  • Loading branch information
FX-Wood committed Apr 23, 2019
1 parent c522073 commit 35c8b89
Showing 1 changed file with 1 addition and 42 deletions.
43 changes: 1 addition & 42 deletions controllers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,17 +639,6 @@ exports.postFileUpload = (req, res) => {
* GET /api/pinterest
* Pinterest API example.
*/
// exports.getPinterest = (req, res, next) => {
// const token = req.user.tokens.find(token => token.kind === 'pinterest');
// request.get({ url: 'https://api.pinterest.com/v1/me/boards/', qs: { access_token: token.accessToken }, json: true }, (err, request, body) => {
// if (err) { return next(err); }
// console.log(body.data)
// res.render('api/pinterest', {
// title: 'Pinterest API',
// boards: body.data
// });
// });
// };
exports.getPinterest = (req, res, next) => {
const token = req.user.tokens.find(token => token.kind === 'pinterest');
axios.get(`https://api.pinterest.com/v1/me/boards?access_token=${token.accessToken}`)
Expand All @@ -667,36 +656,6 @@ exports.getPinterest = (req, res, next) => {
* POST /api/pinterest
* Create a pin.
*/
// exports.postPinterest = (req, res, next) => {
// req.assert('board', 'Board is required.').notEmpty();
// req.assert('note', 'Note cannot be blank.').notEmpty();
// req.assert('image_url', 'Image URL cannot be blank.').notEmpty();

// const errors = req.validationErrors();

// if (errors) {
// req.flash('errors', errors);
// return res.redirect('/api/pinterest');
// }

// const token = req.user.tokens.find(token => token.kind === 'pinterest');
// const formData = {
// board: req.body.board,
// note: req.body.note,
// link: req.body.link,
// image_url: req.body.image_url
// };

// request.post('https://api.pinterest.com/v1/pins/', { qs: { access_token: token.accessToken }, form: formData }, (err, request, body) => {
// if (err) { return next(err); }
// if (request.statusCode !== 201) {
// req.flash('errors', { msg: JSON.parse(body).message });
// return res.redirect('/api/pinterest');
// }
// req.flash('success', { msg: 'Pin created' });
// res.redirect('/api/pinterest');
// });
// };
exports.postPinterest = (req, res, next) => {
req.assert('board', 'Board is required.').notEmpty();
req.assert('note', 'Note cannot be blank').notEmpty();
Expand All @@ -717,7 +676,7 @@ exports.postPinterest = (req, res, next) => {
image_url: req.body.image_url
};

axios.post(`https://api.pinterest.com/v1/me/boards/?access_token=${token.accessToken}`, formData)
axios.post(`https://api.pinterest.com/v1/pins/?access_token=${token.accessToken}`, formData)
.then(response => {
req.flash('success', { msg: 'Pin created'});
res.redirect('/api/pinterest');
Expand Down

0 comments on commit 35c8b89

Please sign in to comment.