|
328 | 328 | } |
329 | 329 |
|
330 | 330 | class SlicingDice{ |
331 | | - constructor(key) { |
| 331 | + constructor(key, usesTestEndpoint = false) { |
332 | 332 | this._key = key; |
333 | 333 | this._checkKey(key); |
334 | 334 | this._sdRoutes = { |
|
346 | 346 | project: '/project/' |
347 | 347 | }; |
348 | 348 | this._setUpRequest(); |
| 349 | + this._usesTestEndpoint = usesTestEndpoint; |
349 | 350 | } |
350 | 351 |
|
351 | 352 | get sdAddress() { |
|
407 | 408 | return currentLevelKey[0]; |
408 | 409 | } |
409 | 410 |
|
410 | | - /* Make request to Slicing Dice API, if objRequest.test is true |
| 411 | + /* Make request to Slicing Dice API, if this._usesTestEndpoint is true |
411 | 412 | the request will be sent to test end-point |
412 | 413 | */ |
413 | 414 | makeRequest(objRequest) { |
414 | 415 | let token = this._getAPIKey(objRequest.levelKey); |
415 | 416 | let urlReq; |
416 | 417 | // test if the request must be sent to test endpoint |
417 | | - if (objRequest.test){ |
| 418 | + if (this._usesTestEndpoint){ |
418 | 419 | urlReq = this.BASE_URL + "/test" + objRequest.path; |
419 | 420 | } else { |
420 | 421 | urlReq = this.BASE_URL + objRequest.path; |
|
436 | 437 | }, (err) => { return err;}); |
437 | 438 | } |
438 | 439 |
|
439 | | - /* Get all projects |
440 | | - * |
441 | | - * @param (boolean) test - if true we will use test end-point, |
442 | | - * otherwise production end-point |
443 | | - */ |
444 | | - getProjects(test = false){ |
| 440 | + /* Get all projects */ |
| 441 | + getProjects(){ |
445 | 442 | let path = this._sdRoutes.project; |
446 | 443 | return this.makeRequest({ |
447 | 444 | path: path, |
448 | 445 | reqType: "GET", |
449 | | - levelKey: 2, |
450 | | - test: test |
| 446 | + levelKey: 2 |
451 | 447 | }); |
452 | 448 | } |
453 | 449 |
|
454 | | - /* Get all fields |
455 | | - * |
456 | | - * @param (boolean) test - if is true we will use test end-point, |
457 | | - * otherwise production end-point |
458 | | - */ |
459 | | - getFields(test = false){ |
| 450 | + /* Get all fields */ |
| 451 | + getFields(){ |
460 | 452 | let path = this._sdRoutes.field; |
461 | 453 | return this.makeRequest({ |
462 | 454 | path: path, |
463 | 455 | reqType: "GET", |
464 | | - levelKey: 2, |
465 | | - test: test |
| 456 | + levelKey: 2 |
466 | 457 | }); |
467 | 458 | } |
468 | 459 |
|
469 | | - /* Get all saved queries |
470 | | - * |
471 | | - * @param (boolean) test - if is true we will use test end-point, |
472 | | - * otherwise production end-point |
473 | | - */ |
474 | | - getSavedQueries(test = false) { |
| 460 | + /* Get all saved queries */ |
| 461 | + getSavedQueries() { |
475 | 462 | let path = this._sdRoutes.saved; |
476 | 463 | return this.makeRequest({ |
477 | 464 | path: path, |
478 | 465 | reqType: "GET", |
479 | | - levelKey: 2, |
480 | | - test: test |
| 466 | + levelKey: 2 |
481 | 467 | }); |
482 | 468 | } |
483 | 469 |
|
484 | 470 | /* Delete a saved query |
485 | 471 | * |
486 | 472 | * @param (string) name - the name of the saved query that will be deleted |
487 | | - * @param (boolean) test - if is true we will use test end-point, |
488 | | - * otherwise production end-point |
489 | 473 | */ |
490 | | - deleteSavedQuery(name, test = false) { |
| 474 | + deleteSavedQuery(name) { |
491 | 475 | let path = this._sdRoutes.saved + name; |
492 | 476 | return this.makeRequest({ |
493 | 477 | path: path, |
494 | 478 | reqType: "DELETE", |
495 | | - levelKey: 2, |
496 | | - teste: test |
| 479 | + levelKey: 2 |
497 | 480 | }); |
498 | 481 | } |
499 | 482 |
|
500 | 483 | /* Get saved query by name |
501 | 484 | * |
502 | 485 | * @param (string) name - the name of the saved query that will be retrieved |
503 | | - * @param (boolean) test - if is true we will use test end-point, |
504 | | - * otherwise production end-point |
505 | 486 | */ |
506 | | - getSavedQuery(name, test = false) { |
| 487 | + getSavedQuery(name) { |
507 | 488 | let path = this._sdRoutes.saved + name; |
508 | 489 | return this.makeRequest({ |
509 | 490 | path: path, |
510 | 491 | reqType: "GET", |
511 | | - levelKey: 0, |
512 | | - test: test, |
| 492 | + levelKey: 0 |
513 | 493 | }); |
514 | 494 | } |
515 | 495 |
|
|
518 | 498 | * @param (array) query - the query to send to Slicing Dice API |
519 | 499 | * @param (boolean) autoCreateFields - if is true Slicing Dice API will |
520 | 500 | * automatically create nonexistent fields |
521 | | - * @param (boolean) test - if is true we will use test end-point, |
522 | | - * otherwise production end-point |
523 | 501 | */ |
524 | | - index(query, autoCreateFields = false, test = false){ |
| 502 | + index(query, autoCreateFields = false){ |
525 | 503 | if (autoCreateFields){ |
526 | 504 | query["auto-create-fields"] = true |
527 | 505 | } |
|
531 | 509 | path: path, |
532 | 510 | reqType: "POST", |
533 | 511 | data: query, |
534 | | - levelKey: 1, |
535 | | - test: test |
| 512 | + levelKey: 1 |
536 | 513 | }); |
537 | 514 | } |
538 | 515 |
|
539 | 516 | /* Create a field on Slicing Dice API |
540 | 517 | * |
541 | 518 | * @param (array) query - the query to send to Slicing Dice API |
542 | | - * @param (boolean) test - if is true we will use test end-point, |
543 | | - * otherwise production end-point |
544 | 519 | */ |
545 | | - createField(query, test = false){ |
| 520 | + createField(query){ |
546 | 521 | let path = this._sdRoutes.field; |
547 | 522 | let sdValidator = new FieldValidator(query); |
548 | 523 | if (sdValidator.validator()){ |
549 | 524 | return this.makeRequest({ |
550 | 525 | path: path, |
551 | 526 | reqType: "POST", |
552 | 527 | data: query, |
553 | | - levelKey: 1, |
554 | | - test: test |
| 528 | + levelKey: 1 |
555 | 529 | }); |
556 | 530 | } |
557 | 531 | } |
|
560 | 534 | * |
561 | 535 | * @param (array) query - the query to send to Slicing Dice API |
562 | 536 | * @param (string) path - the path to send the query (count entity or count event path) |
563 | | - * @param (boolean) test - if is true we will use test end-point, |
564 | | - * otherwise production end-point |
565 | 537 | */ |
566 | | - countQueryWrapper(query, path, test){ |
| 538 | + countQueryWrapper(query, path){ |
567 | 539 | let sdValidator = new QueryCountValidator(query); |
568 | 540 | if (sdValidator.validator()){ |
569 | 541 | return this.makeRequest({ |
570 | 542 | path: path, |
571 | 543 | reqType: "POST", |
572 | 544 | data: query, |
573 | | - levelKey: 0, |
574 | | - test: test |
| 545 | + levelKey: 0 |
575 | 546 | }); |
576 | 547 | } |
577 | 548 | } |
578 | 549 |
|
579 | 550 | /* Makes a count entity query on Slicing Dice API |
580 | 551 | * |
581 | 552 | * @param (array) query - the query to send to Slicing Dice API |
582 | | - * @param (boolean) test - if is true we will use test end-point, |
583 | | - * otherwise production end-point |
584 | 553 | */ |
585 | | - countEntity(query, test = false){ |
| 554 | + countEntity(query){ |
586 | 555 | let path = this._sdRoutes.countEntity; |
587 | 556 | let sdValidator = new QueryCountValidator(query); |
588 | | - return this.countQueryWrapper(query, path, test); |
| 557 | + return this.countQueryWrapper(query, path); |
589 | 558 | } |
590 | 559 |
|
591 | | - /* Makes a total query on Slicing Dice API |
592 | | - * |
593 | | - * @param (boolean) test - if is true we will use test end-point, |
594 | | - * otherwise production end-point |
595 | | - */ |
596 | | - countEntityTotal(test = false) { |
| 560 | + /* Makes a total query on Slicing Dice API */ |
| 561 | + countEntityTotal() { |
597 | 562 | let path = this._sdRoutes.countEntityTotal; |
598 | 563 | return this.makeRequest({ |
599 | 564 | path: path, |
600 | 565 | reqType: "GET", |
601 | | - levelKey: 0, |
602 | | - test: test |
| 566 | + levelKey: 0 |
603 | 567 | }) |
604 | 568 | } |
605 | 569 |
|
606 | 570 | /* Makes a count event query on Slicing Dice API |
607 | 571 | * |
608 | 572 | * @param (array) query - the query to send to Slicing Dice API |
609 | | - * @param (boolean) test - if is true we will use test end-point, |
610 | | - * otherwise production end-point |
611 | 573 | */ |
612 | | - countEvent(query, test = false){ |
| 574 | + countEvent(query){ |
613 | 575 | let path = this._sdRoutes.countEvent; |
614 | | - return this.countQueryWrapper(query, path, test); |
| 576 | + return this.countQueryWrapper(query, path); |
615 | 577 | } |
616 | 578 |
|
617 | 579 | /* Makes a exists query on Slicing Dice API |
618 | 580 | * |
619 | | - * @param (array) ids - the array of ids to check |
620 | | - * @param (boolean) test - if is true we will use test end-point, |
621 | | - * otherwise production end-point |
| 581 | + * @param (array) ids - the array of ids to check |
622 | 582 | */ |
623 | | - existsEntity(ids, test = false) { |
| 583 | + existsEntity(ids) { |
624 | 584 | if (ids.constructor != Array){ |
625 | 585 | throw new errors.WrongTypeError("This method should receive an array as parameter"); |
626 | 586 | } |
|
635 | 595 | path: path, |
636 | 596 | reqType: "POST", |
637 | 597 | data: query, |
638 | | - levelKey: 0, |
639 | | - test: test |
| 598 | + levelKey: 0 |
640 | 599 | }); |
641 | 600 | } |
642 | 601 |
|
643 | 602 | /* Makes an aggregation query on Slicing Dice API |
644 | 603 | * |
645 | 604 | * @param (array) query - the query to send to Slicing Dice API |
646 | | - * @param (boolean) test - if is true we will use test end-point, |
647 | | - * otherwise production end-point |
648 | 605 | */ |
649 | | - aggregation(query, test = false){ |
| 606 | + aggregation(query){ |
650 | 607 | let path = this._sdRoutes.aggregation; |
651 | 608 | return this.makeRequest({ |
652 | 609 | path: path, |
653 | 610 | reqType: "POST", |
654 | 611 | data: query, |
655 | | - levelKey: 0, |
656 | | - test: test |
| 612 | + levelKey: 0 |
657 | 613 | }); |
658 | 614 | } |
659 | 615 |
|
660 | 616 | /* Makes a top values query on Slicing Dice API |
661 | 617 | * |
662 | 618 | * @param (array) query - the query to send to Slicing Dice API |
663 | | - * @param (boolean) test - if is true we will use test end-point, |
664 | | - * otherwise production end-point |
665 | 619 | */ |
666 | | - topValues(query, test = false) { |
| 620 | + topValues(query) { |
667 | 621 | let path = this._sdRoutes.topValues; |
668 | 622 | let sdValidator = new QueryTopValuesValidator(query); |
669 | 623 | if (sdValidator.validator()){ |
670 | 624 | return this.makeRequest({ |
671 | 625 | path: path, |
672 | 626 | reqType: "POST", |
673 | 627 | data: query, |
674 | | - levelKey: 0, |
675 | | - test: test |
| 628 | + levelKey: 0 |
676 | 629 | }); |
677 | 630 | } |
678 | 631 | } |
679 | 632 |
|
680 | 633 | /* Create a saved query on Slicing Dice API |
681 | 634 | * |
682 | 635 | * @param (array) query - the query to send to Slicing Dice API |
683 | | - * @param (boolean) test - if is true we will use test end-point, |
684 | | - * otherwise production end-point |
685 | 636 | */ |
686 | | - createSavedQuery(query, test) { |
| 637 | + createSavedQuery(query) { |
687 | 638 | let path = this._sdRoutes.saved; |
688 | 639 | let sdValidator = new SavedQueryValidator(query); |
689 | 640 | if (sdValidator.validator()){ |
690 | 641 | return this.makeRequest({ |
691 | 642 | path: path, |
692 | 643 | reqType: "POST", |
693 | 644 | data: query, |
694 | | - levelKey: 2, |
695 | | - test: test |
| 645 | + levelKey: 2 |
696 | 646 | }); |
697 | 647 | } |
698 | 648 | } |
|
701 | 651 | * |
702 | 652 | * @param (string) name - the name of the saved query to update |
703 | 653 | * @param (array) query - the query to send to Slicing Dice API |
704 | | - * @param (boolean) test - if is true we will use test end-point, |
705 | | - * otherwise production end-point |
706 | 654 | */ |
707 | | - updateSavedQuery(name, query, test = false) { |
| 655 | + updateSavedQuery(name, query) { |
708 | 656 | let path = this._sdRoutes.saved + name; |
709 | 657 | return this.makeRequest({ |
710 | 658 | path: path, |
711 | 659 | reqType: "PUT", |
712 | 660 | data: query, |
713 | | - levelKey: 2, |
714 | | - test: test |
| 661 | + levelKey: 2 |
715 | 662 | }); |
716 | 663 | } |
717 | 664 |
|
718 | 665 | /* Makes a data extraction query (result or score) on Slicing Dice API |
719 | 666 | * |
720 | 667 | * @param (array) query - the query to send to Slicing Dice API |
721 | 668 | * @param (string) path - the path to send the query (result or score path) |
722 | | - * @param (boolean) test - if is true we will use test end-point, |
723 | | - * otherwise production end-point |
724 | 669 | */ |
725 | | - dataExtractionWrapper(query, path, test) { |
| 670 | + dataExtractionWrapper(query, path) { |
726 | 671 | let sdValidator = new QueryDataExtractionValidator(query); |
727 | 672 | if (sdValidator.validator()){ |
728 | 673 | return this.makeRequest({ |
729 | 674 | path: path, |
730 | 675 | reqType: "POST", |
731 | 676 | data: query, |
732 | | - levelKey: 0, |
733 | | - test: test |
| 677 | + levelKey: 0 |
734 | 678 | }); |
735 | 679 | } |
736 | 680 | } |
737 | 681 |
|
738 | 682 | /* Makes a result query on Slicing Dice API |
739 | 683 | * |
740 | 684 | * @param (array) query - the query to send to Slicing Dice API |
741 | | - * @param (boolean) test - if is true we will use test end-point, |
742 | | - * otherwise production end-point |
743 | 685 | */ |
744 | | - result(query, test = false) { |
| 686 | + result(query) { |
745 | 687 | let path = this._sdRoutes.result; |
746 | | - return this.dataExtractionWrapper(query, path, test); |
| 688 | + return this.dataExtractionWrapper(query, path); |
747 | 689 | } |
748 | 690 |
|
749 | 691 | /* Makes a score query on Slicing Dice API |
750 | 692 | * |
751 | 693 | * @param (array) query - the query to send to Slicing Dice API |
752 | | - * @param (boolean) test - if is true we will use test end-point, |
753 | | - * otherwise production end-point |
754 | 694 | */ |
755 | | - score(query, test = false) { |
| 695 | + score(query) { |
756 | 696 | let path = this._sdRoutes.score; |
757 | | - return this.dataExtractionWrapper(query, path, test); |
| 697 | + return this.dataExtractionWrapper(query, path); |
758 | 698 | } |
759 | 699 | } |
760 | 700 |
|
|
0 commit comments