+ Instagram Service media endpoint to gram by shorname
This commit is contained in:
1 parent
1e03cd012a
commit
427de393ed
4 files changed
+36
-1
No files matched your search
@@ -1,10 +1,12 @@
|
|||||||
import Subscription from './Subscription';
|
import Subscription from './Subscription';
|
||||||
import User from './User';
|
import User from './User';
|
||||||
|
import Media from './Media';
|
||||||
|
|
||||||
export default class Instagram {
|
export default class Instagram {
|
||||||
constructor(clientId, clientSecret, accessToken, createApi) {
|
constructor(clientId, clientSecret, accessToken, createApi) {
|
||||||
this.clientId = clientId;
|
this.clientId = clientId;
|
||||||
this.clientSecret = clientSecret;
|
this.clientSecret = clientSecret;
|
||||||
|
this.accessToken = accessToken;
|
||||||
|
|
||||||
const authenticatedApi = createApi(clientId, clientSecret, accessToken);
|
const authenticatedApi = createApi(clientId, clientSecret, accessToken);
|
||||||
const api = createApi(clientId, clientSecret);
|
const api = createApi(clientId, clientSecret);
|
||||||
@@ -12,5 +14,6 @@ export default class Instagram {
|
|||||||
//noinspection JSUnresolvedVariable
|
//noinspection JSUnresolvedVariable
|
||||||
this.user = new User(authenticatedApi);
|
this.user = new User(authenticatedApi);
|
||||||
this.subscriptions = new Subscription(api);
|
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}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import {auth, authCallback, authOut} from './auth';
|
|||||||
import {list, addTag, addUser} from './subscription';
|
import {list, addTag, addUser} from './subscription';
|
||||||
import {ensureAuth} from './auth';
|
import {ensureAuth} from './auth';
|
||||||
import {callbackGet, callbackPost} from './callback';
|
import {callbackGet, callbackPost} from './callback';
|
||||||
|
import {shortname} from './media';
|
||||||
|
|
||||||
export function statelessRouters() {
|
export function statelessRouters() {
|
||||||
return compose([
|
return compose([
|
||||||
@@ -25,7 +26,8 @@ export function routers() {
|
|||||||
user(),
|
user(),
|
||||||
list(),
|
list(),
|
||||||
addTag(),
|
addTag(),
|
||||||
addUser()
|
addUser(),
|
||||||
|
shortname()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user