-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from polarsquad/Helpers
Helpers
- Loading branch information
Showing
3 changed files
with
52 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package harvest | ||
|
||
import ( | ||
"io/ioutil" | ||
"net/http" | ||
"net/url" | ||
|
||
"github.com/google/go-querystring/query" | ||
) | ||
|
||
func addParamsToURL(baseURL string, opt interface{}) (string, error) { | ||
url, err := url.Parse(baseURL) | ||
if err != nil { | ||
return baseURL, err | ||
} | ||
|
||
vs, err := query.Values(opt) | ||
if err != nil { | ||
return baseURL, err | ||
} | ||
|
||
url.RawQuery = vs.Encode() | ||
return url.String(), nil | ||
} | ||
|
||
func (h *Harvest) getURL(method string, url string) ([]byte, error) { | ||
Client := &http.Client{} | ||
|
||
req, _ := http.NewRequest("GET", url, nil) | ||
req.Header.Set("User-Agent", "Harvest Slack Bot") | ||
req.Header.Set("Harvest-Account-ID", h.API.AccountID) | ||
req.Header.Set("Authorization", "Bearer "+h.API.AuthToken) | ||
req.Header.Set("Content-Type", "application/json") | ||
|
||
resp, err := Client.Do(req) | ||
body, err := ioutil.ReadAll(resp.Body) | ||
defer resp.Body.Close() | ||
|
||
return body, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters