-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetcher.go
68 lines (64 loc) · 1.79 KB
/
fetcher.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
package EpitechFetcher
import (
"encoding/json"
"io/ioutil"
"net/http"
"github.com/lbrulet/EpitechFetcher/models"
"github.com/lbrulet/EpitechFetcher/models/user"
)
//FetchIntranetUser going to fetch the profil of the user
func FetchIntranetUser(userInfo models.EpiUser) (user.UserIntra, error) {
client := &http.Client{}
if req, err := http.NewRequest("GET", "https://intra.epitech.eu/"+userInfo.AutoLogin+"/user?format=json", nil); err != nil {
return user.UserIntra{}, err
} else {
response, err := client.Do(req)
if err != nil {
return user.UserIntra{}, err
} else {
data, err := ioutil.ReadAll(response.Body)
if err != nil {
return user.UserIntra{}, err
} else {
usr := user.NewUserIntra()
if err := json.Unmarshal(data, &usr); err != nil {
return user.UserIntra{}, err
} else {
if err := response.Body.Close(); err != nil {
return user.UserIntra{}, err
} else {
return usr, nil
}
}
}
}
}
}
//FetchIntranetNote going to fetch note of the user
func FetchIntranetNote(userInfo models.EpiUser) (user.CursusIntra, error) {
client := &http.Client{}
if req, err := http.NewRequest("GET", "https://intra.epitech.eu/"+userInfo.AutoLogin+"/user/"+userInfo.Login+"/notes/?format=json", nil); err != nil {
return user.CursusIntra{}, err
} else {
response, err := client.Do(req)
if err != nil {
return user.CursusIntra{}, err
} else {
data, err := ioutil.ReadAll(response.Body)
if err != nil {
return user.CursusIntra{}, err
} else {
cursus := user.NewNoteIntra()
if err := json.Unmarshal(data, &cursus); err != nil {
return user.CursusIntra{}, err
} else {
if err := response.Body.Close(); err != nil {
return user.CursusIntra{}, err
} else {
return cursus, nil
}
}
}
}
}
}