-
Notifications
You must be signed in to change notification settings - Fork 1
/
api.go
76 lines (63 loc) · 1.89 KB
/
api.go
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
package main
import (
"encoding/json"
"io"
"log"
"net/http"
"strconv"
)
/*
Data Model
----------------------------------------
LogbookEntry
Activity
ActivityMedia
Media
Observation
ObservationMedia
Media
*/
// frontend
var apiFrontendRoot = "https://app.journalapetitspas.ca/" // optional
var apiFrontendVersion = "28.3.5" // optional
// backend
var apiBackendRoot = "https://serviceapp.amisgest.ca/"
var apiBackendVersion = "8_2"
var apiBackend = apiBackendRoot + apiBackendVersion + "/"
// apiBackendAPI = apiBackend + "api/"
var apiBackendBreeze = apiBackend + "breeze/Breeze/"
// auth
var apiToken = apiBackend + "token"
// activities
var apiGetLogbookEntry = apiBackendBreeze + "logbook_entry"
var apiGetActivity = apiBackendBreeze + "activity"
var apiGetActivityMedia = apiBackendBreeze + "activity_media"
// observations
var apiGetObservations = apiBackendBreeze + "observation"
var apiGetObservationMedia = apiBackendBreeze + "observation_media"
// media
var apiBackendMedia = apiBackend + "api/media/"
var apiGetMediaGuid = apiBackendMedia + "GetMediaGuid" // full size
// apiGetMediaGuids = apiBackendMedia + "GetMedia" // thumbnails
var apiGetData = apiBackendMedia + "GetData"
/* GET api endpoint wrapper */
func Get(url string, token Token, target interface{}) error {
client := &http.Client{}
req, _ := http.NewRequest("GET", url, nil)
// Set headers
req.Header.Set("accept", "application/json, text/plain, */*")
req.Header.Set("authorization", "Bearer "+token.AccessToken)
// transform token.PersonId from an int to a string
req.Header.Set("personid", strconv.Itoa(token.PersonID))
// Send request
res, err := client.Do(req)
if err != nil {
log.Fatal("Error making request:", err)
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
log.Fatal("Error reading response body:", err)
}
return json.Unmarshal(body, target)
}