-
Notifications
You must be signed in to change notification settings - Fork 18
/
svc_file.go
182 lines (154 loc) · 8.78 KB
/
svc_file.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package lokalise
import (
"fmt"
"github.com/google/go-querystring/query"
"github.com/go-resty/resty/v2"
)
const (
pathFiles = "files"
)
type FileService struct {
BaseService
opts FileListOptions
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Service entity objects
// _____________________________________________________________________________________________________________________
type File struct {
Filename string `json:"filename"`
KeyCount int64 `json:"key_count"`
}
type FileUpload struct {
Data string `json:"data"`
Filename string `json:"filename"`
LangISO string `json:"lang_iso"`
Tags []string `json:"tags,omitempty"`
ConvertPlaceholders *bool `json:"convert_placeholders,omitempty"`
DetectICUPlurals bool `json:"detect_icu_plurals,omitempty"`
TagInsertedKeys *bool `json:"tag_inserted_keys,omitempty"`
TagUpdatedKeys *bool `json:"tag_updated_keys,omitempty"`
TagSkippedKeys bool `json:"tag_skipped_keys,omitempty"`
ReplaceModified bool `json:"replace_modified,omitempty"`
SlashNToLinebreak *bool `json:"slashn_to_linebreak,omitempty"`
KeysToValues bool `json:"keys_to_values,omitempty"`
DistinguishByFile bool `json:"distinguish_by_file,omitempty"`
ApplyTM bool `json:"apply_tm,omitempty"`
HiddenFromContributors bool `json:"hidden_from_contributors,omitempty"`
CleanupMode bool `json:"cleanup_mode,omitempty"`
CustomTranslationStatusIds []int64 `json:"custom_translation_status_ids,omitempty"`
CustomTranslationStatusInsertedKeys *bool `json:"custom_translation_status_inserted_keys,omitempty"`
CustomTranslationStatusUpdatedKeys *bool `json:"custom_translation_status_updated_keys,omitempty"`
CustomTranslationStatusSkippedKeys *bool `json:"custom_translation_status_skipped_keys,omitempty"`
Queue bool `json:"queue"`
SkipDetectLangIso bool `json:"skip_detect_lang_iso,omitempty"`
UseAutomations *bool `json:"use_automations,omitempty"`
}
type FileDownload struct {
Format string `json:"format"`
OriginalFilenames *bool `json:"original_filenames,omitempty"`
BundleStructure string `json:"bundle_structure,omitempty"`
DirectoryPrefix *string `json:"directory_prefix,omitempty"`
AllPlatforms bool `json:"all_platforms,omitempty"`
FilterLangs []string `json:"filter_langs,omitempty"`
FilterData []string `json:"filter_data,omitempty"`
FilterFilenames []string `json:"filter_filenames,omitempty"`
AddNewlineEOF bool `json:"add_newline_eof,omitempty"`
CustomTranslationStatusIDs []string `json:"custom_translation_status_ids,omitempty"`
IncludeTags []string `json:"include_tags,omitempty"`
ExcludeTags []string `json:"exclude_tags,omitempty"`
ExportSort string `json:"export_sort,omitempty"`
ExportEmptyAs string `json:"export_empty_as,omitempty"`
IncludeComments bool `json:"include_comments,omitempty"`
IncludeDescription *bool `json:"include_description,omitempty"`
IncludeProjectIDs []string `json:"include_pids,omitempty"`
Triggers []string `json:"triggers,omitempty"`
FilterRepositories []string `json:"filter_repositories,omitempty"`
ReplaceBreaks *bool `json:"replace_breaks,omitempty"`
DisableReferences bool `json:"disable_references,omitempty"`
PluralFormat string `json:"plural_format,omitempty"`
PlaceholderFormat string `json:"placeholder_format,omitempty"`
WebhookURL string `json:"webhook_url,omitempty"`
LanguageMapping []LanguageMapping `json:"language_mapping,omitempty"`
ICUNumeric bool `json:"icu_numeric,omitempty"`
EscapePercent bool `json:"escape_percent,omitempty"`
Indentation string `json:"indentation,omitempty"`
YAMLIncludeRoot bool `json:"yaml_include_root,omitempty"`
JSONUnescapedSlashes bool `json:"json_unescaped_slashes,omitempty"`
JavaPropertiesEncoding string `json:"java_properties_encoding,omitempty"`
JavaPropertiesSeparator string `json:"java_properties_separator,omitempty"`
BundleDescription string `json:"bundle_description,omitempty"`
}
type LanguageMapping struct {
OriginalLangISO string `json:"original_language_iso"`
CustomLangISO string `json:"custom_language_iso"`
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Service request/response objects
// _____________________________________________________________________________________________________________________
type FilesResponse struct {
Paged
WithProjectID
Files []File `json:"files"`
}
type FileUploadResponse struct {
WithProjectID
Process QueuedProcess `json:"process"`
}
type FileDownloadResponse struct {
WithProjectID
BundleURL string `json:"bundle_url"`
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Service methods
// _____________________________________________________________________________________________________________________
func (c *FileService) List(projectID string) (r FilesResponse, err error) {
resp, err := c.getWithOptions(c.Ctx(), fmt.Sprintf("%s/%s/%s", pathProjects, projectID, pathFiles), &r, c.ListOpts())
if err != nil {
return
}
applyPaged(resp, &r.Paged)
return r, apiError(resp)
}
func (c *FileService) Upload(projectID string, file FileUpload) (r FileUploadResponse, err error) {
if file.CustomTranslationStatusSkippedKeys == nil {
file.CustomTranslationStatusSkippedKeys = Bool(false)
}
if file.CustomTranslationStatusUpdatedKeys == nil {
file.CustomTranslationStatusUpdatedKeys = Bool(true)
}
if file.CustomTranslationStatusInsertedKeys == nil {
file.CustomTranslationStatusInsertedKeys = Bool(true)
}
file.Queue = true
resp, err := c.post(c.Ctx(), fmt.Sprintf("%s/%s/%s/%s", pathProjects, projectID, pathFiles, "upload"), &r, file)
if err != nil {
return
}
return r, apiError(resp)
}
func (c *FileService) Download(projectID string, downloadOptions FileDownload) (r FileDownloadResponse, err error) {
url := fmt.Sprintf("%s/%s/%s/%s", pathProjects, projectID, pathFiles, "download")
resp, err := c.post(c.Ctx(), url, &r, downloadOptions)
if err != nil {
return
}
return r, apiError(resp)
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Additional service structs & methods
// _____________________________________________________________________________________________________________________
type FileListOptions struct {
Limit uint `url:"limit,omitempty"`
Page uint `url:"page,omitempty"`
Filename string `url:"filter_filename,omitempty"`
}
func (options FileListOptions) Apply(req *resty.Request) {
v, _ := query.Values(options)
req.SetQueryString(v.Encode())
}
func (c *FileService) ListOpts() FileListOptions { return c.opts }
func (c *FileService) SetListOptions(o FileListOptions) { c.opts = o }
func (c *FileService) WithListOptions(o FileListOptions) *FileService {
c.opts = o
return c
}