Skip to content

Commit

Permalink
make fetch url support unicode chars (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
yk-eukarya authored Aug 24, 2021
1 parent 080ab97 commit 0f800fe
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions internal/infrastructure/google/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,27 @@ import (
"fmt"
"io"
"net/http"
"net/url"
)

func sheetURL(fileId string, sheetName string) string {
gurl := url.URL{
Scheme: "https",
Host: "docs.google.com",
Path: fmt.Sprintf("spreadsheets/d/%s/gviz/tq", fileId),
}

queryValues := gurl.Query()
queryValues.Set("tqx", "out:csv")
queryValues.Set("sheet", sheetName)
gurl.RawQuery = queryValues.Encode()

return gurl.String()
}

func fetchCSV(token string, fileId string, sheetName string) (*io.ReadCloser, error) {
url := fmt.Sprintf("https://docs.google.com/spreadsheets/d/%s/gviz/tq?tqx=out:csv&sheet=%s", fileId, sheetName)
req, err := http.NewRequest("GET", url, nil)
u := sheetURL(fileId, sheetName)
req, err := http.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 0f800fe

Please sign in to comment.