Skip to content

Commit

Permalink
abstracted JSON request as interface
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasticrabbit committed Nov 10, 2021
1 parent 91796b6 commit 4eb94b1
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions internal/requester.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package internal

import (
"fmt"
"io/ioutil"
"net/http"

"github.com/spf13/viper"
)

type Requester interface {
BuildPath() string
}

//requests the JSON data for all fields in a Clickup task or subtask
func GetJSON(r Requester) []byte {
apiPath := r.BuildPath()
token := viper.GetString("ctoken")
client := &http.Client{}

req, _ := http.NewRequest(http.MethodGet, apiPath, nil)

req.Header.Add("Authorization", token)
req.Header.Add("Content-Type", "application/json")
resp, err := client.Do(req)

if err != nil {
fmt.Println("Errored when sending request to the server")
}

defer resp.Body.Close()
resp_body, _ := ioutil.ReadAll(resp.Body)

return resp_body
}

0 comments on commit 4eb94b1

Please sign in to comment.