crowdin-api 0.4.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +5 -5
  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 +139 -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 +114 -267
  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/languages.rb +81 -0
  18. data/lib/crowdin-api/api-resources/projects.rb +134 -0
  19. data/lib/crowdin-api/api-resources/source_files.rb +303 -0
  20. data/lib/crowdin-api/api-resources/source_strings.rb +74 -0
  21. data/lib/crowdin-api/api-resources/storages.rb +102 -0
  22. data/lib/crowdin-api/api-resources/translation_status.rb +89 -0
  23. data/lib/crowdin-api/api-resources/translations.rb +160 -0
  24. data/lib/crowdin-api/api-resources/workflows.rb +59 -0
  25. data/lib/crowdin-api/client/client.rb +82 -0
  26. data/lib/crowdin-api/client/configuration.rb +44 -0
  27. data/lib/crowdin-api/client/version.rb +7 -0
  28. data/lib/crowdin-api/core/api_errors_raiser.rb +29 -0
  29. data/lib/crowdin-api/core/errors.rb +7 -0
  30. data/lib/crowdin-api/core/request.rb +115 -0
  31. data/lib/crowdin-api.rb +23 -127
  32. data/spec/core/config-instance_spec.rb +72 -0
  33. data/spec/crowdin-api_spec.rb +7 -0
  34. data/spec/spec_helper.rb +9 -0
  35. metadata +129 -57
  36. data/lib/crowdin-api/errors.rb +0 -23
  37. data/lib/crowdin-api/methods.rb +0 -427
  38. data/lib/crowdin-api/version.rb +0 -5
