This repository was archived by the owner on Jan 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtexts.go
More file actions
74 lines (65 loc) · 2.32 KB
/
texts.go
File metadata and controls
74 lines (65 loc) · 2.32 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package clockogo
import (
"github.com/google/go-querystring/query"
"net/http"
)
type EntriesTextsMode string
const (
ExactMatch EntriesTextsMode = "exact_match"
StartsWith EntriesTextsMode = "starts_with"
EndsWith EntriesTextsMode = "ends_with"
Contains EntriesTextsMode = "contains"
)
type EntriesTextsSort string
const (
TextAsc EntriesTextsMode = "text_asc"
TextDesc EntriesTextsMode = "text_desc"
TimeAsc EntriesTextsMode = "time_asc"
TimeDesc EntriesTextsMode = "time_desc"
)
type EntriesTextsAPI struct {
client *Client
}
type EntriesTextsListParams struct {
Text string `url:"text"`
Mode EntriesTextsMode `url:"mode,omitempty"`
Sort EntriesTextsSort `url:"sort,omitempty"`
FilterTimeSince *ISO8601UTC `url:"filter[time_since],omitempty"`
FilterTimeUntil *ISO8601UTC `url:"filter[time_until],omitempty"`
FilterUsersId int `url:"filter[users_id],omitempty"`
FilterCustomersId int `url:"filter[customers_id],omitempty"`
FilterProjectsId int `url:"filter[projects_id],omitempty"`
FilterServicesId int `url:"filter[services_id],omitempty"`
FilterLumpsumServicesId int `url:"filter[lumpsum_services_id],omitempty"`
FilterBillable BillableType `url:"filter[billable],omitempty"`
Page int `url:"page,omitempty"`
}
type EntriesTexts struct {
Paging `json:"paging"`
Filter interface{} `json:"filter"`
Mode EntriesTextsMode `json:"mode"`
Sort EntriesTextsSort `json:"sort"`
TextsRaw interface{} `json:"texts"`
Texts map[string]string `json:"-"`
}
func (api EntriesTextsAPI) List(q EntriesTextsListParams) (*EntriesTexts, error) {
params, err := query.Values(&q)
if err != nil {
return nil, err
}
req, err := api.client.auth.NewRequest(http.MethodGet, BaseURL+"/api/v2/entriesTexts?"+params.Encode(), nil)
var data EntriesTexts
err = api.client.Do(req, &data)
if err != nil {
return nil, err
}
data.Texts = make(map[string]string)
if _, ok := data.TextsRaw.(map[string]interface{}); ok {
for id, text := range data.TextsRaw.(map[string]interface{}) {
if _, ok := text.(string); ok {
data.Texts[id] = text.(string)
}
}
}
return &data, nil
}