All files / apis/detector detector.ts

46.15% Statements 6/13
0% Branches 0/2
0% Functions 0/4
46.15% Lines 6/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 651x 1x 1x                 1x 1x                 1x                                                                                      
import { ApiClass } from "../api";
import { formatQuerystring, SimpleJsonHttp, USER_AGENT } from "../shared";
import { DetectorDetectApi } from "./detect.api";
import type { DetectorApiOptions } from "./detector.options";
 
/**
 * API получения ID провайдера QIWI по Номеру Телефона/Карте
 *
 * @export
 * @class Detector
 */
export class Detector extends ApiClass<DetectorApiOptions> {
  static readonly DetectApi = DetectorDetectApi;
 
  /**
   *
   *
   * @static
   * @return {SimpleJsonHttp} {SimpleJsonHttp}
   * @memberof Detector
   */
  static httpClientFactory = (): SimpleJsonHttp => {
    const http = new SimpleJsonHttp();
 
    http.client.options = {
      ...http.client.options,
      stringifyBody: (body) => formatQuerystring(body),
      baseURL: "https://qiwi.com/",
      headers: {
        "Content-Type": "application/x-www-form-urlencoded",
        Accept: "application/json",
        "User-Agent": USER_AGENT
      },
      okStatusCodes: [200],
      timeout: 10_000
    };
 
    return http;
  };
 
  /**
   *
   *
   * @static
   * @return {Detector}  {Detector}
   * @memberof Detector
   */
  static create(): Detector {
    return new this({ http: this.httpClientFactory() });
  }
 
  /**
   * Creates an instance of P2p.
   * @param {P2pApiOptions} [options]
   * @memberof P2p
   */
  constructor({
    http = Detector.httpClientFactory()
  }: Partial<DetectorApiOptions> = {}) {
    super({ http });
  }
 
  readonly detectProvider = new Detector.DetectApi(this._options);
}