<commit_before>import { Injectable } from '@angular/core';
import { Http, Headers } from '@angular/http';
import 'rxjs/add/operator/map';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';

import { AuthService } from './../../auth';
import { API_BASE_URL } from './../../app.constants';

@Injectable()
export class LocalesService {

    private _locales = new BehaviorSubject([]);
    public locales = this._locales.asObservable();

    constructor(private http: Http, private auth: AuthService) { }

    createLocale(projectId: number, locale) {
        let request = this.http.post(
            `${API_BASE_URL}/projects/${projectId}/locales`,
            JSON.stringify(locale),
            { headers: this.getApiHeaders() }
        )
            .map(res => res.json())
            .map(res => {
                let locale = res.payload;
                if (!locale) {
                    throw new Error("no locale in response");
                }
                return locale;
            }
            ).share();

        request.subscribe(locale => {
            this._locales.next(this._locales.getValue().concat(locale));
        });

        return request;
    }

    updateLocalePairs(projectId: number, localeIdent: string, pairs) {
        return this.http.patch(
            `${API_BASE_URL}/projects/${projectId}/locales/${localeIdent}/pairs`,
            JSON.stringify(pairs),
            { headers: this.getApiHeaders() }
        )
            .map(res => res.json())
            .map(res => {
                let payload = res.payload;
                if (!payload) {
                    throw new Error("no payload in response");
                }
                return payload;
            }).share();
    }

    fetchLocales(projectId: number) {
        let request = this.http.get(
            `${API_BASE_URL}/projects/${projectId}/locales`,
            { headers: this.getApiHeaders() }
        )
            .map(res => res.json())
            .map(res => {
                let locales = res.payload;
                if (!locales) {
                    throw new Error("no locales in response");
                }
                return locales;
            })
            .share();

        request.subscribe(locales => {
            this._locales.next(locales);
        });

        return request;
    }

    fetchLocale(projectId: number, localeIdent: string) {
        let request = this.http.get(
            `${API_BASE_URL}/projects/${projectId}/locales/${localeIdent}`,
            { headers: this.getApiHeaders() }
        )
            .map(res => res.json())
            .map(res => {
                let locale = res.payload;
                if (!locale) {
                    throw new Error("no locale in response");
                }
                return locale;
            }).share();

        return request;
    }

    private getApiHeaders() {
        let headers = new Headers();
        headers.append('Content-Type', 'application/json');
        headers.append('Authorization', 'Bearer ' + this.auth.getToken());
        return headers;<commit_msg>Conform style<commit_after>import { Injectable } from '@angular/core';
import { Http, Headers } from '@angular/http';
import 'rxjs/add/operator/map';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';

import { AuthService } from './../../auth';
import { API_BASE_URL } from './../../app.constants';

@Injectable()
export class LocalesService {

    private _locales = new BehaviorSubject([]);
    public locales = this._locales.asObservable();

    constructor(private http: Http, private auth: AuthService) { }

    createLocale(projectId: number, locale) {
        let request = this.http.post(
            `${API_BASE_URL}/projects/${projectId}/locales`,
            JSON.stringify(locale),
            { headers: this.getApiHeaders() }
        )
            .map(res => res.json())
            .map(res => {
                let locale = res.payload;
                if (!locale) {
                    throw new Error("no locale in response");
                }
                return locale;
            }
            ).share();

        request.subscribe(locale => {
            this._locales.next(this._locales.getValue().concat(locale));
        });

        return request;
    }

    updateLocalePairs(projectId: number, localeIdent: string, pairs) {
        return this.http.patch(
            `${API_BASE_URL}/projects/${projectId}/locales/${localeIdent}/pairs`,
            JSON.stringify(pairs),
            { headers: this.getApiHeaders() }
        )
            .map(res => res.json())
            .map(res => {
                let payload = res.payload;
                if (!payload) {
                    throw new Error("no payload in response");
                }
                return payload;
            }).share();
    }

    fetchLocales(projectId: number) {
        let request = this.http.get(
            `${API_BASE_URL}/projects/${projectId}/locales`,
            { headers: this.getApiHeaders() }
        )
            .map(res => res.json())
            .map(res => {
                let locales = res.payload;
                if (!locales) {
                    throw new Error("no locales in response");
                }
                return locales;
            }).share();

        request.subscribe(locales => {
            this._locales.next(locales);
        });

        return request;
    }

    fetchLocale(projectId: number, localeIdent: string) {
        let request = this.http.get(
            `${API_BASE_URL}/projects/${projectId}/locales/${localeIdent}`,
            { headers: this.getApiHeaders() }
        )
            .map(res => res.json())
            .map(res => {
                let locale = res.payload;
                if (!locale) {
                    throw new Error("no locale in response");
                }
                return locale;
            }).share();

        return request;
    }

    private getApiHeaders() {
        let headers = new Headers();
        headers.append('Content-Type', 'application/json');
        headers.append('Authorization', 'Bearer ' + this.auth.getToken());
        return headers;
{'fraction_non_alphanumeric': 0.13371999355566297, 'fraction_numerical': 0.0, 'mean_word_length': 1.6116954143878839, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1362118', 'n_tokens_mistral': 1650, 'n_tokens_neox': 1604, 'n_words': 340}