Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding share parent endpoint #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions lib/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ const ENDPOINTS = {
getById(id) {
return `/shares/${id}`;
},
getByParentId(id) {
return `/shares/${id}/parent`;
},
recordView(id, uid) {
return {
path: `/shares/${id}/views`,
Expand Down Expand Up @@ -104,7 +107,7 @@ const ENDPOINTS = {
return {
path: `/shares/${id}/featured`,
method: 'PATCH',
body: JSON.stringify({ featured: featured }),
body: JSON.stringify({ featured }),
responseType: 'text',
};
},
Expand All @@ -127,7 +130,7 @@ const ENDPOINTS = {
path: `/shares/${sid}/moderate`,
method: 'POST',
};
}
},
};

function generateAttachmentPath(attachments, key, id) {
Expand All @@ -150,48 +153,56 @@ export class ShareClient extends Client {
super(opts);
this.addEndpoints(ENDPOINTS);
}

feed(limit) {
const endpoint = this.getEndpoint('feed', limit);
return this.fetch(endpoint)
.then(res => res.data)
.then(data => this.afterDataProcessed(endpoint, data));
}

userFeed(id, limit) {
const endpoint = this.getEndpoint('userFeed', id, limit);
return this.fetch(endpoint)
.then(res => res.data)
.then(data => this.afterDataProcessed(endpoint, data));
}

feedByApp(app, limit) {
const endpoint = this.getEndpoint('feedByApp', app, limit);
return this.fetch(endpoint)
.then(res => res.data)
.then(data => this.afterDataProcessed(endpoint, data));
}

feedByHardware(hardware, limit) {
const endpoint = this.getEndpoint('feedByHardware', hardware, limit);
return this.fetch(endpoint)
.then(res => res.data)
.then(data => this.afterDataProcessed(endpoint, data));
}

feedByHardwareFeatured(hardware, featured, limit) {
const endpoint = this.getEndpoint('feedByHardwareFeatured', hardware, featured, limit);
return this.fetch(endpoint)
.then(res => res.data)
.then(data => this.afterDataProcessed(endpoint, data));
}

feedByFollow(uid, limit) {
const endpoint = this.getEndpoint('feedByFollow', uid, limit);
return this.fetch(endpoint)
.then(res => res.data)
.then(data => this.afterDataProcessed(endpoint, data));
}

featured(limit) {
const endpoint = this.getEndpoint('featured', limit);
return this.fetch(endpoint)
.then(res => res.data)
.then(data => this.afterDataProcessed(endpoint, data));
}

getListByIds(ids) {
const endpoint = this.getEndpoint('getShareListByIds', ids);
return this.fetch(endpoint)
Expand All @@ -202,39 +213,53 @@ export class ShareClient extends Client {
)))
.then(data => this.afterDataProcessed(endpoint, data));
}

getById(id) {
const endpoint = this.getEndpoint('getById', id);
return this.fetch(endpoint)
.then(res => expandShare(res.data.share, res.data.atBurl, res.data.aBurl))
.then(data => this.afterDataProcessed(endpoint, data));
}

getByParentId(id) {
const endpoint = this.getEndpoint('getByParentId', id);
return this.fetch(endpoint)
.then(res => expandShare(res.data.share, res.data.atBurl, res.data.aBurl))
.then(data => this.afterDataProcessed(endpoint, data));
}

getBySlug(slug) {
const endpoint = this.getEndpoint('getBySlug', slug);
return this.fetch(endpoint)
.then(res => expandShare(res.data.share, res.data.atBurl, res.data.aBurl))
.then(data => this.afterDataProcessed(endpoint, data));
}

recordView(id, uid) {
const endpoint = this.getEndpoint('recordView', id, uid);
return this.fetch(endpoint)
.then(data => this.afterDataProcessed(endpoint, data));
}

recordLike(id) {
const endpoint = this.getEndpoint('recordLike', id);
return this.fetch(endpoint)
.then(data => this.afterDataProcessed(endpoint, data));
}

deleteLike(id) {
const endpoint = this.getEndpoint('deleteLike', id);
return this.fetch(endpoint)
.then(data => this.afterDataProcessed(endpoint, data));
}

getComments(id) {
const endpoint = this.getEndpoint('getComments', id);
return this.fetch(endpoint)
.then(res => res.data)
.then(data => this.afterDataProcessed(endpoint, data || []));
}

create(data) {
const endpoint = this.getEndpoint('create', data);
return this.fetch(endpoint)
Expand All @@ -258,33 +283,36 @@ export class ShareClient extends Client {
// All attachments are uploaded, trigger the moderation
const moderate = this.getEndpoint('moderate', d.share.id);
return this.fetch(moderate)
.then((moderationData) => {
// Add the moderation data to the response object
return Object.assign(d, { moderation: moderationData.data });
});
// Add the moderation data to the response object
.then(moderationData => Object.assign(d, { moderation: moderationData.data }));
})
.then(d => this.afterDataProcessed(endpoint, d || []));
}

deleteShare(id) {
const endpoint = this.getEndpoint('deleteShare', id);
return this.fetch(endpoint)
.then(data => this.afterDataProcessed(endpoint, data));
}

deleteShareByAdmin(id) {
const endpoint = this.getEndpoint('deleteShareByAdmin', id);
return this.fetch(endpoint)
.then(data => this.afterDataProcessed(endpoint, data));
}

featureShareByAdmin(id, featured) {
const endpoint = this.getEndpoint('featureShareByAdmin', id, featured);
return this.fetch(endpoint)
.then(data => this.afterDataProcessed(endpoint, data));
}

flagShare(id) {
const endpoint = this.getEndpoint('flagShare', id);
return this.fetch(endpoint)
.then(data => this.afterDataProcessed(endpoint, data));
}

unflagShare(id) {
const endpoint = this.getEndpoint('unflagShare', id);
return this.fetch(endpoint)
Expand Down