-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
32 lines (26 loc) · 772 Bytes
/
api.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
class API {
constructor({ url, progressionId }) {
this.url = url
this.progressionId = progressionId
this.fetchSpots.bind(this)
this.fetchSurroundings.bind(this)
console.log(this.url, this.progressionId, 'API')
}
async fetchSpots() {
try {
const res = await fetch(`${this.url}/progressions/${this.progressionId}/spots`)
return await res.json()
} catch (err) {
throw new Error(err.message)
}
}
async fetchSurroundings({ latitude, longitude }) {
try {
const res = await fetch(`${this.url}/progressions/${this.progressionId}/surroundings?latitude=${latitude}&longitude=${longitude}`)
return await res.json()
} catch (err) {
throw new Error(err.message)
}
}
}
export default API