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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build-and-publish.yml +30 -0
  3. data/.github/workflows/test-and-lint.yml +31 -0
  4. data/.gitignore +12 -0
  5. data/.rspec +2 -0
  6. data/.rubocop.yml +5 -0
  7. data/.rubocop_todo.yml +146 -0
  8. data/CODE_OF_CONDUCT.md +128 -0
  9. data/CONTRIBUTING.md +71 -0
  10. data/Gemfile +5 -0
  11. data/LICENSE +1 -1
  12. data/README.md +120 -280
  13. data/Rakefile +19 -0
  14. data/bin/crowdin-console +54 -0
  15. data/bin/setup +6 -0
  16. data/crowdin-api.gemspec +33 -0
  17. data/lib/crowdin-api/api-resources/dictionaries.rb +34 -0
  18. data/lib/crowdin-api/api-resources/distributions.rb +99 -0
  19. data/lib/crowdin-api/api-resources/glossaries.rb +217 -0
  20. data/lib/crowdin-api/api-resources/labels.rb +117 -0
  21. data/lib/crowdin-api/api-resources/languages.rb +82 -0
  22. data/lib/crowdin-api/api-resources/machine_translation_engines.rb +74 -0
  23. data/lib/crowdin-api/api-resources/projects.rb +148 -0
  24. data/lib/crowdin-api/api-resources/reports.rb +138 -0
  25. data/lib/crowdin-api/api-resources/screenshots.rb +186 -0
  26. data/lib/crowdin-api/api-resources/source_files.rb +304 -0
  27. data/lib/crowdin-api/api-resources/source_strings.rb +74 -0
  28. data/lib/crowdin-api/api-resources/storages.rb +106 -0
  29. data/lib/crowdin-api/api-resources/string_comments.rb +73 -0
  30. data/lib/crowdin-api/api-resources/string_translations.rb +220 -0
  31. data/lib/crowdin-api/api-resources/tasks.rb +113 -0
  32. data/lib/crowdin-api/api-resources/teams.rb +144 -0
  33. data/lib/crowdin-api/api-resources/translation_memory.rb +145 -0
  34. data/lib/crowdin-api/api-resources/translation_status.rb +89 -0
  35. data/lib/crowdin-api/api-resources/translations.rb +161 -0
  36. data/lib/crowdin-api/api-resources/users.rb +129 -0
  37. data/lib/crowdin-api/api-resources/vendors.rb +21 -0
  38. data/lib/crowdin-api/api-resources/webhooks.rb +73 -0
  39. data/lib/crowdin-api/api-resources/workflows.rb +62 -0
  40. data/lib/crowdin-api/client/client.rb +95 -0
  41. data/lib/crowdin-api/client/configuration.rb +48 -0
  42. data/lib/crowdin-api/client/version.rb +7 -0
  43. data/lib/crowdin-api/core/errors.rb +8 -0
  44. data/lib/crowdin-api/core/errors_raisers.rb +39 -0
  45. data/lib/crowdin-api/core/request.rb +118 -0
  46. data/lib/crowdin-api/core/utils.rb +10 -0
  47. data/lib/crowdin-api.rb +39 -126
  48. data/spec/client/client-instance_spec.rb +14 -0
  49. data/spec/client/configuration-instance_spec.rb +72 -0
  50. data/spec/spec_helper.rb +9 -0
  51. metadata +130 -47
  52. data/lib/crowdin-api/errors.rb +0 -23
  53. data/lib/crowdin-api/methods.rb +0 -452
  54. data/lib/crowdin-api/version.rb +0 -5
