<commit_before>import {Injectable}    from '@angular/core';
import {Headers, Http} from '@angular/http';

import 'rxjs/add/operator/toPromise';

import {Product} from './product';

@Injectable()
export class ProductService {

    private productUrl = 'api/products';  // URL to web api

    constructor(private http:Http) {
    }

    getProducts():Promise<Product[]> {
        return this.http.get(this.productUrl)
            .toPromise()
            .then(response => response.json().data as Product[])
            .catch(this.handleError);
    }

    getProductById(id:number) {
        return this.getProducts()
            .then(products => products.filter(product => product.id === id)[0]);
    }

    getProductByCompany(company:string[]) {
        return this.getProducts()
            .then(products => products.filter(product => {
                for (var i = 0; i < company.length; i++) {
                    console.log(product.company+" | "+company[i]);
                    if (product.company === company[i])
                        return true;
                }
                return false;
            }));
    }

    getProductByProcessor(company:string) {
        return this.getProducts()
            .then(products => products.filter(product => product.company === company)[0]);
    }

    getProductByOS(company:string) {
        return this.getProducts()
            .then(products => products.filter(product => product.company === company)[0]);
    }

    getProductByRam(company:string) {
        return this.getProducts()
            .then(products => products.filter(product => product.company === company)[0]);
    }

    getProductByHHD(company:string) {
        return this.getProducts()
            .then(products => products.filter(product => product.company === company)[0]);
    }

    save(hero:Product):Promise<Product> {
        if (hero.id) {
            return this.put(hero);
        }
        return this.post(hero);
    }

    delete(hero:Product) {
        let headers = new Headers();
        headers.append('Content-Type', 'application/json');

        let url = `${this.productUrl}/${hero.id}`;

        return this.http
            .delete(url, headers)
            .toPromise()
            .catch(this.handleError);
    }

    // Add new Product
    private post(hero:Product):Promise<Product> {
        let headers = new Headers({
            'Content-Type': 'application/json'
        });

        return this.http
            .post(this.productUrl, JSON.stringify(hero), {headers: headers})
            .toPromise()
            .then(res => res.json().data)
            .catch(this.handleError);
    }

    // Update existing Product
    private put(hero:Product) {
        let headers = new Headers();
        headers.append('Content-Type', 'application/json');

        let url = `${this.productUrl}/${hero.id}`;

        return this.http
            .put(url, JSON.stringify(hero), {headers: headers})
            .toPromise()
            .then(() => hero)
            .catch(this.handleError);
    }

    private handleError(error:any) {
        console.error('An error occurred', error);
        return Promise.reject(error.message || error);
    }
}

<commit_msg>Included API<commit_after>import {Injectable}    from '@angular/core';
import {Headers, Http} from '@angular/http';

import {Observable} from 'rxjs/Rx';
import {Product} from './product';

@Injectable()
export class ProductService {

    private productUrl = 'https://saraex01.mybluemix.net/cproduct/';  // URL to web api

    constructor(private http:Http) {
    }
     getProducts() : Observable<Product[]>{
         // ...using get request
         return this.http.get(this.productUrl)
                        // ...and calling .json() on the response to return data
                         .map((response:Response) => {
                             return response.json();
                             })
                         //...errors if any
                         .catch(this.handleError);
        
     }

     searchProducts(term: string) : Observable<Product[]>{
         // ...using get request
         return this.http.get(this.productUrl + term)
                        // ...and calling .json() on the response to return data
                         .map((response:Response) => {
                             alert(JSON.stringify(response.json()));
                             return response.json();
                             })
                         //...errors if any
                         .catch(this.handleError);
        
     }
     
    private handleError(error:any) {
        console.error('An error occurred', error);
        return Observable.throw(error.json().error || 'Server error');
    }
}


{'fraction_non_alphanumeric': 0.13722198908938313, 'fraction_numerical': 0.001678556441460344, 'mean_word_length': 1.8123893805309734, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 25, 'https://': 1, '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': '4973368', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1236, 'n_words': 260}