-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaping-github-helper.js
More file actions
146 lines (131 loc) · 6.5 KB
/
Copy pathaping-github-helper.js
File metadata and controls
146 lines (131 loc) · 6.5 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
'use strict';
angular.module('jtt_aping_github')
.service('apingGithubHelper', ['apingModels', 'apingTimeHelper', 'apingUtilityHelper', function (apingModels, apingTimeHelper, apingUtilityHelper) {
this.getThisPlatformString = function () {
return 'github';
};
this.getThisPlatformLink = function () {
return 'https://github.com/';
};
this.getObjectByJsonData = function (_data, _helperObject) {
var requestResults = [];
if (_data && _data.data) {
var _this = this;
if (_data.data.constructor === Array) {
angular.forEach(_data.data, function (value, key) {
var tempResult;
if (_helperObject.getNativeData === true || _helperObject.getNativeData === 'true') {
tempResult = value;
} else {
tempResult = _this.getItemByJsonData(value, _helperObject.model);
}
if (tempResult) {
requestResults.push(tempResult);
}
});
} else {
if (_data.data.items) {
angular.forEach(_data.data.items, function (value, key) {
var tempResult;
if (_helperObject.getNativeData === true || _helperObject.getNativeData === 'true') {
tempResult = value;
} else {
tempResult = _this.getItemByJsonData(value, _helperObject.model);
}
if (tempResult) {
requestResults.push(tempResult);
}
});
} else {
var tempResult;
if (_helperObject.getNativeData === true || _helperObject.getNativeData === 'true') {
tempResult = _data.data;
} else {
tempResult = _this.getItemByJsonData(_data.data, _helperObject.model);
}
if (tempResult) {
requestResults.push(tempResult);
}
}
}
}
return requestResults;
};
this.getItemByJsonData = function (_item, _model) {
var returnObject = {};
if (_item && _model) {
switch (_model) {
case 'repo':
returnObject = this.getRepoItemByJsonData(_item);
break;
case 'user':
returnObject = this.getUserItemByJsonData(_item);
break;
default:
return false;
}
}
return returnObject;
};
this.getRepoItemByJsonData = function (_item) {
var repoObject = apingModels.getNew('repo', this.getThisPlatformString());
angular.extend(repoObject, {
owner_name: _item.owner ? _item.owner.login : undefined,
owner_id: _item.owner ? _item.owner.id : undefined,
owner_link: _item.owner ? _item.owner.html_url : undefined,
owner_img_url: _item.owner ? _item.owner.avatar_url : undefined,
name: _item.name,
id: _item.id,
fullname: _item.full_name,
description: _item.description || undefined,
url: _item.html_url,
homepage: _item.homepage || undefined,
language: _item.language || undefined,
clone_url: _item.clone_url,
git_url: _item.git_url,
ssh_url: _item.ssh_url,
svn_url: _item.svn_url,
isFork: _item.fork,
openIssues: _item.open_issues_count,
watchers: _item.watchers_count,
stargazers: _item.stargazers_count,
forks: _item.forks_count,
created_timestamp: apingTimeHelper.getTimestampFromDateString(_item.created_at, 1000, 3600 * 1000),
created_date_time: new Date(_item.created_at),
updated_timestamp: _item.updated_at ? apingTimeHelper.getTimestampFromDateString(_item.updated_at, 1000, 3600 * 1000) : undefined,
updated_date_time: _item.updated_at ? new Date(_item.updated_at) : undefined,
pushed_timestamp: _item.pushed_at ? apingTimeHelper.getTimestampFromDateString(_item.pushed_at, 1000, 3600 * 1000) : undefined,
pushed_date_time: _item.pushed_at ? new Date(_item.pushed_at) : undefined,
});
return repoObject;
};
this.getUserItemByJsonData = function (_item) {
var userObject = apingModels.getNew('user', this.getThisPlatformString());
angular.extend(userObject, {
username: _item.login, //NAME of of the user
score: _item.score,
user_id: _item.login, //ID of user (channel / page / account, ...)
user_url: _item.html_url, //url to user (channel / uploader / page / account, ...)
intern_id: _item.id, // INTERN ID of user (facebook id, instagram id, ...)
thumb_url: _item.avatar_url, // best case 200px (min)
img_url: _item.avatar_url, //preview image url (best case 700px)
native_url: _item.avatar_url, // best quality
type: _item.type,
bio: _item.bio || undefined,
blog_url: _item.blog || undefined,
company: _item.company || undefined,
email: _item.email || undefined,
created_at: _item.created_at || undefined,
updated_at: _item.updated_at || undefined,
followers: _item.followers || undefined,
following: _item.following || undefined,
hireable: _item.hireable || undefined,
location: _item.location || undefined,
fullname: _item.name || undefined,
public_gists: _item.public_gists || undefined,
public_repos: _item.public_repos || undefined,
source: _item, //different payload
});
return userObject;
};
}]);