-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from amansinghbais/gitbook-api
Implemented: centralized services for Gitbook api calls
- Loading branch information
Showing
4 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import api, {client} from "../../api"; | ||
import { hasError } from "../../util"; | ||
|
||
async function askQuery(payload: any): Promise<any> { | ||
try { | ||
const resp = await client({ | ||
url: `spaces/${payload.spaceId}/search/ask`, | ||
method: "post", | ||
baseURL: payload.baseURL, | ||
data: { | ||
"query": payload.queryString | ||
}, | ||
headers: { | ||
Authorization: 'Bearer ' + payload.token, | ||
"Content-Type": "application/json" | ||
} | ||
}) as any; | ||
|
||
if (!hasError(resp)) { | ||
return Promise.resolve(resp) | ||
} else { | ||
throw resp.data; | ||
} | ||
} catch (err) { | ||
return Promise.reject({ | ||
code: 'error', | ||
message: 'Something went wrong', | ||
serverResponse: err | ||
}) | ||
} | ||
} | ||
|
||
async function getGitBookPage(payload: any): Promise<any> { | ||
try { | ||
const resp = await client({ | ||
url: `spaces/${payload.spaceId}/content/page/${payload.pageId}`, | ||
method: "get", | ||
baseURL: payload.baseURL, | ||
headers: { | ||
Authorization: 'Bearer ' + payload.token, | ||
"Content-Type": "application/json" | ||
} | ||
}) as any; | ||
|
||
if (!hasError(resp)) { | ||
return Promise.resolve(resp) | ||
} else { | ||
throw resp.data; | ||
} | ||
} catch (err) { | ||
return Promise.reject({ | ||
code: 'error', | ||
message: 'Something went wrong', | ||
serverResponse: err | ||
}) | ||
} | ||
} | ||
|
||
async function searchQuery(payload: any): Promise<any> { | ||
try { | ||
const resp = await client({ | ||
url: `spaces/${payload.spaceId}/search`, | ||
method: "get", | ||
baseURL: payload.baseURL, | ||
params: { | ||
"query": payload.queryString | ||
}, | ||
headers: { | ||
Authorization: 'Bearer ' + payload.token, | ||
"Content-Type": "application/json" | ||
} | ||
}) as any; | ||
|
||
if (!hasError(resp)) { | ||
return Promise.resolve(resp) | ||
} else { | ||
throw resp.data; | ||
} | ||
} catch (err) { | ||
return Promise.reject({ | ||
code: 'error', | ||
message: 'Something went wrong', | ||
serverResponse: err | ||
}) | ||
} | ||
} | ||
|
||
export { | ||
askQuery, | ||
getGitBookPage, | ||
searchQuery | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters