<commit_before>/*
 * Copyright 2017 <NAME>, S.A.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { Injectable } from '@angular/core';

import { HttpClient, HttpParams } from '@angular/common/http';

import { ConfigService } from './config.service';
import { Dashboard } from '../model/dashboard';

@Injectable()
export class SlackService {

  constructor(private http: HttpClient, private configService: ConfigService) { }

  signSlack(team:string, clientId:string, clientSecret:string): Promise<any> {
    var dummy: HTMLAnchorElement = document.createElement('a');
    dummy.href = 'utils/slack/code-capturer';

    return new Promise((resolve, reject) =>  {
      var source = window.open(
        `https://slack.com/oauth/authorize?client_id=${clientId}&scope=client&team=${team}`
      );

      var receiver = (msg: MessageEvent) =>  {
        window.removeEventListener("message", receiver, false);
        if(msg.source == source && msg.origin == document.location.origin) {
          this.generateToken(msg.data, team, clientId, clientSecret).subscribe(
            token => resolve(token),
            error => reject(error)
          );
        } else {
          reject('Slack Token could not be generated');
        }
      };
      window.addEventListener("message", receiver, false);
    });
  }

  private generateToken(code:string, team:string, clientId:string, clientSecret:string) {
    let params: HttpParams = new HttpParams()
      .set('code', code)
      .set('team', team)
      .set('clientId', clientId)
      .set('clientSecret', clientSecret);

    return this.http.get(`${this.configService.getConfig('MIRRORGATE_API_URL')}/slack/token-generator`, {
      params: params
    });
  }

  getChannels(dashboard:Dashboard) {
    let params: HttpParams = new HttpParams()
      .set('dashboard', dashboard.name)
      .set('token', dashboard.slackToken);

    return this.http.get(`${this.configService.getConfig('MIRRORGATE_API_URL')}/slack/channels`, {
      params: params
    });
  }

}
<commit_msg>fix(slack): fix get token service call<commit_after>/*
 * Copyright 2017 <NAME>, S.A.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { Injectable } from '@angular/core';

import { HttpClient, HttpParams } from '@angular/common/http';

import { ConfigService } from './config.service';
import { Dashboard } from '../model/dashboard';

@Injectable()
export class SlackService {

  constructor(private http: HttpClient, private configService: ConfigService) { }

  signSlack(team:string, clientId:string, clientSecret:string): Promise<any> {
    var dummy: HTMLAnchorElement = document.createElement('a');
    dummy.href = 'utils/slack/code-capturer';

    return new Promise((resolve, reject) =>  {
      var source = window.open(
        `https://slack.com/oauth/authorize?client_id=${clientId}&scope=client&team=${team}`
      );

      var receiver = (msg: MessageEvent) =>  {
        window.removeEventListener("message", receiver, false);
        if(msg.source == source && msg.origin == document.location.origin) {
          this.generateToken(msg.data, team, clientId, clientSecret).subscribe(
            token => resolve(token),
            error => reject(error)
          );
        } else {
          reject('Slack Token could not be generated');
        }
      };
      window.addEventListener("message", receiver, false);
    });
  }

  private generateToken(code:string, team:string, clientId:string, clientSecret:string) {
    let params: HttpParams = new HttpParams()
      .set('code', code)
      .set('team', team)
      .set('clientId', clientId)
      .set('clientSecret', clientSecret);

    return this.http.get(`${this.configService.getConfig('MIRRORGATE_API_URL')}/slack/token-generator`, {
      params: params,
      responseType: 'text'
    });
  }

  getChannels(dashboard:Dashboard) {
    let params: HttpParams = new HttpParams()
      .set('dashboard', dashboard.name)
      .set('token', dashboard.slackToken);

    return this.http.get(`${this.configService.getConfig('MIRRORGATE_API_URL')}/slack/channels`, {
      params: params
    });
  }

}

{'fraction_non_alphanumeric': 0.13021540849990296, 'fraction_numerical': 0.0031049873859887445, 'mean_word_length': 3.405128205128205, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5709316', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1452, 'n_words': 393}