+ Instagram Service media endpoint to gram by shorname

This commit is contained in:
tmshv committed 2016-03-26 01:46:02 +03:00
1 parent 1e03cd012a
commit 427de393ed
4 files changed
+36 -1

No files matched your search

@@ -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);
}
}
@@ -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}`);
}
}
+3 -1
View File
@@ -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()
]);
}
+23
View File
@@ -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);
}
})
]);
}