Skip to content

Commit

Permalink
Merge pull request #16 from cto-ai/feat/sdk-team
Browse files Browse the repository at this point in the history
PROD-1156 Feat: added Team() function
  • Loading branch information
slaterb1 authored Mar 31, 2021
2 parents 0d97776 + d004b53 commit 4519113
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,32 @@ func (*Sdk) Log(message string) error {
_, err := fmt.Printf(message)
return err
}

// TeamInfo contains user info returned by daemon.
type TeamInfo struct {
ID string `json:"id"`
Name string `json:"name"`
}

// Team returns the team info for the current user running the Op.
func (*Sdk) Team() (TeamInfo, error) {
var body interface{}
method := "GET"
result, err := daemon.SyncRequest("team", body, method)

if err != nil {
return TeamInfo{}, fmt.Errorf("error getting team information: %w", err)
}

// map results to TeamInfo
mapValue := result.(map[string]interface{})
teamInfo := TeamInfo{}
if id, ok := mapValue["id"].(string); ok {
teamInfo.ID = id
}
if name, ok := mapValue["name"].(string); ok {
teamInfo.Name = name
}

return teamInfo, nil
}

0 comments on commit 4519113

Please sign in to comment.