-
Notifications
You must be signed in to change notification settings - Fork 6
/
activity.go
57 lines (46 loc) · 1.41 KB
/
activity.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package client
// Activity represents Redmine activity for time that's being tracked.
type Activity struct {
ID int64 `json:"id"`
Name string `json:"name"`
}
// Activities represents a list of activities.
type Activities []Activity
type activitiesResponse struct {
Activities Activities `json:"time_entry_activities"`
}
// GetActivities fetches all Activities that can be entered in time entry record. Project specific
// activities cannot be fetched with this method.
func (c *Client) GetActivities() (Activities, error) {
req, err := c.getRequest("/enumerations/time_entry_activities.json", "")
if err != nil {
return nil, err
}
var response activitiesResponse
_, err = c.Do(req, &response)
if err != nil {
return nil, err
}
return response.Activities, nil
}
// Valid checks whether activity with provided name parameter exists. If yes,
// returns its ID and true as second parameter; if not, return false as second parameter.
func (acts Activities) Valid(name string) (int64, bool) {
theMap := make(map[string]int64)
for _, activity := range acts {
theMap[activity.Name] = activity.ID
}
activityID, exists := theMap[name]
if !exists {
return activityID, false
}
return activityID, true
}
// Names returns activity names.
func (acts Activities) Names() []string {
theActs := make([]string, 0, len(acts))
for _, activity := range acts {
theActs = append(theActs, activity.Name)
}
return theActs
}