crowdin-api 0.5.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- 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 +139 -0
- data/CODE_OF_CONDUCT.md +128 -0
- data/CONTRIBUTING.md +71 -0
- data/Gemfile +5 -0
- data/LICENSE +1 -1
- data/README.md +114 -267
- 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/languages.rb +81 -0
- data/lib/crowdin-api/api-resources/projects.rb +134 -0
- data/lib/crowdin-api/api-resources/source_files.rb +303 -0
- data/lib/crowdin-api/api-resources/source_strings.rb +74 -0
- data/lib/crowdin-api/api-resources/storages.rb +102 -0
- data/lib/crowdin-api/api-resources/translation_status.rb +89 -0
- data/lib/crowdin-api/api-resources/translations.rb +162 -0
- data/lib/crowdin-api/api-resources/workflows.rb +59 -0
- data/lib/crowdin-api/client/client.rb +82 -0
- data/lib/crowdin-api/client/configuration.rb +44 -0
- data/lib/crowdin-api/client/version.rb +7 -0
- data/lib/crowdin-api/core/api_errors_raiser.rb +29 -0
- data/lib/crowdin-api/core/errors.rb +7 -0
- data/lib/crowdin-api/core/request.rb +118 -0
- data/lib/crowdin-api.rb +23 -126
- data/spec/core/config-instance_spec.rb +72 -0
- data/spec/crowdin-api_spec.rb +7 -0
- data/spec/spec_helper.rb +9 -0
- metadata +112 -40
- data/lib/crowdin-api/errors.rb +0 -23
- data/lib/crowdin-api/methods.rb +0 -427
- data/lib/crowdin-api/version.rb +0 -5
data/lib/crowdin-api/methods.rb
DELETED
@@ -1,427 +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
|
-
# Build ZIP archive with the latest translations.
|
310
|
-
#
|
311
|
-
# Please note that this method can be invoked only every 30 minutes.
|
312
|
-
# Also API call will be ignored if there were no any changes in project since last export.
|
313
|
-
#
|
314
|
-
# Optional:
|
315
|
-
# * :branch - a branch name
|
316
|
-
#
|
317
|
-
# == Request
|
318
|
-
#
|
319
|
-
# GET https://api.crowdin.com/api/project/{project-identifier}/export?key={project-key}
|
320
|
-
#
|
321
|
-
def export_translations(params = {})
|
322
|
-
request(
|
323
|
-
:method => :get,
|
324
|
-
:path => "/api/project/#{@project_id}/export",
|
325
|
-
:query => params,
|
326
|
-
)
|
327
|
-
end
|
328
|
-
|
329
|
-
|
330
|
-
# Get supported languages list with Crowdin codes mapped to locale name and standarded codes.
|
331
|
-
#
|
332
|
-
# == Request
|
333
|
-
#
|
334
|
-
# GET https://api.crowdin.com/api/project/{project-identifier}/supported-languages?key={project-key}
|
335
|
-
#
|
336
|
-
def supported_languages
|
337
|
-
request(
|
338
|
-
:method => :get,
|
339
|
-
:path => "/api/project/#{@project_id}/supported-languages",
|
340
|
-
)
|
341
|
-
end
|
342
|
-
|
343
|
-
# Track your Crowdin project translation progress by language.
|
344
|
-
#
|
345
|
-
# == Request
|
346
|
-
#
|
347
|
-
# POST https://api.crowdin.com/api/project/{project-identifier}/status?key={project-key}
|
348
|
-
#
|
349
|
-
def translations_status
|
350
|
-
request(
|
351
|
-
:method => :post,
|
352
|
-
:path => "/api/project/#{@project_id}/status",
|
353
|
-
)
|
354
|
-
end
|
355
|
-
|
356
|
-
# Get Crowdin Project details.
|
357
|
-
#
|
358
|
-
# == Request
|
359
|
-
#
|
360
|
-
# POST https://api.crowdin.com/api/project/{project-identifier}/info?key={project-key}
|
361
|
-
#
|
362
|
-
def project_info
|
363
|
-
request(
|
364
|
-
:method => :post,
|
365
|
-
:path => "/api/project/#{@project_id}/info",
|
366
|
-
)
|
367
|
-
end
|
368
|
-
|
369
|
-
# Create new Crowdin project.
|
370
|
-
# Important: The API method requires Account API Key. This key can not be found on your profile pages.
|
371
|
-
#
|
372
|
-
# == Request
|
373
|
-
#
|
374
|
-
# POST https://api.crowdin.com/api/account/create-project?account-key={account-key}
|
375
|
-
#
|
376
|
-
def create_project(params = {})
|
377
|
-
request(
|
378
|
-
:method => :post,
|
379
|
-
:path => "/api/account/create-project",
|
380
|
-
:query => params,
|
381
|
-
)
|
382
|
-
end
|
383
|
-
|
384
|
-
# Edit Crowdin project.
|
385
|
-
#
|
386
|
-
# == Request
|
387
|
-
#
|
388
|
-
# POST https://api.crowdin.com/api/project/{project-identifier}/edit-project?key={key}
|
389
|
-
#
|
390
|
-
def edit_project(params = {})
|
391
|
-
request(
|
392
|
-
:method => :post,
|
393
|
-
:path => "/api/project/#{@project_id}/edit-project",
|
394
|
-
:query => params,
|
395
|
-
)
|
396
|
-
end
|
397
|
-
|
398
|
-
# Delete Crowdin project with all translations.
|
399
|
-
#
|
400
|
-
# == Request
|
401
|
-
#
|
402
|
-
# POST https://api.crowdin.com/api/project/{project-identifier}/delete-project?key={project-key}
|
403
|
-
#
|
404
|
-
def delete_project
|
405
|
-
request(
|
406
|
-
:method => :post,
|
407
|
-
:path => "/api/project/#{@project_id}/delete-project",
|
408
|
-
)
|
409
|
-
end
|
410
|
-
|
411
|
-
# Get Crowdin Project details.
|
412
|
-
# Important: The API method requires Account API Key. This key can not be found on your profile pages.
|
413
|
-
#
|
414
|
-
# == Request
|
415
|
-
#
|
416
|
-
# GET https://api.crowdin.com/api/account/get-projects?account-key={account-key}
|
417
|
-
#
|
418
|
-
def get_projects(login)
|
419
|
-
request(
|
420
|
-
:method => :get,
|
421
|
-
:path => "/api/account/get-projects",
|
422
|
-
:query => { :login => login },
|
423
|
-
)
|
424
|
-
end
|
425
|
-
|
426
|
-
end
|
427
|
-
end
|