All files / src/apis/detector detector.ts

100% Statements 16/16
100% Branches 2/2
100% Functions 4/4
100% Lines 16/16

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 65 66 67 685x 5x 5x 5x 5x 5x                 5x 5x                 5x 9x   9x   5x                     9x                     6x                     9x     9x    
import { ApiClass } from "../api";
import { SimpleJsonHttp } from "../shared/http";
import { url } from "../shared/url";
import { formatQuerystring } from "../shared/querystring";
import { USER_AGENT } from "../shared/identity";
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: url`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);
}