forked from lokalise/go-lokalise-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
svc_segment.go
157 lines (134 loc) · 4.91 KB
/
svc_segment.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package lokalise
import (
"fmt"
"github.com/go-resty/resty/v2"
"github.com/google/go-querystring/query"
)
const (
pathSegments = "segments"
)
// SegmentationService supports List, Retrieve and Update commands
type SegmentationService struct {
BaseService
listOpts SegmentsListOptions
retrieveOpts SegmentsRetrieveOptions
}
type Segment struct {
SegmentNumber int64 `json:"segment_number"`
LanguageIso string `json:"language_iso"`
ModifiedAt string `json:"modified_at"`
ModifiedAtTimestamp int64 `json:"modified_at_timestamp"`
ModifiedBy int64 `json:"modified_by"`
ModifiedByEmail string `json:"modified_by_email"`
Value string `json:"value"`
IsFuzzy bool `json:"is_fuzzy"`
IsReviewed bool `json:"is_reviewed"`
ReviewedBy int64 `json:"reviewed_by"`
Words int64 `json:"words"`
CustomTranslationStatuses []TranslationStatus `json:"custom_translation_statuses"`
}
type SegmentsResponse struct {
WithProjectID
Segments []Segment `json:"segments"`
Errors []ErrorKeys `json:"error,omitempty"`
}
type SegmentResponse struct {
WithProjectID
KeyID int64 `json:"key_id"`
LanguageISO string `json:"language_iso"`
Segment Segment `json:"segment"`
}
type SegmentUpdateRequest struct {
Value string `json:"value"` // could be string or json for plural keys.
IsFuzzy *bool `json:"is_fuzzy,omitempty"`
IsReviewed *bool `json:"is_reviewed,omitempty"`
CustomTranslationStatusIds []int64 `json:"custom_translation_status_ids,omitempty"`
}
func (s *SegmentationService) List(projectID string, keyID int64, languageIso string) (r SegmentsResponse, err error) {
resp, err := s.getWithOptions(
s.Ctx(),
fmt.Sprintf("%s/%s/%s/%d/%s/%s", pathProjects, projectID, pathKeys, keyID, pathSegments, languageIso),
&r,
s.ListOpts(),
)
if err != nil {
return
}
return r, apiError(resp)
}
func (s *SegmentationService) Retrieve(
projectID string,
keyID int64,
languageIso string,
segmentNumber int64,
) (r SegmentResponse, err error) {
resp, err := s.getWithOptions(
s.Ctx(),
segmentPath(projectID, keyID, languageIso, segmentNumber),
&r,
s.RetrieveOpts(),
)
if err != nil {
return
}
return r, apiError(resp)
}
func (s *SegmentationService) Update(
projectID string,
keyID int64,
languageIso string,
segmentNumber int64,
updateRequest SegmentUpdateRequest,
) (r SegmentResponse, err error) {
resp, err := s.put(s.Ctx(), segmentPath(projectID, keyID, languageIso, segmentNumber), &r, updateRequest)
if err != nil {
return
}
return r, apiError(resp)
}
func segmentPath(projectID string, keyID int64, languageIso string, segmentNumber int64) string {
return fmt.Sprintf(
"%s/%s/%s/%d/%s/%s/%d",
pathProjects,
projectID,
pathKeys,
keyID,
pathSegments,
languageIso,
segmentNumber,
)
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Additional methods
// _____________________________________________________________________________________________________________________
type SegmentsListOptions struct {
// Possible values are 1 and 0.
DisableReferences uint8 `url:"disable_references,omitempty"`
FilterIsReviewed uint8 `url:"filter_is_reviewed,omitempty"`
FilterUnverified uint8 `url:"filter_unverified,omitempty"`
FilterUntranslated uint8 `url:"filter_untranslated,omitempty"`
FilterQAIssues string `url:"filter_qa_issues,omitempty"`
}
func (s *SegmentationService) ListOpts() SegmentsListOptions { return s.listOpts }
func (s *SegmentationService) SetListOptions(o SegmentsListOptions) { s.listOpts = o }
func (s *SegmentationService) WithListOptions(o SegmentsListOptions) *SegmentationService {
s.listOpts = o
return s
}
func (options SegmentsListOptions) Apply(req *resty.Request) {
v, _ := query.Values(options)
req.SetQueryString(v.Encode())
}
type SegmentsRetrieveOptions struct {
DisableReferences uint8 `url:"disable_references,omitempty"`
}
func (options SegmentsRetrieveOptions) Apply(req *resty.Request) {
v, _ := query.Values(options)
req.SetQueryString(v.Encode())
}
func (s *SegmentationService) RetrieveOpts() SegmentsRetrieveOptions { return s.retrieveOpts }
func (s *SegmentationService) SetRetrieveOptions(o SegmentsRetrieveOptions) { s.retrieveOpts = o }
func (s *SegmentationService) WithRetrieveOptions(o SegmentsRetrieveOptions) *SegmentationService {
s.retrieveOpts = o
return s
}