From aa23c1f7110372ee5e2f1c469ce7f1a3ed005cee Mon Sep 17 00:00:00 2001 From: Henrique Schreiner Date: Sat, 27 May 2017 21:25:17 -0300 Subject: [PATCH] Removed class instance for a pure function. --- src/endpoints/blog.js | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/endpoints/blog.js b/src/endpoints/blog.js index f07b59f..f8ead56 100644 --- a/src/endpoints/blog.js +++ b/src/endpoints/blog.js @@ -1,33 +1,28 @@ import errorHandler from '../helpers/errorHandler' -class Blog { +const Blog = (api = null) => { - constructor(api = null) { + if (api === null) throw new Error('Request instance must be provided on constructor.') - if (api === null) throw new Error('Request instance must be provided on constructor.') + return { + getAllBlogs(params) { - this.api = api - } - - getAllBlogs(params) { - - return this.api.get('content/api/v2/blogs', { ...params }) - .then(response => response) - .catch(error => errorHandler(error)) - } - - getPosts(params) { - - return this.api.get('content/api/v2/blog-posts', { ...params }) - .then(response => response) - .catch(error => errorHandler(error)) - } + return api.get('content/api/v2/blogs', { ...params }) + .then(response => response) + .catch(error => errorHandler(error)) + }, + getPosts(params) { - getPostById(postId) { + return api.get('content/api/v2/blog-posts', { ...params }) + .then(response => response) + .catch(error => errorHandler(error)) + }, + getPostById(postId) { - return this.api.get(`content/api/v2/blog-posts/${postId}`) - .then(response => response) - .catch(error => errorHandler(error)) + return api.get(`content/api/v2/blog-posts/${postId}`) + .then(response => response) + .catch(error => errorHandler(error)) + }, } }