<commit_before><commit_msg>Creating SearchService class<commit_after>'use strict';
import { API_ENDPOINT } from '../const';
import { Bus } from '../models/bus';
import { Injectable } from 'angular2/core';
import { Http } from 'angular2/http';

@Injectable()
export class SearchService {
    
    private http: Http;
    
    constructor(http: Http) {
        this.http = http;
    }

    private processBuses(obj: any[]): Bus[] {
        let result: Bus[] = [];
        obj.forEach((data) => {
            result.push(new Bus(data.line, data.order, data.speed, data.direction, data.latitude, data.longitude, data.sense, data.timeStamp));
        });
        return result;
    }
    
    public getBuses(query: string): Promise<Bus[]> {
        return new Promise<Bus[]>(resolve => {
            let url: string = `${API_ENDPOINT}/v3/search/${query}`;
            this.http.get(url).subscribe(data => resolve( this.processBuses( data.json() ) ) );
        });
    }
}
{'fraction_non_alphanumeric': 0.16028955532574973, 'fraction_numerical': 0.0031023784901758012, 'mean_word_length': 2.723076923076923, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '5486582', 'n_tokens_mistral': 296, 'n_tokens_neox': 296, 'n_words': 65}