-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgetRequest.go
More file actions
71 lines (57 loc) · 1.59 KB
/
Copy pathgetRequest.go
File metadata and controls
71 lines (57 loc) · 1.59 KB
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
package main
import (
"encoding/base64"
"encoding/json"
"io/ioutil"
"log"
"net/http"
)
const (
siteName string = "{{yourSiteName}}"
apiUrl string = "https://" + siteName + ".teamwork.com/"
apiKey string = "{{yourApiKey}}"
dataPreference string = "json"
)
var (
companyId string = "{{yourCompanyId}}"
projectId string = "{{yourProjectId}}"
endPoint string = "projects/" + projectId + "." + dataPreference
)
type ProjectJson struct {
Project `json:"project"`
}
type Project struct {
Category_id string `json:"category-id"`
CompanyID string `json:"companyId"`
Description string `json:"description"`
EndDate string `json:"endDate"`
Harvest_timers_enabled bool `json:"harvest-timers-enabled"`
Name string `json:"name"`
NewCompany string `json:"newCompany"`
PrivacyEnabled bool `json:"privacyEnabled"`
ReplyByEmailEnabled bool `json:"replyByEmailEnabled"`
StartDate string `json:"startDate"`
}
func main() {
getRequest(endPoint)
}
func getRequest(endPoint string) {
client := &http.Client{}
req, err := http.NewRequest("GET", apiUrl+endPoint, nil)
req.Header.Add("Authorization", "Basic "+basicAuth(apiKey))
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
body, err := ioutil.ReadAll(resp.Body)
var p ProjectJson
err = json.Unmarshal(body, &p)
if err != nil {
log.Fatal(err)
}
log.Println(p.Project.Name)
log.Println(string(body))
}
func basicAuth(apiKey string) string {
return base64.StdEncoding.EncodeToString([]byte(apiKey))
}