-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBaseAPIHelper.js
More file actions
65 lines (57 loc) · 1.9 KB
/
BaseAPIHelper.js
File metadata and controls
65 lines (57 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* Classe base para API Helpers
*/
export class BaseAPIHelper {
constructor(config) {
if (!config || !config.username) {
throw new Error('Nome de usuário é obrigatório');
}
this.config = {
username: config.username,
token: config.token || null,
baseUrl: config.baseUrl || null
};
// Serviços que serão implementados
this.userService = null;
this.repoService = null;
this.activityService = null;
this.languageService = null;
this.commitService = null;
this.contributionService = null;
// Estado atual
this.currentRepo = null;
this.currentPath = '';
this.currentCommit = null;
}
async loadAllData() {
throw new Error('Método loadAllData() deve ser implementado');
}
// Getters
get userData() { return this.userService?.userData; }
get reposData() { return this.repoService?.reposData; }
get activitiesData() { return this.activityService?.activitiesData; }
get languagesData() { return this.languageService?.languagesData; }
get commitsData() { return this.commitService?.commitsData; }
get contributionsData() { return this.contributionService?.contributionsData; }
// Métodos de renderização
renderProfile() { return this.userService?.renderProfile(); }
renderActivities() { return this.activityService?.renderActivities(); }
renderRepos(sort) { return this.repoService?.renderRepos(sort); }
renderCharts() {
return {
languages: {
labels: Object.keys(this.languagesData || {}),
data: Object.values(this.languagesData || {})
},
commits: {
labels: Object.keys(this.commitsData || {}).slice(0, 10),
data: Object.values(this.commitsData || {}).slice(0, 10)
},
contributions: {
labels: Object.keys(this.contributionsData || {}),
data: Object.values(this.contributionsData || {})
}
};
}
}
export default BaseAPIHelper;