diff --git a/services/Instagram/src/instagram/Instagram.js b/services/Instagram/src/instagram/Instagram.js index fa7e189c..aaf01524 100644 --- a/services/Instagram/src/instagram/Instagram.js +++ b/services/Instagram/src/instagram/Instagram.js @@ -1,10 +1,12 @@ import Subscription from './Subscription'; import User from './User'; +import Media from './Media'; export default class Instagram { constructor(clientId, clientSecret, accessToken, createApi) { this.clientId = clientId; this.clientSecret = clientSecret; + this.accessToken = accessToken; const authenticatedApi = createApi(clientId, clientSecret, accessToken); const api = createApi(clientId, clientSecret); @@ -12,5 +14,6 @@ export default class Instagram { //noinspection JSUnresolvedVariable this.user = new User(authenticatedApi); this.subscriptions = new Subscription(api); + this.media = new Media(api, accessToken); } } diff --git a/services/Instagram/src/instagram/Media.js b/services/Instagram/src/instagram/Media.js new file mode 100644 index 00000000..54f76677 --- /dev/null +++ b/services/Instagram/src/instagram/Media.js @@ -0,0 +1,7 @@ +import EndPoint from './EndPoint'; + +export default class Media extends EndPoint { + shortname(name){ + return this.request('GET', `/media/shortcode/${name}?access_token=${this.token}`); + } +} diff --git a/services/Instagram/src/routers/index.js b/services/Instagram/src/routers/index.js index 221ba4a8..bc75749b 100644 --- a/services/Instagram/src/routers/index.js +++ b/services/Instagram/src/routers/index.js @@ -8,6 +8,7 @@ import {auth, authCallback, authOut} from './auth'; import {list, addTag, addUser} from './subscription'; import {ensureAuth} from './auth'; import {callbackGet, callbackPost} from './callback'; +import {shortname} from './media'; export function statelessRouters() { return compose([ @@ -25,7 +26,8 @@ export function routers() { user(), list(), addTag(), - addUser() + addUser(), + shortname() ]); } diff --git a/services/Instagram/src/routers/media.js b/services/Instagram/src/routers/media.js new file mode 100644 index 00000000..344d926c --- /dev/null +++ b/services/Instagram/src/routers/media.js @@ -0,0 +1,23 @@ +import compose from 'koa-compose'; +import {get} from './'; +import {ensureAuth} from './auth'; +import {push} from '../core/update'; +import {postFromInstagramMedia} from '../models/post'; + +export function shortname() { + return compose([ + ensureAuth(), + get('/media/shortname/:name', async(ctx, name) => { + const instagram = ctx.instagram; + let result = await instagram.media.shortname(name); + + if(result.meta.code === 200) { + let post = postFromInstagramMedia(result.data); + console.log('SHORTNAME'); + + ctx.set('Content-Type', 'application/json'); + ctx.body = await push(post); + } + }) + ]); +}