-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttpTest.js
More file actions
executable file
·79 lines (71 loc) · 2.08 KB
/
httpTest.js
File metadata and controls
executable file
·79 lines (71 loc) · 2.08 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
(function() {
var userData = {
'ekelkar': {
'data': {
'name': 'Erin Kelkar',
'location': 'Peachtree Corners, GA',
'avatar_url': 'https://media.licdn.com/mpr/mpr/shrinknp_200_200/p/6/000/27a/27d/18888da.jpg',
'repos': [{
'name': 'Repo 1',
'stargazers_count': 5,
'language': 'javascript'
}, {
'name': 'Repo 2',
'stargazers_count': 10,
'language': 'c'
}, {
'name': 'Repo 3',
'stargazers_count': 30,
'language': 'PL/1'
}]
}
},
'jkelkar': {
'data': {
'name': 'Jay Kelkar',
'location': 'Peachtree Corners, GA',
'avatar_url': 'https://pbs.twimg.com/profile_images/1250452527/jaykelkar_400x400.png'
}
},
'AllisonFisher': {
'data': {
'name': 'Allison Fisher',
'location': 'Pittsburgh, PA',
'avatar_url': 'http://charpiescholars.appspot.com/images/allison_fisher.jpg'
}
}
};
var httpTest = function($q, $log) {
// In order to simulate an async http call, getUser must return a
// the data in a promise.
var getUser = function(username) {
// replace new Promise with angular promises $q
return $q(function(resolve, reject) {
if (userData[username]) { // This user exists.
$log.log('userData:', userData[username]);
resolve(userData[username].data);
} else {
$log.log('reject');
// Removed sending an Error object
// Would that be better
// reject(Error('User not found'));
reject('User not found');
}
})
};
var getRepos = function(username) {
return $q(function(resolve, reject) {
if (userData[username].data.repos) {
$log.log('repos:', userData[username].data.repos);
resolve(userData[username].data.repos);
}
});
};
return ({
getUser: getUser,
getRepos: getRepos
});
};
var module = angular.module('githubViewer');
module.factory('httpTest', httpTest);
}());