crowdin-api 0.6.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build-and-publish.yml +30 -0
- data/.github/workflows/test-and-lint.yml +31 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +5 -0
- data/.rubocop_todo.yml +146 -0
- data/CODE_OF_CONDUCT.md +128 -0
- data/CONTRIBUTING.md +71 -0
- data/Gemfile +5 -0
- data/LICENSE +1 -1
- data/README.md +120 -280
- data/Rakefile +19 -0
- data/bin/crowdin-console +54 -0
- data/bin/setup +6 -0
- data/crowdin-api.gemspec +33 -0
- data/lib/crowdin-api/api-resources/dictionaries.rb +34 -0
- data/lib/crowdin-api/api-resources/distributions.rb +99 -0
- data/lib/crowdin-api/api-resources/glossaries.rb +217 -0
- data/lib/crowdin-api/api-resources/labels.rb +117 -0
- data/lib/crowdin-api/api-resources/languages.rb +82 -0
- data/lib/crowdin-api/api-resources/machine_translation_engines.rb +74 -0
- data/lib/crowdin-api/api-resources/projects.rb +148 -0
- data/lib/crowdin-api/api-resources/reports.rb +138 -0
- data/lib/crowdin-api/api-resources/screenshots.rb +186 -0
- data/lib/crowdin-api/api-resources/source_files.rb +304 -0
- data/lib/crowdin-api/api-resources/source_strings.rb +74 -0
- data/lib/crowdin-api/api-resources/storages.rb +106 -0
- data/lib/crowdin-api/api-resources/string_comments.rb +73 -0
- data/lib/crowdin-api/api-resources/string_translations.rb +220 -0
- data/lib/crowdin-api/api-resources/tasks.rb +113 -0
- data/lib/crowdin-api/api-resources/teams.rb +144 -0
- data/lib/crowdin-api/api-resources/translation_memory.rb +145 -0
- data/lib/crowdin-api/api-resources/translation_status.rb +89 -0
- data/lib/crowdin-api/api-resources/translations.rb +161 -0
- data/lib/crowdin-api/api-resources/users.rb +129 -0
- data/lib/crowdin-api/api-resources/vendors.rb +21 -0
- data/lib/crowdin-api/api-resources/webhooks.rb +73 -0
- data/lib/crowdin-api/api-resources/workflows.rb +62 -0
- data/lib/crowdin-api/client/client.rb +95 -0
- data/lib/crowdin-api/client/configuration.rb +48 -0
- data/lib/crowdin-api/client/version.rb +7 -0
- data/lib/crowdin-api/core/errors.rb +8 -0
- data/lib/crowdin-api/core/errors_raisers.rb +39 -0
- data/lib/crowdin-api/core/request.rb +118 -0
- data/lib/crowdin-api/core/utils.rb +10 -0
- data/lib/crowdin-api.rb +39 -126
- data/spec/client/client-instance_spec.rb +14 -0
- data/spec/client/configuration-instance_spec.rb +72 -0
- data/spec/spec_helper.rb +9 -0
- metadata +130 -47
- data/lib/crowdin-api/errors.rb +0 -23
- data/lib/crowdin-api/methods.rb +0 -452
- data/lib/crowdin-api/version.rb +0 -5
data/lib/crowdin-api/errors.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module Crowdin
|
2
|
-
class API
|
3
|
-
|
4
|
-
module Errors
|
5
|
-
class Error < StandardError
|
6
|
-
attr_reader :error_code
|
7
|
-
attr_reader :error_message
|
8
|
-
attr_reader :message
|
9
|
-
|
10
|
-
def initialize(error_code, error_message)
|
11
|
-
@error_code = error_code.to_i
|
12
|
-
@error_message = error_message
|
13
|
-
@message = "#{error_code}: #{error_message}"
|
14
|
-
end
|
15
|
-
|
16
|
-
def to_s
|
17
|
-
@message
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
data/lib/crowdin-api/methods.rb
DELETED
@@ -1,452 +0,0 @@
|
|
1
|
-
module Crowdin
|
2
|
-
# A wrapper and interface to the Crowdin api. Please visit the Crowdin developers
|
3
|
-
# site for a full explaination of what each of the Crowdin api methods
|
4
|
-
# expect and perform.
|
5
|
-
#
|
6
|
-
# https://crowdin.com/page/api
|
7
|
-
|
8
|
-
class API
|
9
|
-
|
10
|
-
# Add new file to Crowdin project.
|
11
|
-
#
|
12
|
-
# == Parameters
|
13
|
-
#
|
14
|
-
# files - Array of files that should be added to Crowdin project.
|
15
|
-
# file is a Hash { :dest, :source, :title, :export_pattern }
|
16
|
-
# * :dest - file name with path in Crowdin project (required)
|
17
|
-
# * :source - path for uploaded file (required)
|
18
|
-
# * :title - title in Crowdin UI (optional)
|
19
|
-
# * :export_pattern - Resulted file name (optional)
|
20
|
-
#
|
21
|
-
# Optional:
|
22
|
-
# * :branch - a branch name.
|
23
|
-
# If the branch is not exists Crowdin will be return an error:
|
24
|
-
# "error":{
|
25
|
-
# "code":8,
|
26
|
-
# "message":"File was not found"
|
27
|
-
# }
|
28
|
-
#
|
29
|
-
# == Request
|
30
|
-
#
|
31
|
-
# POST https://api.crowdin.com/api/project/{project-identifier}/add-file?key={project-key}
|
32
|
-
#
|
33
|
-
def add_file(files, params = {})
|
34
|
-
params[:files] = Hash[files.map { |f| [
|
35
|
-
f[:dest] || raise(ArgumentError, "'`:dest`' is required"),
|
36
|
-
::File.open(f[:source] || raise(ArgumentError, "'`:source` is required'"))
|
37
|
-
] }]
|
38
|
-
|
39
|
-
params[:titles] = Hash[files.map { |f| [f[:dest], f[:title]] }]
|
40
|
-
params[:titles].delete_if { |_, v| v.nil? }
|
41
|
-
|
42
|
-
params[:export_patterns] = Hash[files.map { |f| [f[:dest], f[:export_pattern]] }]
|
43
|
-
params[:export_patterns].delete_if { |_, v| v.nil? }
|
44
|
-
|
45
|
-
params.delete_if { |_, v| v.respond_to?(:empty?) ? !!v.empty? : !v }
|
46
|
-
|
47
|
-
request(
|
48
|
-
:method => :post,
|
49
|
-
:path => "/api/project/#{@project_id}/add-file",
|
50
|
-
:query => params,
|
51
|
-
)
|
52
|
-
end
|
53
|
-
|
54
|
-
# Upload fresh version of your localization file to Crowdin.
|
55
|
-
#
|
56
|
-
# == Parameters
|
57
|
-
#
|
58
|
-
# files - Array of files that should be updated in Crowdin project.
|
59
|
-
# file is a Hash { :dest, :source }
|
60
|
-
# * :dest - file name with path in Crowdin project (required)
|
61
|
-
# * :source - path for uploaded file (required)
|
62
|
-
# * :title - title in Crowdin UI (optional)
|
63
|
-
# * :export_pattern - Resulted file name (optional)
|
64
|
-
#
|
65
|
-
# Optional:
|
66
|
-
# * :branch - a branch name
|
67
|
-
#
|
68
|
-
# == Request
|
69
|
-
#
|
70
|
-
# POST https://api.crowdin.com/api/project/{project-identifier}/update-file?key={project-key}
|
71
|
-
#
|
72
|
-
def update_file(files, params = {})
|
73
|
-
params[:files] = Hash[files.map { |f|
|
74
|
-
dest = f[:dest] || raise(ArgumentError, "'`:dest` is required'")
|
75
|
-
source = ::File.open(f[:source] || raise(ArgumentError, "'`:source` is required'"))
|
76
|
-
source.define_singleton_method(:original_filename) do
|
77
|
-
dest
|
78
|
-
end
|
79
|
-
[dest, source]
|
80
|
-
}]
|
81
|
-
|
82
|
-
params[:titles] = Hash[files.map { |f| [f[:dest], f[:title]] }]
|
83
|
-
params[:titles].delete_if { |_, v| v.nil? }
|
84
|
-
|
85
|
-
params[:export_patterns] = Hash[files.map { |f| [f[:dest], f[:export_pattern]] }]
|
86
|
-
params[:export_patterns].delete_if { |_, v| v.nil? }
|
87
|
-
|
88
|
-
params.delete_if { |_, v| v.respond_to?(:empty?) ? !!v.empty? : !v }
|
89
|
-
|
90
|
-
request(
|
91
|
-
:method => :post,
|
92
|
-
:path => "/api/project/#{@project_id}/update-file",
|
93
|
-
:query => params,
|
94
|
-
)
|
95
|
-
end
|
96
|
-
|
97
|
-
# Upload existing translations to your Crowdin project.
|
98
|
-
#
|
99
|
-
# == Parameters
|
100
|
-
#
|
101
|
-
# files - Array of files that should be added to Crowdin project.
|
102
|
-
# file is a Hash { :dest, :source }
|
103
|
-
# * :dest - file name with path in Crowdin project (required)
|
104
|
-
# * :source - path for uploaded file (required)
|
105
|
-
# language - Target language. With a single call it's possible to upload translations for several
|
106
|
-
# files but only into one of the languages. (required)
|
107
|
-
#
|
108
|
-
# Optional:
|
109
|
-
# * :import_duplicates (default: false)
|
110
|
-
# * :import_eq_suggestions (default: false)
|
111
|
-
# * :auto_approve_imported (default: false)
|
112
|
-
# * :branch - a branch name
|
113
|
-
#
|
114
|
-
# == Request
|
115
|
-
#
|
116
|
-
# POST https://api.crowdin.com/api/project/{project-identifier}/upload-translation?key={project-key}
|
117
|
-
#
|
118
|
-
def upload_translation(files, language, params = {})
|
119
|
-
params[:files] = Hash[files.map { |f| [
|
120
|
-
f[:dest] || raise(ArgumentError, "`:dest` is required"),
|
121
|
-
::File.open(f[:source] || raise(ArgumentError, "`:source` is required"))
|
122
|
-
] }]
|
123
|
-
|
124
|
-
params[:language] = language
|
125
|
-
|
126
|
-
request(
|
127
|
-
:method => :post,
|
128
|
-
:path => "/api/project/#{@project_id}/upload-translation",
|
129
|
-
:query => params,
|
130
|
-
)
|
131
|
-
end
|
132
|
-
|
133
|
-
# Download ZIP file with translations. You can choose the language of translation you need or download all of them at once.
|
134
|
-
#
|
135
|
-
# Note: If you would like to download the most recent translations you may want to use export API method before downloading.
|
136
|
-
#
|
137
|
-
# Optional:
|
138
|
-
# * :output - a name of ZIP file with translations
|
139
|
-
# * :branch - a branch name
|
140
|
-
#
|
141
|
-
# == Request
|
142
|
-
#
|
143
|
-
# GET https://api.crowdin.com/api/project/{project-identifier}/download/{package}.zip?key={project-key}
|
144
|
-
#
|
145
|
-
def download_translation(language = 'all', params = {})
|
146
|
-
request(
|
147
|
-
:method => :get,
|
148
|
-
:path => "/api/project/#{@project_id}/download/#{language}.zip",
|
149
|
-
:output => params.delete(:output),
|
150
|
-
:query => params,
|
151
|
-
)
|
152
|
-
end
|
153
|
-
|
154
|
-
# Upload your glossarries for Crowdin Project in TBX file format.
|
155
|
-
#
|
156
|
-
# == Request
|
157
|
-
#
|
158
|
-
# POST https://api.crowdin.com/api/project/{project-identifier}/upload-glossary?key={project-key}
|
159
|
-
#
|
160
|
-
def upload_glossary(file)
|
161
|
-
# raise "#{path} file does not exist" unless ::File.exist?(path)
|
162
|
-
file = ::File.open(file, 'rb')
|
163
|
-
|
164
|
-
request(
|
165
|
-
:method => :post,
|
166
|
-
:path => "/api/project/#{@project_id}/upload-glossary",
|
167
|
-
:query => { :file => file },
|
168
|
-
)
|
169
|
-
end
|
170
|
-
|
171
|
-
# Upload your Translation Memory for Crowdin Project in TMX file format.
|
172
|
-
#
|
173
|
-
# == Request
|
174
|
-
#
|
175
|
-
# POST https://api.crowdin.com/api/project/{project-identifier}/upload-tm?key={project-key}
|
176
|
-
#
|
177
|
-
def upload_tm(file)
|
178
|
-
file = ::File.open(file, 'rb')
|
179
|
-
|
180
|
-
request(
|
181
|
-
:method => :post,
|
182
|
-
:path => "/api/project/#{@project_id}/upload-tm",
|
183
|
-
:query => { :file => file },
|
184
|
-
)
|
185
|
-
end
|
186
|
-
|
187
|
-
# Add directory to Crowdin project.
|
188
|
-
#
|
189
|
-
# == Parameters
|
190
|
-
#
|
191
|
-
# name - directory name (with path if nested directory should be created). (required)
|
192
|
-
#
|
193
|
-
# Optional:
|
194
|
-
# * :is_branch - create new branch. Valid values - 0, 1. Only when create root directory.
|
195
|
-
# * :branch - a branch name.
|
196
|
-
#
|
197
|
-
# == Request
|
198
|
-
#
|
199
|
-
# POST https://api.crowdin.com/api/project/{project-identifier}/add-directory?key={project-key}
|
200
|
-
#
|
201
|
-
def add_directory(name, params = {})
|
202
|
-
params[:name] = name
|
203
|
-
|
204
|
-
request(
|
205
|
-
:method => :post,
|
206
|
-
:path => "/api/project/#{@project_id}/add-directory",
|
207
|
-
:query => params,
|
208
|
-
)
|
209
|
-
end
|
210
|
-
|
211
|
-
# Delete Crowdin project directory. All nested files and directories will be deleted too.
|
212
|
-
#
|
213
|
-
# == Parameters
|
214
|
-
#
|
215
|
-
# name - Directory path (or just name if the directory is in root) (required)
|
216
|
-
# :branch - a branch name (optional)
|
217
|
-
#
|
218
|
-
# FIXME
|
219
|
-
# When you try to remove the branch directory Crowdin will be return an error:
|
220
|
-
# "error":{
|
221
|
-
# "code":17,
|
222
|
-
# "message":"Specified directory was not found"
|
223
|
-
# }
|
224
|
-
#
|
225
|
-
# == Request
|
226
|
-
#
|
227
|
-
# POST https://api.crowdin.com/api/project/{project-identifier}/delete-directory?key={project-key}
|
228
|
-
#
|
229
|
-
def delete_directory(name, params = {})
|
230
|
-
params[:name] = name
|
231
|
-
|
232
|
-
request(
|
233
|
-
:method => :post,
|
234
|
-
:path => "/api/project/#{@project_id}/delete-directory",
|
235
|
-
:query => params,
|
236
|
-
)
|
237
|
-
end
|
238
|
-
|
239
|
-
|
240
|
-
# Rename or change directory attributes.
|
241
|
-
#
|
242
|
-
# == Parameters
|
243
|
-
#
|
244
|
-
# name - Full directory path that should be modified (e.g. /MainPage/AboutUs).
|
245
|
-
#
|
246
|
-
# Optional:
|
247
|
-
# * :new_name - new directory name (not contain path, name only)
|
248
|
-
# * :title - new directory title to be displayed in Crowdin UI
|
249
|
-
# * :export_pattern - new directory export pattern
|
250
|
-
# * :branch - a branch name
|
251
|
-
#
|
252
|
-
# == Request
|
253
|
-
#
|
254
|
-
# POST https://api.crowdin.com/api/project/{project-identifier}/change-directory?key={project-key}
|
255
|
-
#
|
256
|
-
def change_directory(name, params = {})
|
257
|
-
params[:name] = name
|
258
|
-
|
259
|
-
request(
|
260
|
-
:method => :post,
|
261
|
-
:path => "/api/project/#{@project_id}/change-directory",
|
262
|
-
:query => params,
|
263
|
-
)
|
264
|
-
end
|
265
|
-
|
266
|
-
|
267
|
-
# Delete file from Crowdin project. All the translations will be lost without ability to restore them.
|
268
|
-
#
|
269
|
-
# == Request
|
270
|
-
#
|
271
|
-
# POST https://api.crowdin.com/api/project/{project-identifier}/delete-file?key={project-key}
|
272
|
-
#
|
273
|
-
def delete_file(file)
|
274
|
-
request(
|
275
|
-
:method => :post,
|
276
|
-
:path => "/api/project/#{@project_id}/delete-file",
|
277
|
-
:query => { :file => file },
|
278
|
-
)
|
279
|
-
end
|
280
|
-
|
281
|
-
# Download Crowdin project glossaries as TBX file.
|
282
|
-
#
|
283
|
-
# == Request
|
284
|
-
#
|
285
|
-
# GET https://api.crowdin.com/api/project/{project-identifier}/download-glossary?key={project-key}
|
286
|
-
#
|
287
|
-
def download_glossary(params = {})
|
288
|
-
request(
|
289
|
-
:method => :get,
|
290
|
-
:path => "/api/project/#{@project_id}/download-glossary",
|
291
|
-
:output => params[:output],
|
292
|
-
)
|
293
|
-
end
|
294
|
-
|
295
|
-
# Download Crowdin project Translation Memory as TMX file.
|
296
|
-
#
|
297
|
-
# == Request
|
298
|
-
#
|
299
|
-
# GET https://api.crowdin.com/api/project/{project-identifier}/download-tm?key={project-key}
|
300
|
-
#
|
301
|
-
def download_tm(params = {})
|
302
|
-
request(
|
303
|
-
:method => :get,
|
304
|
-
:path => "/api/project/#{@project_id}/download-tm",
|
305
|
-
:output => params[:output],
|
306
|
-
)
|
307
|
-
end
|
308
|
-
|
309
|
-
# Export a single translated file from Crowdin.
|
310
|
-
#
|
311
|
-
# == Parameters
|
312
|
-
#
|
313
|
-
# file - File name with path in Crowdin project. (required)
|
314
|
-
# language - Target language. (required)
|
315
|
-
#
|
316
|
-
# Optional:
|
317
|
-
# * :branch - a branch name
|
318
|
-
#
|
319
|
-
# == Request
|
320
|
-
#
|
321
|
-
# GET https://api.crowdin.com/api/project/{project-identifier}/export-file?key={project-key}
|
322
|
-
#
|
323
|
-
def export_file(file, language, params = {})
|
324
|
-
params[:file] = file
|
325
|
-
params[:language] = language
|
326
|
-
request(
|
327
|
-
:method => :get,
|
328
|
-
:path => "/api/project/#{@project_id}/export-file",
|
329
|
-
:output => params.delete(:output),
|
330
|
-
:query => params,
|
331
|
-
)
|
332
|
-
end
|
333
|
-
|
334
|
-
# Build ZIP archive with the latest translations.
|
335
|
-
#
|
336
|
-
# Please note that this method can be invoked only every 30 minutes.
|
337
|
-
# Also API call will be ignored if there were no any changes in project since last export.
|
338
|
-
#
|
339
|
-
# Optional:
|
340
|
-
# * :branch - a branch name
|
341
|
-
#
|
342
|
-
# == Request
|
343
|
-
#
|
344
|
-
# GET https://api.crowdin.com/api/project/{project-identifier}/export?key={project-key}
|
345
|
-
#
|
346
|
-
def export_translations(params = {})
|
347
|
-
request(
|
348
|
-
:method => :get,
|
349
|
-
:path => "/api/project/#{@project_id}/export",
|
350
|
-
:query => params,
|
351
|
-
)
|
352
|
-
end
|
353
|
-
|
354
|
-
|
355
|
-
# Get supported languages list with Crowdin codes mapped to locale name and standarded codes.
|
356
|
-
#
|
357
|
-
# == Request
|
358
|
-
#
|
359
|
-
# GET https://api.crowdin.com/api/project/{project-identifier}/supported-languages?key={project-key}
|
360
|
-
#
|
361
|
-
def supported_languages
|
362
|
-
request(
|
363
|
-
:method => :get,
|
364
|
-
:path => "/api/project/#{@project_id}/supported-languages",
|
365
|
-
)
|
366
|
-
end
|
367
|
-
|
368
|
-
# Track your Crowdin project translation progress by language.
|
369
|
-
#
|
370
|
-
# == Request
|
371
|
-
#
|
372
|
-
# POST https://api.crowdin.com/api/project/{project-identifier}/status?key={project-key}
|
373
|
-
#
|
374
|
-
def translations_status
|
375
|
-
request(
|
376
|
-
:method => :post,
|
377
|
-
:path => "/api/project/#{@project_id}/status",
|
378
|
-
)
|
379
|
-
end
|
380
|
-
|
381
|
-
# Get Crowdin Project details.
|
382
|
-
#
|
383
|
-
# == Request
|
384
|
-
#
|
385
|
-
# POST https://api.crowdin.com/api/project/{project-identifier}/info?key={project-key}
|
386
|
-
#
|
387
|
-
def project_info
|
388
|
-
request(
|
389
|
-
:method => :post,
|
390
|
-
:path => "/api/project/#{@project_id}/info",
|
391
|
-
)
|
392
|
-
end
|
393
|
-
|
394
|
-
# Create new Crowdin project.
|
395
|
-
# Important: The API method requires Account API Key. This key can not be found on your profile pages.
|
396
|
-
#
|
397
|
-
# == Request
|
398
|
-
#
|
399
|
-
# POST https://api.crowdin.com/api/account/create-project?account-key={account-key}
|
400
|
-
#
|
401
|
-
def create_project(params = {})
|
402
|
-
request(
|
403
|
-
:method => :post,
|
404
|
-
:path => "/api/account/create-project",
|
405
|
-
:query => params,
|
406
|
-
)
|
407
|
-
end
|
408
|
-
|
409
|
-
# Edit Crowdin project.
|
410
|
-
#
|
411
|
-
# == Request
|
412
|
-
#
|
413
|
-
# POST https://api.crowdin.com/api/project/{project-identifier}/edit-project?key={key}
|
414
|
-
#
|
415
|
-
def edit_project(params = {})
|
416
|
-
request(
|
417
|
-
:method => :post,
|
418
|
-
:path => "/api/project/#{@project_id}/edit-project",
|
419
|
-
:query => params,
|
420
|
-
)
|
421
|
-
end
|
422
|
-
|
423
|
-
# Delete Crowdin project with all translations.
|
424
|
-
#
|
425
|
-
# == Request
|
426
|
-
#
|
427
|
-
# POST https://api.crowdin.com/api/project/{project-identifier}/delete-project?key={project-key}
|
428
|
-
#
|
429
|
-
def delete_project
|
430
|
-
request(
|
431
|
-
:method => :post,
|
432
|
-
:path => "/api/project/#{@project_id}/delete-project",
|
433
|
-
)
|
434
|
-
end
|
435
|
-
|
436
|
-
# Get Crowdin Project details.
|
437
|
-
# Important: The API method requires Account API Key. This key can not be found on your profile pages.
|
438
|
-
#
|
439
|
-
# == Request
|
440
|
-
#
|
441
|
-
# GET https://api.crowdin.com/api/account/get-projects?account-key={account-key}
|
442
|
-
#
|
443
|
-
def get_projects(login)
|
444
|
-
request(
|
445
|
-
:method => :get,
|
446
|
-
:path => "/api/account/get-projects",
|
447
|
-
:query => { :login => login },
|
448
|
-
)
|
449
|
-
end
|
450
|
-
|
451
|
-
end
|
452
|
-
end
|