From 795ba089207571ec13226f2d07c149c8697763ce Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Tue, 27 Oct 2020 19:31:39 -0400 Subject: done (#81) --- src/services/SocialLinkingService.ts | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'src/services/SocialLinkingService.ts') diff --git a/src/services/SocialLinkingService.ts b/src/services/SocialLinkingService.ts index 8d67d90e..c9ffcedf 100644 --- a/src/services/SocialLinkingService.ts +++ b/src/services/SocialLinkingService.ts @@ -20,21 +20,50 @@ export const integratedEndpoints: {[social: string]: [string, string]} = { Twitter: [LINK_TWITTER_OAUTH, LINK_TWITTER_ENDPOINT], }; -export const nonIntegratedEndponits: {[social: string]: string} = { +export const nonIntegratedEndpoints: {[social: string]: string} = { Snapchat: LINK_SNAPCHAT_ENDPOINT, TikTok: LINK_TIKTOK_ENDPOINT, }; +export const getNonIntegratedURL: ( + socialType: string, + userId: string, +) => Promise = async (socialType, userId) => { + if (!(socialType in nonIntegratedEndpoints)) { + return ''; + } + try { + const userToken = await AsyncStorage.getItem('token'); + const response = await fetch( + nonIntegratedEndpoints[socialType] + userId + '/', + { + method: 'GET', + headers: { + Authorization: `Token ${userToken}`, + }, + }, + ); + if (response.status !== 200) { + throw 'Unable to fetch profile URL:' + socialType; + } + const body = await response.json(); + return body.url || ''; + } catch (error) { + console.log(error); + return ''; + } +}; + export const registerNonIntegratedSocialLink: ( socialType: string, username: string, ) => Promise = async (socialType, username) => { - if (!(socialType in nonIntegratedEndponits)) { + if (!(socialType in nonIntegratedEndpoints)) { return false; } try { const user_token = await AsyncStorage.getItem('token'); - const response = await fetch(nonIntegratedEndponits[socialType], { + const response = await fetch(nonIntegratedEndpoints[socialType], { method: 'POST', headers: { Authorization: `Token ${user_token}`, -- cgit v1.2.3-70-g09d2