forked from charcard/FinalProject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.js
111 lines (99 loc) · 2.79 KB
/
service.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
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
"use strict";
function ArtService($http, $q) {
let colorList;
let classList;
let cultureList;
let finalClassList;
let finalColorList;
let finalCultureList;
let page = 1;
let key = "88bb71d0-7015-11e8-9d38-6fd658e729d6";
const getColor = (colorType) => {
colorList = [];
return $q((resolve, reject) => {
for (let i = 1; i <= 2000; i++) {
$http({
method: 'GET',
url: `https://api.harvardartmuseums.org/object?size=100&page=${i}&apikey=${key}`
}).then((response) => {
for (let itemInArr of response.data.records) {
if (itemInArr.hasOwnProperty("colors") && itemInArr.hasOwnProperty("images")) {
if (itemInArr.images[0].height > 0 ) {
for (let color of itemInArr.colors) {
if (color.hue === colorType) {
colorList.push(itemInArr);
}
}
}
}
};
})
resolve(colorList);
}
})
}
const returnColorImages = () => {
finalColorList = colorList;
console.log(colorList);
return finalColorList;
}
const getClassification = (classType) => {
classList = [];
return $q((resolve, reject)=>{
for (let i = 1; i <= 300; i++) {
$http({
method: 'GET',
url: `https://api.harvardartmuseums.org/object?classification=${classType}&size=100&page=${i}&apikey=${key}`
}).then((response)=>{
for (let itemInArr of response.data.records) {
if (itemInArr.hasOwnProperty("images")) {
if (itemInArr.images[0].height > 0) {
classList.push(itemInArr);
}
}
}
})
resolve(classList);
}
})
}
const returnClassificationImages = () => {
finalClassList = classList;
return finalClassList;
}
const getCulture = (cultureType) => {
cultureList = [];
return $q((resolve, reject)=>{
for (let i = 1; i <= 2000; i++) {
$http({
method: 'GET',
url: `https://api.harvardartmuseums.org/object?culture=${cultureType}&size=100&page=${i}&apikey=${key}`
}).then((response)=>{
for (let itemInArr of response.data.records){
if (itemInArr.hasOwnProperty("images")) {
if (itemInArr.images[0].height > 0) {
cultureList.push(itemInArr);
}
}
}
})
resolve(cultureList);
}
})
}
const returnCultureImages = () => {
finalCultureList = cultureList;
return finalCultureList;
}
return {
getClassification,
returnClassificationImages,
getCulture,
returnCultureImages,
getColor,
returnColorImages
}
}
angular
.module("app")
.factory("ArtService", ArtService);