aboutsummaryrefslogtreecommitdiff
path: root/src/services/api/api.service.js
diff options
context:
space:
mode:
authortaehoon <th.dev91@gmail.com>2019-05-07 23:27:22 -0400
committertaehoon <th.dev91@gmail.com>2019-05-07 23:27:22 -0400
commit26131266a926c8511d92e3d10aa618af5e94c6e3 (patch)
treeb7f24908c48c157364187824e41ba0791769d093 /src/services/api/api.service.js
parenta54cf47ba504712369574270ff15af23d3d634f9 (diff)
refactor api service functions using new helper
Diffstat (limited to 'src/services/api/api.service.js')
-rw-r--r--src/services/api/api.service.js48
1 files changed, 4 insertions, 44 deletions
diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js
index da44fc54..b7a602b8 100644
--- a/src/services/api/api.service.js
+++ b/src/services/api/api.service.js
@@ -506,62 +506,22 @@ const verifyCredentials = (user) => {
}
const favorite = ({ id, credentials }) => {
- return fetch(MASTODON_FAVORITE_URL(id), {
- headers: authHeaders(credentials),
- method: 'POST'
- })
- .then(response => {
- if (response.ok) {
- return response.json()
- } else {
- throw new Error('Error favoriting post')
- }
- })
+ return promisedRequest({ url: MASTODON_FAVORITE_URL(id), method: 'POST', credentials })
.then((data) => parseStatus(data))
}
const unfavorite = ({ id, credentials }) => {
- return fetch(MASTODON_UNFAVORITE_URL(id), {
- headers: authHeaders(credentials),
- method: 'POST'
- })
- .then(response => {
- if (response.ok) {
- return response.json()
- } else {
- throw new Error('Error removing favorite')
- }
- })
+ return promisedRequest({ url: MASTODON_UNFAVORITE_URL(id), method: 'POST', credentials })
.then((data) => parseStatus(data))
}
const retweet = ({ id, credentials }) => {
- return fetch(MASTODON_RETWEET_URL(id), {
- headers: authHeaders(credentials),
- method: 'POST'
- })
- .then(response => {
- if (response.ok) {
- return response.json()
- } else {
- throw new Error('Error repeating post')
- }
- })
+ return promisedRequest({ url: MASTODON_RETWEET_URL(id), method: 'POST', credentials })
.then((data) => parseStatus(data))
}
const unretweet = ({ id, credentials }) => {
- return fetch(MASTODON_UNRETWEET_URL(id), {
- headers: authHeaders(credentials),
- method: 'POST'
- })
- .then(response => {
- if (response.ok) {
- return response.json()
- } else {
- throw new Error('Error removing repeat')
- }
- })
+ return promisedRequest({ url: MASTODON_UNRETWEET_URL(id), method: 'POST', credentials })
.then((data) => parseStatus(data))
}