@@ -0,0 +1,134 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crowdin
4
+ module ApiResources
5
+ module Projects
6
+ def list_projects(query = {})
7
+ request = Web::Request.new(
8
+ self,
9
+ :get,
10
+ '/projects',
11
+ query
12
+ )
13
+
14
+ request.perform
15
+ end
16
+
17
+ def add_project(query = {})
18
+ request = Web::Request.new(
19
+ self,
20
+ :post,
21
+ '/projects',
22
+ query
23
+ )
24
+
25
+ request.perform
26
+ end
27
+
28
+ def get_project(project_id = nil)
29
+ project_id || raise_parameter_is_required_error(:project_id)
30
+
31
+ request = Web::Request.new(
32
+ self,
33
+ :get,
34
+ "/projects/#{project_id}"
35
+ )
36
+
37
+ request.perform
38
+ end
39
+
40
+ def delete_project(project_id = nil)
41
+ project_id || raise_parameter_is_required_error(:project_id)
42
+
43
+ request = Web::Request.new(
44
+ self,
45
+ :delete,
46
+ "/projects/#{project_id}"
47
+ )
48
+
49
+ request.perform
50
+ end
51
+
52
+ def edit_project(project_id = nil, query = {})
53
+ project_id || raise_parameter_is_required_error(:project_id)
54
+
55
+ request = Web::Request.new(
56
+ self,
57
+ :patch,
58
+ "/projects/#{project_id}",
59
+ query
60
+ )
61
+
62
+ request.perform
63
+ end
64
+
65
+ # For Enterprise mode only
66
+
67
+ def list_groups(query = {})
68
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
69
+
70
+ request = Web::Request.new(
71
+ self,
72
+ :get,
73
+ '/groups',
74
+ query
75
+ )
76
+
77
+ request.perform
78
+ end
79
+
80
+ def add_group(query = {})
81
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
82
+
83
+ request = Web::Request.new(
84
+ self,
85
+ :post,
86
+ '/groups',
87
+ query
88
+ )
89
+
90
+ request.perform
91
+ end
92
+
93
+ def get_group(group_id = nil)
94
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
95
+ group_id || raise_parameter_is_required_error(:group_id)
96
+
97
+ request = Web::Request.new(
98
+ self,
99
+ :get,
100
+ "/groups/#{group_id}"
101
+ )
102
+
103
+ request.perform
104
+ end
105
+
106
+ def delete_group(group_id = nil)
107
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
108
+ group_id || raise_parameter_is_required_error(:group_id)
109
+
110
+ request = Web::Request.new(
111
+ self,
112
+ :delete,
113
+ "/groups/#{group_id}"
114
+ )
115
+
116
+ request.perform
117
+ end
118
+
119
+ def edit_group(group_id = nil, query = {})
120
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
121
+ group_id || raise_parameter_is_required_error(:group_id)
122
+
123
+ request = Web::Request.new(
124
+ self,
125
+ :patch,
126
+ "/groups/#{group_id}",
127
+ query
128
+ )
129
+
130
+ request.perform
131
+ end
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,303 @@
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
+ # Add custom language.
152
+ #
153
+ # === Parameters
154
+ #
155
+ # * +:projectId+ [Integer] - Project Identifier. Get via list_projects. Can be initialized with the Crowdin Client
156
+ # * +:storageId+ [Integer] - Storage Identifier. Get via list_storages
157
+ # * +:name+ [String] - File name. Note: Can't contain \ / : * ? " < > | symbols. ZIP files are not allowed.
158
+ #
159
+ # === Example
160
+ #
161
+ # when you're initialized Crowdin Client with a project_id
162
+ #
163
+ # crowdin.add_file(storage_id: your_storage_id, name: 'your_filename')
164
+ #
165
+ # or you can specify project_id
166
+ #
167
+ # crowdin.add_file({ storage_id: your_storage_id, name: 'your_filename' }, your_project_id)
168
+ #
169
+ def add_file(query = {}, project_id = config.project_id)
170
+ project_id || raise_project_id_is_required_error
171
+
172
+ request = Web::Request.new(
173
+ self,
174
+ :post,
175
+ "/projects/#{project_id}/files",
176
+ query
177
+ )
178
+
179
+ request.perform
180
+ end
181
+
182
+ def get_file(file_id = nil, project_id = config.project_id)
183
+ file_id || raise_parameter_is_required_error(:file_id)
184
+ project_id || raise_project_id_is_required_error
185
+
186
+ request = Web::Request.new(
187
+ self,
188
+ :get,
189
+ "/projects/#{project_id}/files/#{file_id}"
190
+ )
191
+
192
+ request.perform
193
+ end
194
+
195
+ def update_or_restore_file(file_id = nil, query = {}, project_id = config.project_id)
196
+ file_id || raise_parameter_is_required_error(:file_id)
197
+ project_id || raise_project_id_is_required_error
198
+
199
+ request = Web::Request.new(
200
+ self,
201
+ :put,
202
+ "/projects/#{project_id}/files/#{file_id}",
203
+ query
204
+ )
205
+
206
+ request.perform
207
+ end
208
+
209
+ def delete_file(file_id = nil, project_id = config.project_id)
210
+ file_id || raise_parameter_is_required_error(:file_id)
211
+ project_id || raise_project_id_is_required_error
212
+
213
+ request = Web::Request.new(
214
+ self,
215
+ :delete,
216
+ "/projects/#{project_id}/files/#{file_id}"
217
+ )
218
+
219
+ request.perform
220
+ end
221
+
222
+ def edit_file(file_id = nil, query = {}, project_id = config.project_id)
223
+ file_id || raise_parameter_is_required_error(:file_id)
224
+ project_id || raise_project_id_is_required_error
225
+
226
+ request = Web::Request.new(
227
+ self,
228
+ :patch,
229
+ "/projects/#{project_id}/files/#{file_id}",
230
+ query
231
+ )
232
+
233
+ request.perform
234
+ end
235
+
236
+ def download_file(destination = nil, file_id = nil, project_id = config.project_id)
237
+ destination || raise_parameter_is_required_error(:destination)
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
+ # List file revisions.
254
+ #
255
+ # === Parameters
256
+ #
257
+ # * +:projectId+ [Integer] - Project Identifier. Get via list_projects. Can be initialized with the Crowdin Client
258
+ # * +:fileId+ [Integer] - File Identifier. Get via list_files
259
+ #
260
+ # Optional:
261
+ # * +:limit+ [Integer 1..500] - A maximum number of items to retrieve, default - 25
262
+ # * +:offset+ [Integer >= 0] - A starting offset in the collection, default - 0
263
+ #
264
+ # === Example
265
+ #
266
+ # when you're initialized Crowdin Client with a project_id
267
+ #
268
+ # crowdin.list_file_revisions(your_file_id, limit: your_value)
269
+ #
270
+ # or you can specify project_id
271
+ #
272
+ # crowdin.list_file_revisions(your_file_id, { limit: your_value }, your_project_id)
273
+ #
274
+ def list_file_revisions(file_id = nil, query = {}, project_id = config.project_id)
275
+ file_id || raise_parameter_is_required_error(:file_id)
276
+ project_id || raise_project_id_is_required_error
277
+
278
+ request = Web::Request.new(
279
+ self,
280
+ :get,
281
+ "/projects/#{project_id}/files/#{file_id}/revisions",
282
+ query
283
+ )
284
+
285
+ request.perform
286
+ end
287
+
288
+ def get_file_revision(file_id = nil, revision_id = nil, project_id = config.project_id)
289
+ file_id || raise_parameter_is_required_error(:file_id)
290
+ revision_id || raise_parameter_is_required_error(:revision_id)
291
+ project_id || raise_project_id_is_required_error
292
+
293
+ request = Web::Request.new(
294
+ self,
295
+ :get,
296
+ "/projects/#{project_id}/files/#{file_id}/revisions/#{revision_id}"
297
+ )
298
+
299
+ request.perform
300
+ end
301
+ end
302
+ end
303
+ 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,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crowdin
4
+ module ApiResources
5
+ module Storages
6
+ # Get storages list.
7
+ #
8
+ # === Parameters
9
+ #
10
+ # Optional:
11
+ # * +:limit+ [Integer 1..500] - A maximum number of items to retrieve, default - 25
12
+ # * +:offset+ [Integer >= 0] - A starting offset in the collection, default - 0
13
+ #
14
+ # === Example
15
+ #
16
+ # crowdin.list_projects(limit: your_value)
17
+ #
18
+ def list_storages(query = {})
19
+ request = Web::Request.new(
20
+ self,
21
+ :get,
22
+ '/storages',
23
+ query
24
+ )
25
+
26
+ request.perform
27
+ end
28
+
29
+ # Add storage.
30
+ #
31
+ # === Parameters
32
+ #
33
+ # * +File+ - File class object or path to file
34
+ #
35
+ # === Example
36
+ #
37
+ # crowdin.add_storage(File.open('your_filename.extension', 'r'))
38
+ # or
39
+ # crowdin.add_storage('your_filename.extension')
40
+ #
41
+ def add_storage(file = nil)
42
+ file || raise_parameter_is_required_error(:file)
43
+
44
+ file = file.is_a?(File) ? file : File.open(file, 'r')
45
+
46
+ request = Web::Request.new(
47
+ self,
48
+ :post,
49
+ '/storages',
50
+ file,
51
+ { 'Content-Type' => 'application/octet-stream', 'Crowdin-API-FileName' => File.basename(file) }
52
+ )
53
+
54
+ request.perform
55
+ end
56
+
57
+ # Get storage information.
58
+ #
59
+ # === Parameters
60
+ #
61
+ # * +:storage_id+ [Integer] - Storage Identifier. Get via list_storages
62
+ #
63
+ # === Example
64
+ #
65
+ # crowdin.get_storage(your_storage_id)
66
+ #
67
+ def get_storage(storage_id = nil)
68
+ storage_id || raise_parameter_is_required_error(:storage_id)
69
+
70
+ request = Web::Request.new(
71
+ self,
72
+ :get,
73
+ "/storages/#{storage_id}"
74
+ )
75
+
76
+ request.perform
77
+ end
78
+
79
+ # Delete storage.
80
+ #
81
+ # === Parameters
82
+ #
83
+ # * +:storage_id+ [Integer] - Storage Identifier. Get via list_storages
84
+ #
85
+ # === Example
86
+ #
87
+ # crowdin.delete_storage(your_storage_id)
88
+ #
89
+ def delete_storage(storage_id = nil)
90
+ storage_id || raise_parameter_is_required_error(:storage_id)
91
+
92
+ request = Web::Request.new(
93
+ self,
94
+ :delete,
95
+ "/storages/#{storage_id}"
96
+ )
97
+
98
+ request.perform
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crowdin
4
+ module ApiResources
5
+ module TranslationStatus
6
+ def get_branch_progress(branch_id = nil, query = {}, project_id = config.project_id)
7
+ branch_id || raise_parameter_is_required_error(:branch_id)
8
+ project_id || raise_project_id_is_required_error
9
+
10
+ request = Web::Request.new(
11
+ self,
12
+ :get,
13
+ "/projects/#{project_id}/branches/#{branch_id}/languages/progress",
14
+ query
15
+ )
16
+
17
+ request.perform
18
+ end
19
+
20
+ def get_directory_progress(directory_id = nil, query = {}, project_id = config.project_id)
21
+ directory_id || raise_parameter_is_required_error(:directory_id)
22
+ project_id || raise_project_id_is_required_error
23
+
24
+ request = Web::Request.new(
25
+ self,
26
+ :get,
27
+ "/projects/#{project_id}/directories/#{directory_id}/languages/progress",
28
+ query
29
+ )
30
+
31
+ request.perform
32
+ end
33
+
34
+ def get_file_progress(file_id = nil, query = {}, project_id = config.project_id)
35
+ file_id || raise_parameter_is_required_error(:file_id)
36
+ project_id || raise_project_id_is_required_error
37
+
38
+ request = Web::Request.new(
39
+ self,
40
+ :get,
41
+ "/projects/#{project_id}/files/#{file_id}/languages/progress",
42
+ query
43
+ )
44
+
45
+ request.perform
46
+ end
47
+
48
+ def get_language_progress(language_id = nil, query = {}, project_id = config.project_id)
49
+ language_id || raise_parameter_is_required_error(:language_id)
50
+ project_id || raise_project_id_is_required_error
51
+
52
+ request = Web::Request.new(
53
+ self,
54
+ :get,
55
+ "/projects/#{project_id}/languages/#{language_id}/progress",
56
+ query
57
+ )
58
+
59
+ request.perform
60
+ end
61
+
62
+ def get_project_progress(query = {}, project_id = config.project_id)
63
+ project_id || raise_project_id_is_required_error
64
+
65
+ request = Web::Request.new(
66
+ self,
67
+ :get,
68
+ "/projects/#{project_id}/languages/progress",
69
+ query
70
+ )
71
+
72
+ request.perform
73
+ end
74
+
75
+ def get_qa_progress(query = {}, project_id = config.project_id)
76
+ project_id || raise_project_id_is_required_error
77
+
78
+ request = Web::Request.new(
79
+ self,
80
+ :get,
81
+ "/projects/#{project_id}/qa-checks",
82
+ query
83
+ )
84
+
85
+ request.perform
86
+ end
87
+ end
88
+ end
89
+ end