add team exists endpoint for APIv4 (#5517)

Этот коммит содержится в:
Carlos Tadeu Panato Junior
2017-03-08 01:30:33 +01:00
коммит произвёл Joram Wilander
родитель fa75e0e7c4
Коммит 19ec4c4298
5 изменённых файлов: 86 добавлений и 6 удалений

Просмотреть файл

@@ -600,6 +600,16 @@ func (c *Client4) GetTeamByName(name, etag string) (*Team, *Response) {
}
}
// TeamExists returns true or false if the team exist or not.
func (c *Client4) TeamExists(name, etag string) (bool, *Response) {
if r, err := c.DoApiGet(c.GetTeamByNameRoute(name)+"/exists", etag); err != nil {
return false, &Response{StatusCode: r.StatusCode, Error: err}
} else {
defer closeBody(r)
return MapBoolFromJson(r.Body)["exists"], BuildResponse(r)
}
}
// GetTeamsForUser returns a list of teams a user is on. Must be logged in as the user
// or be a system administrator.
func (c *Client4) GetTeamsForUser(userId, etag string) ([]*Team, *Response) {

Просмотреть файл

@@ -156,6 +156,15 @@ func MapToJson(objmap map[string]string) string {
}
}
// MapToJson converts a map to a json string
func MapBoolToJson(objmap map[string]bool) string {
if b, err := json.Marshal(objmap); err != nil {
return ""
} else {
return string(b)
}
}
// MapFromJson will decode the key/value pair map
func MapFromJson(data io.Reader) map[string]string {
decoder := json.NewDecoder(data)
@@ -168,6 +177,18 @@ func MapFromJson(data io.Reader) map[string]string {
}
}
// MapFromJson will decode the key/value pair map
func MapBoolFromJson(data io.Reader) map[string]bool {
decoder := json.NewDecoder(data)
var objmap map[string]bool
if err := decoder.Decode(&objmap); err != nil {
return make(map[string]bool)
} else {
return objmap
}
}
func ArrayToJson(objmap []string) string {
if b, err := json.Marshal(objmap); err != nil {
return ""