import { Injectable } from '@angular/core';
import { Http, RequestOptions } from '@angular/http';
import 'rxjs/add/operator/map';
import { from } from 'rxjs';
import { HttpParams } from '@angular/common/http';
import { map, filter, catchError, mergeMap } from 'rxjs/operators';
//
// import { HttpHeaders } from '@angular/common/http';
// import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class RestService {
config: any = {
AppName: "Affiliate Admin",
PrimaryUrl: "http://xx.xxx..xx:5052/xxxxx",//damo
SecondaryUrl: "xx.x..x..xx5052/xxxxx",//demo
};
constructor(public http: Http) {
}
GetMethod(param: string) {
return this.http.get(param).map(response => response.json());
}
//aj
UploadProfilePic(url: string, params: any){
console.log("url:", url);
console.log("Parms:",params);
try {
return this.http.post(url, params)
.map(response => response.json());
} catch (e) {
console.log(e);
}
}
get(endPointg: string, params?: any, optn?: any) {
if (!optn) {
optn = {
params: new HttpParams()
};
};
let p = [];
let newParam;
if (params) {
for (let k in params) {
let str = k + '=' + params[k];
p.push(str);
}
newParam = p.join('&');
}
try {
return this.http.get(this.config.PrimaryUrl + '/' + endPointg + '?' + newParam)
.map(response => response.json());
} catch (e) {
console.log(e);
}
}
post(endPointg: string, params?: any, optn?: any) {
if (!optn) {
optn = {
params: new HttpParams()
};
};
try {
return this.http.post(this.config.PrimaryUrl + '/' + endPointg, params)
.map(response => response.json());
} catch (e) {
console.log(e);
}
}
get1(endPointg: string, params?: any, optn?: any) {
if (!optn) {
optn = {
params: new HttpParams()
};
};
let p = [];
let newParam;
if (params) {
for (let k in params) {
let str = k + '=' + params[k];
p.push(str);
}
newParam = p.join('&');
}
try {
return this.http.get(this.config.SecondaryUrl + '/' + endPointg + '?' + newParam)
.map(response => response.json());
} catch (e) {
console.log(e);
}
}
post1(endPointg: string, params?: any, optn?: any) {
if (!optn) {
optn = {
params: new HttpParams()
};
};
try {
return this.http.post(this.config.SecondaryUrl + '/' + endPointg, params)
.map(response => response.json());
} catch (e) {
console.log(e);
}
}
webSocket(domain: string, param?: any) {
var fws = new WebSocket(domain);
fws.onopen = function () {
fws.send(param); // Send the message 'Ping' to the server
};
return fws;
}
// ajAuthGet(){
// // var headerApi= new Headers({ "Content-Type": "application/x-www-form-urlencoded",
// // "Authorization": "Basic 488ccc4dbcd818784de6f72d9e1a7b88-us19"})
// // return this.http.get('https://us19.api.mailchimp.com/3.0/', { headers: headerApi })
// // let headers = new Headers({ 'Content-Type': 'application/json' });
// // headers.append('Authorization', 'Basic 488ccc4dbcd818784de6f72d9e1a7b88-us19 ')
// // let options = new RequestOptions({ headers: headers });
// const httpOptions = {
// headers: new HttpHeaders({
// 'Content-Type': 'application/json',
// 'Authorization': 'Basic 488ccc4dbcd818784de6f72d9e1a7b88-us19'
// })
// };
// return this.HttpClient.get('https://us19.api.mailchimp.com/3.0/', httpOptions)
// .map(response => response);
// }
}