Skip to content

Instantly share code, notes, and snippets.

@oonsamyi
Created April 20, 2017 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oonsamyi/282a1a375c2ca2387bd03d390dd3c070 to your computer and use it in GitHub Desktop.
Save oonsamyi/282a1a375c2ca2387bd03d390dd3c070 to your computer and use it in GitHub Desktop.
/* flow */
import type {
ClientMisResponse,
VisitsMisResponse,
ServicesMisResponse,
} from '../types/MISResponse';
export type MISResponse = ClientMisResponse | VisitsMisResponse | ServicesMisResponse;
export type ClientBodyRequest = { barcode: number };
export type ClientInfoBodyRequest = { id: string };
export type BodyRequest = ClientBodyRequest | ClientInfoBodyRequest;
export type MethodName = 'get_client_by_barcode' | 'get_visits_by_userid' | 'get_services_by_userid';
export type SendRequest = (url: string, body: BodyRequest) => Promise<MISResponse>;
export default class MisApi {
constructor(sendRequest: SendRequest) {
Object.defineProperty(this, 'sendRequest', {
value: sendRequest,
enumerable: true,
});
}
async callMethod(methodName: MethodName, body: BodyRequest): MISResponse {
return this.sendRequest(
`https://example.com/${methodName}`, body,
);
}
getClientByBarcode(body: ClientBodyRequest): ClientMisResponse {
return this.callMethod('get_client_by_barcode', body);
}
getVisitsByUserId(body: ClientInfoBodyRequest): VisitsMisResponse {
return this.callMethod('get_visits_by_userid', body);
}
getServicesByUserId(body: ClientInfoBodyRequest): ServicesMisResponse {
return this.callMethod('get_services_by_userid', body);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment