From cea6ea42f0f882864e01f79a8af08c8bc59272fb Mon Sep 17 00:00:00 2001
From: taehoon
Date: Wed, 20 Mar 2019 11:45:19 -0400
Subject: add api service function
---
src/services/api/api.service.js | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
(limited to 'src/services/api/api.service.js')
diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js
index c5e2280d..9753049f 100644
--- a/src/services/api/api.service.js
+++ b/src/services/api/api.service.js
@@ -50,6 +50,7 @@ const MASTODON_MEDIA_UPLOAD_URL = '/api/v1/media'
const MASTODON_STATUS_FAVORITEDBY_URL = id => `/api/v1/statuses/${id}/favourited_by`
const MASTODON_STATUS_REBLOGGEDBY_URL = id => `/api/v1/statuses/${id}/reblogged_by`
const MASTODON_PROFILE_UPDATE_URL = '/api/v1/accounts/update_credentials'
+const MASTODON_REPORT_USER_URL = 'api/v1/reports'
import { each, map, concat, last } from 'lodash'
import { parseStatus, parseUser, parseNotification, parseAttachment } from '../entity_normalizer/entity_normalizer.service.js'
@@ -722,6 +723,24 @@ const fetchRebloggedByUsers = ({id}) => {
return promisedRequest(MASTODON_STATUS_REBLOGGEDBY_URL(id)).then((users) => users.map(parseUser))
}
+const reportUser = ({credentials, userId, statusIds, comment, forward}) => {
+ const payload = {
+ 'account_id': userId,
+ 'status_ids': statusIds,
+ comment,
+ forward
+ }
+ return fetch(MASTODON_REPORT_USER_URL, {
+ body: JSON.stringify(payload),
+ headers: {
+ ...authHeaders(credentials),
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json'
+ },
+ method: 'POST'
+ }).then((data) => data.json())
+}
+
const apiService = {
verifyCredentials,
fetchTimeline,
@@ -773,7 +792,8 @@ const apiService = {
suggestions,
markNotificationsAsSeen,
fetchFavoritedByUsers,
- fetchRebloggedByUsers
+ fetchRebloggedByUsers,
+ reportUser
}
export default apiService
--
cgit v1.2.3-70-g09d2
From 02d169b92c61015a5663b703a23e769848239b13 Mon Sep 17 00:00:00 2001
From: taehoon
Date: Wed, 20 Mar 2019 11:54:16 -0400
Subject: add promisedRequest helper
---
src/services/api/api.service.js | 24 ++++++++++--------------
1 file changed, 10 insertions(+), 14 deletions(-)
(limited to 'src/services/api/api.service.js')
diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js
index 9753049f..a19aff9f 100644
--- a/src/services/api/api.service.js
+++ b/src/services/api/api.service.js
@@ -724,21 +724,17 @@ const fetchRebloggedByUsers = ({id}) => {
}
const reportUser = ({credentials, userId, statusIds, comment, forward}) => {
- const payload = {
- 'account_id': userId,
- 'status_ids': statusIds,
- comment,
- forward
- }
- return fetch(MASTODON_REPORT_USER_URL, {
- body: JSON.stringify(payload),
- headers: {
- ...authHeaders(credentials),
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
+ return promisedRequest({
+ uri: MASTODON_REPORT_USER_URL,
+ method: 'POST',
+ payload: {
+ 'account_id': userId,
+ 'status_ids': statusIds,
+ comment,
+ forward
},
- method: 'POST'
- }).then((data) => data.json())
+ credentials
+ })
}
const apiService = {
--
cgit v1.2.3-70-g09d2
From 2e6eab51b8272e3136046544f195253ec6c5841c Mon Sep 17 00:00:00 2001
From: taehoon
Date: Sun, 24 Mar 2019 21:35:34 -0400
Subject: Update promisedRequest helper to support json payload
---
src/services/api/api.service.js | 37 ++++++++++++++++++++++++-------------
1 file changed, 24 insertions(+), 13 deletions(-)
(limited to 'src/services/api/api.service.js')
diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js
index a19aff9f..15c4b62a 100644
--- a/src/services/api/api.service.js
+++ b/src/services/api/api.service.js
@@ -67,7 +67,24 @@ let fetch = (url, options) => {
return oldfetch(fullUrl, options)
}
-const promisedRequest = (url, options) => {
+const promisedRequest = ({ method, url, payload, credentials, headers = {} }) => {
+ const options = {
+ method,
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json',
+ ...headers
+ }
+ }
+ if (payload) {
+ options.body = JSON.stringify(payload)
+ }
+ if (credentials) {
+ options.headers = {
+ ...options.headers,
+ ...authHeaders(credentials)
+ }
+ }
return fetch(url, options)
.then((response) => {
return new Promise((resolve, reject) => response.json()
@@ -228,7 +245,7 @@ const denyUser = ({id, credentials}) => {
const fetchUser = ({id, credentials}) => {
let url = `${MASTODON_USER_URL}/${id}`
- return promisedRequest(url, { headers: authHeaders(credentials) })
+ return promisedRequest({ url, credentials })
.then((data) => parseUser(data))
}
@@ -652,26 +669,20 @@ const changePassword = ({credentials, password, newPassword, newPasswordConfirma
}
const fetchMutes = ({credentials}) => {
- return promisedRequest(MASTODON_USER_MUTES_URL, { headers: authHeaders(credentials) })
+ return promisedRequest({ url: MASTODON_USER_MUTES_URL, credentials })
.then((users) => users.map(parseUser))
}
const muteUser = ({id, credentials}) => {
- return promisedRequest(MASTODON_MUTE_USER_URL(id), {
- headers: authHeaders(credentials),
- method: 'POST'
- })
+ return promisedRequest({ url: MASTODON_MUTE_USER_URL(id), credentials, method: 'POST' })
}
const unmuteUser = ({id, credentials}) => {
- return promisedRequest(MASTODON_UNMUTE_USER_URL(id), {
- headers: authHeaders(credentials),
- method: 'POST'
- })
+ return promisedRequest({ url: MASTODON_UNMUTE_USER_URL(id), credentials, method: 'POST' })
}
const fetchBlocks = ({credentials}) => {
- return promisedRequest(MASTODON_USER_BLOCKS_URL, { headers: authHeaders(credentials) })
+ return promisedRequest({ url: MASTODON_USER_BLOCKS_URL, credentials })
.then((users) => users.map(parseUser))
}
@@ -725,7 +736,7 @@ const fetchRebloggedByUsers = ({id}) => {
const reportUser = ({credentials, userId, statusIds, comment, forward}) => {
return promisedRequest({
- uri: MASTODON_REPORT_USER_URL,
+ url: MASTODON_REPORT_USER_URL,
method: 'POST',
payload: {
'account_id': userId,
--
cgit v1.2.3-70-g09d2
From 19a04769858c6786826a546bd5c0d3876049bad2 Mon Sep 17 00:00:00 2001
From: taehoon
Date: Wed, 24 Apr 2019 22:40:37 -0400
Subject: update api endpoint url
---
src/services/api/api.service.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'src/services/api/api.service.js')
diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js
index 15c4b62a..846fab3a 100644
--- a/src/services/api/api.service.js
+++ b/src/services/api/api.service.js
@@ -50,7 +50,7 @@ const MASTODON_MEDIA_UPLOAD_URL = '/api/v1/media'
const MASTODON_STATUS_FAVORITEDBY_URL = id => `/api/v1/statuses/${id}/favourited_by`
const MASTODON_STATUS_REBLOGGEDBY_URL = id => `/api/v1/statuses/${id}/reblogged_by`
const MASTODON_PROFILE_UPDATE_URL = '/api/v1/accounts/update_credentials'
-const MASTODON_REPORT_USER_URL = 'api/v1/reports'
+const MASTODON_REPORT_USER_URL = '/api/v1/reports'
import { each, map, concat, last } from 'lodash'
import { parseStatus, parseUser, parseNotification, parseAttachment } from '../entity_normalizer/entity_normalizer.service.js'
--
cgit v1.2.3-70-g09d2
From 9787d996722e44e6554d936e0995bf4c346207e2 Mon Sep 17 00:00:00 2001
From: taehoon
Date: Tue, 30 Apr 2019 16:38:34 -0400
Subject: update api services
---
src/services/api/api.service.js | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
(limited to 'src/services/api/api.service.js')
diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js
index 846fab3a..da44fc54 100644
--- a/src/services/api/api.service.js
+++ b/src/services/api/api.service.js
@@ -140,14 +140,11 @@ const updateBanner = ({credentials, banner}) => {
}
const updateProfile = ({credentials, params}) => {
- return promisedRequest(MASTODON_PROFILE_UPDATE_URL, {
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- ...authHeaders(credentials)
- },
+ return promisedRequest({
+ url: MASTODON_PROFILE_UPDATE_URL,
method: 'PATCH',
- body: JSON.stringify(params)
+ payload: params,
+ credentials
})
.then((data) => parseUser(data))
}
@@ -727,11 +724,11 @@ const markNotificationsAsSeen = ({id, credentials}) => {
}
const fetchFavoritedByUsers = ({id}) => {
- return promisedRequest(MASTODON_STATUS_FAVORITEDBY_URL(id)).then((users) => users.map(parseUser))
+ return promisedRequest({ url: MASTODON_STATUS_FAVORITEDBY_URL(id) }).then((users) => users.map(parseUser))
}
const fetchRebloggedByUsers = ({id}) => {
- return promisedRequest(MASTODON_STATUS_REBLOGGEDBY_URL(id)).then((users) => users.map(parseUser))
+ return promisedRequest({ url: MASTODON_STATUS_REBLOGGEDBY_URL(id) }).then((users) => users.map(parseUser))
}
const reportUser = ({credentials, userId, statusIds, comment, forward}) => {
--
cgit v1.2.3-70-g09d2