Skip to content

Commit

Permalink
Fix api constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulrich Lissé committed Apr 10, 2019
1 parent 8c25d5a commit 0750531
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
29 changes: 17 additions & 12 deletions mite/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ import (
"net/url"
)

const contentType = "application/json"
const userAgentTemplate = "mite-go/%s (+github.com/leanovate/mite-go)"
const (
headerContentType = "Content-Type"
headerUserAgent = "User-Agent"
headerXMiteApiKey = "X-MiteApiKey"
mediaTypeApplicationJson = "application/json"
userAgentTemplate = "mite-go/%s (+github.com/leanovate/mite-go)"
)

type Api interface {
domain.AccountApi
Expand Down Expand Up @@ -46,8 +51,8 @@ func (a *api) get(resource string, query url.Values, result interface{}) error {
return err
}

req.Header.Add("User-Agent", a.agent)
req.Header.Add("X-MiteApiKey", a.key)
req.Header.Add(headerUserAgent, a.agent)
req.Header.Add(headerXMiteApiKey, a.key)

res, err := a.client.Do(req)
if err != nil {
Expand All @@ -73,9 +78,9 @@ func (a *api) post(resource string, body interface{}, result interface{}) error
return err
}

req.Header.Add("Content-Type", contentType)
req.Header.Add("User-Agent", a.agent)
req.Header.Add("X-MiteApiKey", a.key)
req.Header.Add(headerContentType, mediaTypeApplicationJson)
req.Header.Add(headerUserAgent, a.agent)
req.Header.Add(headerXMiteApiKey, a.key)

res, err := a.client.Do(req)
if err != nil {
Expand Down Expand Up @@ -105,9 +110,9 @@ func (a *api) patch(resource string, body interface{}, result interface{}) error
return err
}

req.Header.Add("Content-Type", contentType)
req.Header.Add("User-Agent", a.agent)
req.Header.Add("X-MiteApiKey", a.key)
req.Header.Add(headerContentType, mediaTypeApplicationJson)
req.Header.Add(headerUserAgent, a.agent)
req.Header.Add(headerXMiteApiKey, a.key)

res, err := a.client.Do(req)
if err != nil {
Expand All @@ -132,8 +137,8 @@ func (a *api) delete(resource string, result interface{}) error {
return err
}

req.Header.Add("User-Agent", a.agent)
req.Header.Add("X-MiteApiKey", a.key)
req.Header.Add(headerUserAgent, a.agent)
req.Header.Add(headerXMiteApiKey, a.key)

res, err := a.client.Do(req)
if err != nil {
Expand Down
8 changes: 5 additions & 3 deletions mite/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"encoding/json"
)

const testApiKey = "f00bar"
const testClientVersion = "vX"
const testUserAgent = "mite-go/" + testClientVersion + " (+github.com/leanovate/mite-go)"
const (
testApiKey = "key"
testClientVersion = "test"
testUserAgent = "mite-go/" + testClientVersion + " (+github.com/leanovate/mite-go)"
)

type recorder struct {
method string
Expand Down

0 comments on commit 0750531

Please sign in to comment.