1
|
/*
|
2
|
* Created by myrto on 12/05/2017
|
3
|
*/
|
4
|
|
5
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
6
|
import { Injectable } from '@angular/core';
|
7
|
import { environment } from '../../environments/environment';
|
8
|
import { PiwikInfo } from '../domain/typeScriptClasses';
|
9
|
import { Observable } from 'rxjs';
|
10
|
|
11
|
const headerOptions = {
|
12
|
headers : new HttpHeaders().set('Content-Type', 'application/json')
|
13
|
.set('Accept', 'application/json'),
|
14
|
withCredentials: true
|
15
|
};
|
16
|
|
17
|
@Injectable ()
|
18
|
export class PiwikService {
|
19
|
private apiUrl = environment.API_ENDPOINT + '/piwik/';
|
20
|
|
21
|
constructor(private httpClient: HttpClient) { }
|
22
|
|
23
|
|
24
|
approvePiwikSite(repositoryId: string) {
|
25
|
const url = `${this.apiUrl}approvePiwikSite/${repositoryId}`;
|
26
|
console.log(`knocking on: ${url}`);
|
27
|
return this.httpClient.get(url, {withCredentials: true, responseType: 'text'});
|
28
|
}
|
29
|
|
30
|
enableMetricsForRepository(repoName: string, repoWebsite: string, piwik: PiwikInfo): Observable<PiwikInfo> {
|
31
|
let url = `${this.apiUrl}enableMetricsForRepository`;
|
32
|
url = `${url}?officialName=${encodeURIComponent(repoName)}&repoWebsite=${encodeURIComponent(repoWebsite)}`;
|
33
|
console.log(`knocking on: ${url}`);
|
34
|
console.log(`sending ${JSON.stringify(piwik)}`);
|
35
|
|
36
|
return this.httpClient.post<PiwikInfo>(url, JSON.stringify(piwik), headerOptions);
|
37
|
}
|
38
|
|
39
|
getOpenaireId(id: string) {
|
40
|
const url = `${this.apiUrl}getOpenaireId/${id}`;
|
41
|
console.log(`knocking on: ${url}`);
|
42
|
|
43
|
return this.httpClient.get(url, {withCredentials: true, responseType: 'text'});
|
44
|
}
|
45
|
|
46
|
getPiwikInfo(id: string): Observable<PiwikInfo> {
|
47
|
const url = `${this.apiUrl}getPiwikSiteForRepo/${id}`;
|
48
|
console.log(`knocking on: ${url}`);
|
49
|
|
50
|
return this.httpClient.get<PiwikInfo>(url, headerOptions);
|
51
|
}
|
52
|
|
53
|
getPiwikSitesForRepos(): Observable<PiwikInfo[]> {
|
54
|
const url = `${this.apiUrl}getPiwikSitesForRepos`;
|
55
|
console.log(`knocking on: ${url}`);
|
56
|
|
57
|
return this.httpClient.get<PiwikInfo[]>(url, headerOptions);
|
58
|
}
|
59
|
|
60
|
|
61
|
markPiwikSiteAsValidated (repositoryId: string) {
|
62
|
const url = `${this.apiUrl}markPiwikSiteAsValidated/${repositoryId}`;
|
63
|
console.log(`knocking on: ${url}`);
|
64
|
const body = {};
|
65
|
|
66
|
return this.httpClient.post(url, body, { withCredentials: true, responseType: 'text' });
|
67
|
}
|
68
|
|
69
|
savePiwikInfo(piwik: PiwikInfo): Observable<PiwikInfo> {
|
70
|
const url = `${this.apiUrl}savePiwikInfo`;
|
71
|
console.log(`knocking on: ${url}`);
|
72
|
|
73
|
return this.httpClient.post<PiwikInfo>(url, piwik, headerOptions);
|
74
|
}
|
75
|
|
76
|
|
77
|
}
|