Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions cmd/gettask.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ var taskCmd = &cobra.Command{
Subtasks: subtasksFlag,
}
t.WriteOut(t.GetJSON(t.BuildPath()))

},
}

Expand All @@ -38,5 +37,4 @@ func init() {
taskCmd.Flags().BoolP("custom", "c", false, "task id provided is a clickup custom task id")
taskCmd.Flags().BoolP("subtasks", "s", false, "include subtasks in output")
taskCmd.Flags().BoolP("file", "f", false, "output to file clickup_<taskID>.json")

}
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ require (
github.com/pkg/browser v0.0.0-20201112035734-206646e67786
github.com/spf13/cobra v1.2.1
github.com/spf13/viper v1.9.0
github.com/stretchr/testify v1.7.0
golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mitchellh/mapstructure v1.4.2 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
Expand All @@ -29,4 +32,5 @@ require (
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/ini.v1 v1.63.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
26 changes: 14 additions & 12 deletions internal/requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,38 @@ import (
"github.com/spf13/viper"
)

var (
Client HTTPClient
)

//Requester interface needs an API path to request JSON data
type Requester interface {
BuildPath() string
GetJSON(string) []byte
WriteOut([]byte)
}

// HTTPClient interface
type HTTPClient interface {
Do(req *http.Request) (*http.Response, error)
}

func init() {
Client = &http.Client{}
}

//Gets JSON data for any struct that implements Requester interface
func getJSON(apiPath string) []byte {
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)
resp, err := Client.Do(req)
if err != nil {
log.Fatalln("Errored when sending request to the server")
}
defer resp.Body.Close()
resp_body, _ := ioutil.ReadAll(resp.Body)

return resp_body
// fileFlag := viper.GetBool("file")
// if !fileFlag {
// fmt.Println(string(resp_body))
// }
}

func (t TaskRequest) GetJSON(apiPath string) []byte {
return getJSON(apiPath)
}
29 changes: 29 additions & 0 deletions internal/requester_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package internal

import (
"bytes"
"io/ioutil"
"net/http"
"testing"

"github.com/fantasticrabbit/ClickupCLI/mocks"
"github.com/stretchr/testify/assert"
)

func init() {
Client = &mocks.MockClient{}
}

func TestGetJSON(t *testing.T) {
json := `{"name":"Test Name","full_name":"test full name","owner":{"login": "admin"}}`
mocks.GetDoFunc = func(*http.Request) (*http.Response, error) {
r := ioutil.NopCloser(bytes.NewReader([]byte(json)))
return &http.Response{
StatusCode: 200,
Body: r,
}, nil
}
request := getJSON("http://localhost/testpath")
assert.NotNil(t, request)
assert.EqualValues(t, json, request)
}
18 changes: 18 additions & 0 deletions mocks/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package mocks

import "net/http"

var (
// GetDoFunc fetches the mock client's `Do` func
GetDoFunc func(req *http.Request) (*http.Response, error)
)

// MockClient is the mock client
type MockClient struct {
DoFunc func(req *http.Request) (*http.Response, error)
}

// Do is the mock client's `Do` func
func (m *MockClient) Do(req *http.Request) (*http.Response, error) {
return GetDoFunc(req)
}