diff options
Diffstat (limited to 'src/client/apis/hypothesis/HypothesisApiUtils.ts')
-rw-r--r-- | src/client/apis/hypothesis/HypothesisApiUtils.ts | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/client/apis/hypothesis/HypothesisApiUtils.ts b/src/client/apis/hypothesis/HypothesisApiUtils.ts index fe35f5831..ab83630a9 100644 --- a/src/client/apis/hypothesis/HypothesisApiUtils.ts +++ b/src/client/apis/hypothesis/HypothesisApiUtils.ts @@ -14,7 +14,7 @@ export namespace Hypothesis { * Searches for annotations made by @param username that * contain @param searchKeyWord */ - export const searchAnnotation = async (username: String, searchKeyWord: String) => { + export const searchAnnotation = async (username: string, searchKeyWord: string) => { const base = 'https://api.hypothes.is/api/search'; const request = base + `?user=acct:${username}@hypothes.is&text=${searchKeyWord}`; console.log("DASH Querying " + request); @@ -26,6 +26,19 @@ export namespace Hypothesis { } }; + export const fetchUser = async (apiKey: string) => { + const response = await fetch('https://api.hypothes.is/api/profile', { + headers: { + 'Authorization': `Bearer ${apiKey}`, + }, + }); + if (response.ok) { + return response.json(); + } else { + throw new Error('DASH: Error in fetchUser GET request'); + } + }; + // Find the most recent placeholder annotation created, and return its ID export const getPlaceholderId = async (username: String, searchKeyWord: String) => { const getResponse = await Hypothesis.searchAnnotation(username, searchKeyWord); @@ -54,9 +67,9 @@ export namespace Hypothesis { return `https://hyp.is/${annotationId}/${baseUrl}`; }; - // export const checkValidApiKey = async (apiKey: string) => { - // const response = await fetch("https://api.hypothes.is/api/profile", { - - // }); - // }; + // Extract username from Hypothe.is's userId format + export const extractUsername = (userid: string) => { + const exp: RegExp = /(?<=\:)(.*?)(?=\@)/; + return exp.exec(userid)![0]; + }; }
\ No newline at end of file |