@@ -0,0 +1,304 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crowdin
4
+ module ApiResources
5
+ module SourceFiles
6
+ def list_branches(query = {}, project_id = config.project_id)
7
+ project_id || raise_project_id_is_required_error
8
+
9
+ request = Web::Request.new(
10
+ self,
11
+ :get,
12
+ "/projects/#{project_id}/branches",
13
+ query
14
+ )
15
+
16
+ request.perform
17
+ end
18
+
19
+ def add_branch(query = {}, project_id = config.project_id)
20
+ project_id || raise_project_id_is_required_error
21
+
22
+ request = Web::Request.new(
23
+ self,
24
+ :post,
25
+ "/projects/#{project_id}/branches",
26
+ query
27
+ )
28
+
29
+ request.perform
30
+ end
31
+
32
+ def get_branch(branch_id = nil, project_id = config.project_id)
33
+ branch_id || raise_parameter_is_required_error(:branch_id)
34
+ project_id || raise_project_id_is_required_error
35
+
36
+ request = Web::Request.new(
37
+ self,
38
+ :get,
39
+ "/projects/#{project_id}/branches/#{branch_id}"
40
+ )
41
+
42
+ request.perform
43
+ end
44
+
45
+ def delete_branch(branch_id = nil, project_id = config.project_id)
46
+ branch_id || raise_parameter_is_required_error(:branch_id)
47
+ project_id || raise_project_id_is_required_error
48
+
49
+ request = Web::Request.new(
50
+ self,
51
+ :delete,
52
+ "/projects/#{project_id}/branches/#{branch_id}"
53
+ )
54
+
55
+ request.perform
56
+ end
57
+
58
+ def edit_branch(branch_id = nil, query = {}, project_id = config.project_id)
59
+ branch_id || raise_parameter_is_required_error(:branch_id)
60
+ project_id || raise_project_id_is_required_error
61
+
62
+ request = Web::Request.new(
63
+ self,
64
+ :patch,
65
+ "/projects/#{project_id}/branches/#{branch_id}",
66
+ query
67
+ )
68
+
69
+ request.perform
70
+ end
71
+
72
+ def list_directories(query = {}, project_id = config.project_id)
73
+ project_id || raise_project_id_is_required_error
74
+
75
+ request = Web::Request.new(
76
+ self,
77
+ :get,
78
+ "/projects/#{project_id}/directories",
79
+ query
80
+ )
81
+
82
+ request.perform
83
+ end
84
+
85
+ def add_directory(query = {}, project_id = config.project_id)
86
+ project_id || raise_project_id_is_required_error
87
+
88
+ request = Web::Request.new(
89
+ self,
90
+ :post,
91
+ "/projects/#{project_id}/directories",
92
+ query
93
+ )
94
+
95
+ request.perform
96
+ end
97
+
98
+ def get_directory(directory_id = nil, project_id = config.project_id)
99
+ directory_id || raise_parameter_is_required_error(:directory_id)
100
+ project_id || raise_project_id_is_required_error
101
+
102
+ request = Web::Request.new(
103
+ self,
104
+ :get,
105
+ "/projects/#{project_id}/directories/#{directory_id}"
106
+ )
107
+
108
+ request.perform
109
+ end
110
+
111
+ def delete_directory(directory_id = nil, project_id = config.project_id)
112
+ directory_id || raise_parameter_is_required_error(:directory_id)
113
+ project_id || raise_project_id_is_required_error
114
+
115
+ request = Web::Request.new(
116
+ self,
117
+ :delete,
118
+ "/projects/#{project_id}/directories/#{directory_id}"
119
+ )
120
+
121
+ request.perform
122
+ end
123
+
124
+ def edit_directory(directory_id = nil, query = {}, project_id = config.project_id)
125
+ directory_id || raise_parameter_is_required_error(:directory_id)
126
+ project_id || raise_project_id_is_required_error
127
+
128
+ request = Web::Request.new(
129
+ self,
130
+ :patch,
131
+ "/projects/#{project_id}/directories/#{directory_id}",
132
+ query
133
+ )
134
+
135
+ request.perform
136
+ end
137
+
138
+ def list_files(query = {}, project_id = config.project_id)
139
+ project_id || raise_project_id_is_required_error
140
+
141
+ request = Web::Request.new(
142
+ self,
143
+ :get,
144
+ "/projects/#{project_id}/files",
145
+ query
146
+ )
147
+
148
+ request.perform
149
+ end
150
+
151
+ #
152
+ # Add custom language.
153
+ #
154
+ # === Parameters
155
+ #
156
+ # * +:projectId+ [Integer] - Project Identifier. Get via list_projects. Can be initialized with the Crowdin Client
157
+ # * +:storageId+ [Integer] - Storage Identifier. Get via list_storages
158
+ # * +:name+ [String] - File name. Note: Can't contain \ / : * ? " < > | symbols. ZIP files are not allowed.
159
+ #
160
+ # === Example
161
+ #
162
+ # when you're initialized Crowdin Client with a project_id
163
+ #
164
+ # crowdin.add_file(storage_id: your_storage_id, name: 'your_filename')
165
+ #
166
+ # or you can specify project_id
167
+ #
168
+ # crowdin.add_file({ storage_id: your_storage_id, name: 'your_filename' }, your_project_id)
169
+ #
170
+ def add_file(query = {}, project_id = config.project_id)
171
+ project_id || raise_project_id_is_required_error
172
+
173
+ request = Web::Request.new(
174
+ self,
175
+ :post,
176
+ "/projects/#{project_id}/files",
177
+ query
178
+ )
179
+
180
+ request.perform
181
+ end
182
+
183
+ def get_file(file_id = nil, project_id = config.project_id)
184
+ file_id || raise_parameter_is_required_error(:file_id)
185
+ project_id || raise_project_id_is_required_error
186
+
187
+ request = Web::Request.new(
188
+ self,
189
+ :get,
190
+ "/projects/#{project_id}/files/#{file_id}"
191
+ )
192
+
193
+ request.perform
194
+ end
195
+
196
+ def update_or_restore_file(file_id = nil, query = {}, project_id = config.project_id)
197
+ file_id || raise_parameter_is_required_error(:file_id)
198
+ project_id || raise_project_id_is_required_error
199
+
200
+ request = Web::Request.new(
201
+ self,
202
+ :put,
203
+ "/projects/#{project_id}/files/#{file_id}",
204
+ query
205
+ )
206
+
207
+ request.perform
208
+ end
209
+
210
+ def delete_file(file_id = nil, project_id = config.project_id)
211
+ file_id || raise_parameter_is_required_error(:file_id)
212
+ project_id || raise_project_id_is_required_error
213
+
214
+ request = Web::Request.new(
215
+ self,
216
+ :delete,
217
+ "/projects/#{project_id}/files/#{file_id}"
218
+ )
219
+
220
+ request.perform
221
+ end
222
+
223
+ def edit_file(file_id = nil, query = {}, project_id = config.project_id)
224
+ file_id || raise_parameter_is_required_error(:file_id)
225
+ project_id || raise_project_id_is_required_error
226
+
227
+ request = Web::Request.new(
228
+ self,
229
+ :patch,
230
+ "/projects/#{project_id}/files/#{file_id}",
231
+ query
232
+ )
233
+
234
+ request.perform
235
+ end
236
+
237
+ def download_file(file_id = nil, destination = nil, project_id = config.project_id)
238
+ file_id || raise_parameter_is_required_error(:file_id)
239
+ project_id || raise_project_id_is_required_error
240
+
241
+ request = Web::Request.new(
242
+ self,
243
+ :get,
244
+ "/projects/#{project_id}/files/#{file_id}/download",
245
+ {},
246
+ {},
247
+ destination
248
+ )
249
+
250
+ request.perform
251
+ end
252
+
253
+ #
254
+ # List file revisions.
255
+ #
256
+ # === Parameters
257
+ #
258
+ # * +:projectId+ [Integer] - Project Identifier. Get via list_projects. Can be initialized with the Crowdin Client
259
+ # * +:fileId+ [Integer] - File Identifier. Get via list_files
260
+ #
261
+ # Optional:
262
+ # * +:limit+ [Integer 1..500] - A maximum number of items to retrieve, default - 25
263
+ # * +:offset+ [Integer >= 0] - A starting offset in the collection, default - 0
264
+ #
265
+ # === Example
266
+ #
267
+ # when you're initialized Crowdin Client with a project_id
268
+ #
269
+ # crowdin.list_file_revisions(your_file_id, limit: your_value)
270
+ #
271
+ # or you can specify project_id
272
+ #
273
+ # crowdin.list_file_revisions(your_file_id, { limit: your_value }, your_project_id)
274
+ #
275
+ def list_file_revisions(file_id = nil, query = {}, project_id = config.project_id)
276
+ file_id || raise_parameter_is_required_error(:file_id)
277
+ project_id || raise_project_id_is_required_error
278
+
279
+ request = Web::Request.new(
280
+ self,
281
+ :get,
282
+ "/projects/#{project_id}/files/#{file_id}/revisions",
283
+ query
284
+ )
285
+
286
+ request.perform
287
+ end
288
+
289
+ def get_file_revision(file_id = nil, revision_id = nil, project_id = config.project_id)
290
+ file_id || raise_parameter_is_required_error(:file_id)
291
+ revision_id || raise_parameter_is_required_error(:revision_id)
292
+ project_id || raise_project_id_is_required_error
293
+
294
+ request = Web::Request.new(
295
+ self,
296
+ :get,
297
+ "/projects/#{project_id}/files/#{file_id}/revisions/#{revision_id}"
298
+ )
299
+
300
+ request.perform
301
+ end
302
+ end
303
+ end
304
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crowdin
4
+ module ApiResources
5
+ module SourceStrings
6
+ def list_strings(query = {}, project_id = config.project_id)
7
+ project_id || raise_project_id_is_required_error
8
+
9
+ request = Web::Request.new(
10
+ self,
11
+ :get,
12
+ "/projects/#{project_id}/strings",
13
+ query
14
+ )
15
+
16
+ request.perform
17
+ end
18
+
19
+ def add_string(query = {}, project_id = config.project_id)
20
+ project_id || raise_project_id_is_required_error
21
+
22
+ request = Web::Request.new(
23
+ self,
24
+ :post,
25
+ "/projects/#{project_id}/strings",
26
+ query
27
+ )
28
+
29
+ request.perform
30
+ end
31
+
32
+ def get_string(string_id = nil, query = {}, project_id = config.project_id)
33
+ string_id || raise_parameter_is_required_error(:string_id)
34
+ project_id || raise_project_id_is_required_error
35
+
36
+ request = Web::Request.new(
37
+ self,
38
+ :get,
39
+ "/projects/#{project_id}/strings/#{string_id}",
40
+ query
41
+ )
42
+
43
+ request.perform
44
+ end
45
+
46
+ def delete_string(string_id = nil, project_id = config.project_id)
47
+ string_id || raise_parameter_is_required_error(:string_id)
48
+ project_id || raise_project_id_is_required_error
49
+
50
+ request = Web::Request.new(
51
+ self,
52
+ :delete,
53
+ "/projects/#{project_id}/strings/#{string_id}"
54
+ )
55
+
56
+ request.perform
57
+ end
58
+
59
+ def edit_string(string_id = nil, query = {}, project_id = config.project_id)
60
+ string_id || raise_parameter_is_required_error(:string_id)
61
+ project_id || raise_project_id_is_required_error
62
+
63
+ request = Web::Request.new(
64
+ self,
65
+ :patch,
66
+ "/projects/#{project_id}/strings/#{string_id}",
67
+ query
68
+ )
69
+
70
+ request.perform
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crowdin
4
+ module ApiResources
5
+ module Storages
6
+ #
7
+ # Get storages list.
8
+ #
9
+ # === Parameters
10
+ #
11
+ # Optional:
12
+ # * +:limit+ [Integer 1..500] - A maximum number of items to retrieve, default - 25
13
+ # * +:offset+ [Integer >= 0] - A starting offset in the collection, default - 0
14
+ #
15
+ # === Example
16
+ #
17
+ # crowdin.list_projects(limit: your_value)
18
+ #
19
+ def list_storages(query = {})
20
+ request = Web::Request.new(
21
+ self,
22
+ :get,
23
+ '/storages',
24
+ query
25
+ )
26
+
27
+ request.perform
28
+ end
29
+
30
+ #
31
+ # Add storage.
32
+ #
33
+ # === Parameters
34
+ #
35
+ # * +File+ - File class object or full path to file
36
+ #
37
+ # === Example
38
+ #
39
+ # crowdin.add_storage(File.open('your_filename.extension', 'r'))
40
+ # or
41
+ # crowdin.add_storage('your_filename.extension')
42
+ #
43
+ def add_storage(file = nil)
44
+ file || raise_parameter_is_required_error(:file)
45
+
46
+ file = file.is_a?(File) ? file : File.open(file, 'r')
47
+
48
+ request = Web::Request.new(
49
+ self,
50
+ :post,
51
+ '/storages',
52
+ file,
53
+ { 'Content-Type' => 'application/octet-stream', 'Crowdin-API-FileName' => File.basename(file) }
54
+ )
55
+
56
+ request.perform
57
+ end
58
+
59
+ #
60
+ # Get storage information.
61
+ #
62
+ # === Parameters
63
+ #
64
+ # * +:storage_id+ [Integer] - Storage Identifier. Get via list_storages
65
+ #
66
+ # === Example
67
+ #
68
+ # crowdin.get_storage(your_storage_id)
69
+ #
70
+ def get_storage(storage_id = nil)
71
+ storage_id || raise_parameter_is_required_error(:storage_id)
72
+
73
+ request = Web::Request.new(
74
+ self,
75
+ :get,
76
+ "/storages/#{storage_id}"
77
+ )
78
+
79
+ request.perform
80
+ end
81
+
82
+ #
83
+ # Delete storage.
84
+ #
85
+ # === Parameters
86
+ #
87
+ # * +:storage_id+ [Integer] - Storage Identifier. Get via list_storages
88
+ #
89
+ # === Example
90
+ #
91
+ # crowdin.delete_storage(your_storage_id)
92
+ #
93
+ def delete_storage(storage_id = nil)
94
+ storage_id || raise_parameter_is_required_error(:storage_id)
95
+
96
+ request = Web::Request.new(
97
+ self,
98
+ :delete,
99
+ "/storages/#{storage_id}"
100
+ )
101
+
102
+ request.perform
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crowdin
4
+ module ApiResources
5
+ module StringComments
6
+ def list_string_comments(query = {}, project_id = config.project_id)
7
+ project_id || raise_project_id_is_required_error
8
+
9
+ request = Web::Request.new(
10
+ self,
11
+ :get,
12
+ "/projects/#{project_id}/comments",
13
+ query
14
+ )
15
+
16
+ request.perform
17
+ end
18
+
19
+ def add_string_comment(query = {}, project_id = config.project_id)
20
+ project_id || raise_project_id_is_required_error
21
+
22
+ request = Web::Request.new(
23
+ self,
24
+ :post,
25
+ "/projects/#{project_id}/comments",
26
+ query
27
+ )
28
+
29
+ request.perform
30
+ end
31
+
32
+ def get_string_comment(string_comment_id = nil, project_id = config.project_id)
33
+ string_comment_id || raise_parameter_is_required_error(:string_comment_id)
34
+ project_id || raise_project_id_is_required_error
35
+
36
+ request = Web::Request.new(
37
+ self,
38
+ :get,
39
+ "/projects/#{project_id}/comments/#{string_comment_id}"
40
+ )
41
+
42
+ request.perform
43
+ end
44
+
45
+ def delete_string_comment(string_comment_id = nil, project_id = config.project_id)
46
+ string_comment_id || raise_parameter_is_required_error(:string_comment_id)
47
+ project_id || raise_project_id_is_required_error
48
+
49
+ request = Web::Request.new(
50
+ self,
51
+ :delete,
52
+ "/projects/#{project_id}/comments/#{string_comment_id}"
53
+ )
54
+
55
+ request.perform
56
+ end
57
+
58
+ def edit_string_comment(string_comment_id = nil, query = {}, project_id = config.project_id)
59
+ string_comment_id || raise_parameter_is_required_error(:string_comment_id)
60
+ project_id || raise_project_id_is_required_error
61
+
62
+ request = Web::Request.new(
63
+ self,
64
+ :patch,
65
+ "/projects/#{project_id}/comments/#{string_comment_id}",
66
+ query
67
+ )
68
+
69
+ request.perform
70
+ end
71
+ end
72
+ end
73
+ end