Skip to content

Commit

Permalink
Merge pull request #52 from kogitoapp/api-key-header
Browse files Browse the repository at this point in the history
Moved API key to request header
  • Loading branch information
JamesClonk authored Dec 25, 2017
2 parents e3b53b3 + 9d583af commit 0e76731
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions lib/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,6 @@ func apiPath(path string) string {
return fmt.Sprintf("/%s/%s", APIVersion, path)
}

func apiKeyPath(path, apiKey string) string {
if strings.Contains(path, "?") {
return path + "&api_key=" + apiKey
}
return path + "?api_key=" + apiKey
}

func (c *Client) get(path string, data interface{}) error {
req, err := c.newRequest("GET", apiPath(path), nil)
if err != nil {
Expand All @@ -155,7 +148,7 @@ func (c *Client) OnRequestCompleted(rc RequestCompletionCallback) {
}

func (c *Client) newRequest(method string, path string, body io.Reader) (*http.Request, error) {
relPath, err := url.Parse(apiKeyPath(path, c.APIKey))
relPath, err := url.Parse(path)
if err != nil {
return nil, err
}
Expand All @@ -167,6 +160,7 @@ func (c *Client) newRequest(method string, path string, body io.Reader) (*http.R
return nil, err
}

req.Header.Add("API-Key", c.APIKey)
req.Header.Add("User-Agent", c.UserAgent)
req.Header.Add("Accept", mediaType)

Expand Down

0 comments on commit 0e76731

Please sign in to comment.