You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

client.ts 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import got, { GotFn } from 'got'
  2. import { RequestOptions } from 'https'
  3. import { IncomingHttpHeaders } from 'http';
  4. export interface Response {
  5. status: {
  6. code?: number,
  7. word?: string,
  8. },
  9. body: any,
  10. headers: IncomingHttpHeaders,
  11. _rawResponse: got.Response<any>, // raw string response
  12. }
  13. export interface Client {
  14. request (method: string, path: string, payload: {}, options: any): Promise<Response>
  15. }
  16. export class PortalClient implements Client {
  17. client: GotFn
  18. constructor (client: GotFn) {
  19. this.client = client
  20. }
  21. async request (method: string, path: string, payload: {}, options: any): Promise<Response> {
  22. const requestOptions = this.constructRequestOptions(method, path, payload, options)
  23. const response = await this.client(requestOptions)
  24. return {
  25. status: {
  26. code: response.statusCode,
  27. word: response.statusMessage,
  28. },
  29. body: response.body,
  30. headers: response.headers,
  31. _rawResponse: response,
  32. }
  33. }
  34. constructRequestOptions (method: string, path: string, payload: {}, options: any): RequestOptions {
  35. return {
  36. // TODO:
  37. }
  38. }
  39. }
  40. export default PortalClient