2017-09-26 22:54:26 +00:00
|
|
|
import store from '../../store';
|
|
|
|
import wordpressHelper from './helpers/wordpressHelper';
|
2018-04-27 14:37:05 +00:00
|
|
|
import Provider from './common/Provider';
|
2017-09-26 22:54:26 +00:00
|
|
|
|
2018-04-27 14:37:05 +00:00
|
|
|
export default new Provider({
|
2017-09-26 22:54:26 +00:00
|
|
|
id: 'wordpress',
|
|
|
|
getToken(location) {
|
2018-06-21 19:16:33 +00:00
|
|
|
return store.getters['data/wordpressTokensBySub'][location.sub];
|
2017-09-26 22:54:26 +00:00
|
|
|
},
|
2018-07-03 23:41:24 +00:00
|
|
|
getLocationUrl(location) {
|
2017-09-26 22:54:26 +00:00
|
|
|
return `https://wordpress.com/post/${location.siteId}/${location.postId}`;
|
|
|
|
},
|
2018-07-03 23:41:24 +00:00
|
|
|
getLocationDescription({ postId }) {
|
|
|
|
return postId;
|
2017-09-26 22:54:26 +00:00
|
|
|
},
|
2018-05-13 13:27:33 +00:00
|
|
|
async publish(token, html, metadata, publishLocation) {
|
|
|
|
const post = await wordpressHelper.uploadPost({
|
|
|
|
...publishLocation,
|
|
|
|
...metadata,
|
2017-09-26 22:54:26 +00:00
|
|
|
token,
|
2018-05-13 13:27:33 +00:00
|
|
|
content: html,
|
|
|
|
});
|
|
|
|
return {
|
|
|
|
...publishLocation,
|
|
|
|
siteId: `${post.site_ID}`,
|
|
|
|
postId: `${post.ID}`,
|
|
|
|
};
|
2017-09-26 22:54:26 +00:00
|
|
|
},
|
|
|
|
makeLocation(token, domain, postId) {
|
|
|
|
const location = {
|
|
|
|
providerId: this.id,
|
|
|
|
sub: token.sub,
|
|
|
|
domain,
|
|
|
|
};
|
|
|
|
if (postId) {
|
|
|
|
location.postId = postId;
|
|
|
|
}
|
|
|
|
return location;
|
|
|
|
},
|
|
|
|
});
|