/
GamesService.js
69 lines (60 loc) · 2.06 KB
/
GamesService.js
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
function GamesService($http) {
var API_URL = '/api'; //using Node + Express proxy API to circumvent cross-origin request from: 'https://store.steampowered.com/api'
var featuredCategories;
this.getFeaturedCategories = function() {
if (!featuredCategories) { //If the response hasn't already been stored
featuredCategories = $http.get(API_URL + '/featuredcategories'); //store the response in the variable
return featuredCategories;
} else {
return featuredCategories;
}
}
this.getTopSellers = function() {
return this.getFeaturedCategories()
.then(function successCallback(response) {
return response["data"]["top_sellers"]["items"];
}, function errorCallback(response) {
logError(response);
});
}
this.getNewReleases = function() {
return this.getFeaturedCategories()
.then(function successCallback(response) {
return response["data"]["new_releases"]["items"];
}, function errorCallback(response) {
logError(response);
});
}
this.getSpecials = function() {
return this.getFeaturedCategories()
.then(function successCallback(response) {
return response["data"]["specials"]["items"];
}, function errorCallback(response) {
logError(response);
});
}
this.getComingSoon = function() {
return this.getFeaturedCategories()
.then(function successCallback(response) {
return response["data"]["coming_soon"]["items"];
}, function errorCallback(response) {
logError(response);
});
}
this.getGame = function(id) {
return $http.get(API_URL + '/appdetails/' + id) //, {params: { appids: id }}
.then(function successCallback(response) {
return response["data"][id.toString()];
}, function errorCallback(response) {
logError(response);
});
}
function logError(response) { //private function
console.log("API error");
console.log(response);
}
}
GamesService.$inject = ['$http']; //explicit dependency injection for Webpack JS minification
angular
.module('app')
.service('GamesService', GamesService);