
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable,from } from 'rxjs';
import { map } from 'rxjs/operators';
//import { resolve } from 'dns';


@Injectable({
  providedIn: 'root'
})
export class BlackConnectService {
  // data source - https://www.chiefsoft.net/INTGR/API/theblackfaces/

  url = 'https://www.chiefsoft.net/INTGR/API/theblackfaces/';
  apiKey = ''; // <-- Enter your own key here!

  constructor(
    private http: HttpClient
  ) {


  }



  getResult: any;
  blogData(title: string) {
    // blogData(title: string): Observable<any> {
    var end_url = this.url + "?s=" + encodeURI(title) + "&apikey=" + this.apiKey;
    //    return this.http.get(`${this.url}?s=${encodeURI(title)}&apikey=${this.apiKey}`).pipe(

    /* return this.http.get(this.url+"?s="+encodeURI(title)+"&apikey="+this.apiKey).pipe(
       map(results => results['internal_return'])
 */
return from (
  new Promise((resolve)=>{

    this.http.get(end_url).subscribe(
      (data) => {
        this.getResult = data;
      //  console.log(this.getResult);
        resolve(data);
      }
    )

  })
)

      //console.log(results);
  //  );
  }

}
