crowdin-api 0.4.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,127 @@
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(ArgumentError, ':project_id is required')
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(ArgumentError, ':project_id is required')
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(ArgumentError, ':project_id is required')
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 API only
66
+
67
+ def list_groups(query = {})
68
+ request = Web::Request.new(
69
+ self,
70
+ :get,
71
+ '/groups',
72
+ query
73
+ )
74
+
75
+ request.perform
76
+ end
77
+
78
+ def add_group(query = {})
79
+ request = Web::Request.new(
80
+ self,
81
+ :post,
82
+ '/groups',
83
+ query
84
+ )
85
+
86
+ request.perform
87
+ end
88
+
89
+ def get_group(group_id = nil)
90
+ group_id || raise(ArgumentError, ':group_id is required')
91
+
92
+ request = Web::Request.new(
93
+ self,
94
+ :get,
95
+ "/groups/#{group_id}"
96
+ )
97
+
98
+ request.perform
99
+ end
100
+
101
+ def delete_group(group_id = nil)
102
+ group_id || raise(ArgumentError, ':group_id is required')
103
+
104
+ request = Web::Request.new(
105
+ self,
106
+ :delete,
107
+ "/groups/#{group_id}"
108
+ )
109
+
110
+ request.perform
111
+ end
112
+
113
+ def edit_group(group_id = nil, query = {})
114
+ group_id || raise(ArgumentError, ':group_id is required')
115
+
116
+ request = Web::Request.new(
117
+ self,
118
+ :patch,
119
+ "/groups/#{group_id}",
120
+ query
121
+ )
122
+
123
+ request.perform
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,313 @@
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(ArgumentError, ':project_id is required in parameters or when initialize Client')
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(ArgumentError, ':project_id is required in parameters or when initialize Client')
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(ArgumentError, ':branch_id is required')
34
+ project_id || raise(ArgumentError, ':project_id is required in parameters or when initialize Client')
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(ArgumentError, ':branch_id is required')
47
+ project_id || raise(ArgumentError, ':project_id is required in parameters or when initialize Client')
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 = {})
59
+ project_id = query[:project_id] || config.project_id
60
+
61
+ branch_id || raise(ArgumentError, ':branch_id is required')
62
+ project_id || raise(ArgumentError, ':project_id is required in parameters or when initialize Client')
63
+
64
+ request = Web::Request.new(
65
+ self,
66
+ :patch,
67
+ "/projects/#{project_id}/branches/#{branch_id}",
68
+ query
69
+ )
70
+
71
+ request.perform
72
+ end
73
+
74
+ def list_directories(query = {}, project_id = config.project_id)
75
+ project_id || raise(ArgumentError, ':project_id is required in parameters or when initialize Client')
76
+
77
+ request = Web::Request.new(
78
+ self,
79
+ :get,
80
+ "/projects/#{project_id}/directories",
81
+ query
82
+ )
83
+
84
+ request.perform
85
+ end
86
+
87
+ def add_directory(query = {}, project_id = config.project_id)
88
+ project_id || raise(ArgumentError, ':project_id is required in parameters or when initialize Client')
89
+
90
+ request = Web::Request.new(
91
+ self,
92
+ :post,
93
+ "/projects/#{project_id}/directories",
94
+ query
95
+ )
96
+
97
+ request.perform
98
+ end
99
+
100
+ def get_directory(directory_id = nil, project_id = config.project_id)
101
+ directory_id || raise(ArgumentError, ':directory_id is required')
102
+ project_id || raise(ArgumentError, ':project_id is required in parameters or when initialize Client')
103
+
104
+ request = Web::Request.new(
105
+ self,
106
+ :get,
107
+ "/projects/#{project_id}/directories/#{directory_id}"
108
+ )
109
+
110
+ request.perform
111
+ end
112
+
113
+ def delete_directory(directory_id = nil, project_id = config.project_id)
114
+ directory_id || raise(ArgumentError, ':directory_id is required')
115
+ project_id || raise(ArgumentError, ':project_id is required in parameters or when initialize Client')
116
+
117
+ request = Web::Request.new(
118
+ self,
119
+ :delete,
120
+ "/projects/#{project_id}/directories/#{directory_id}"
121
+ )
122
+
123
+ request.perform
124
+ end
125
+
126
+ def edit_directory(directory_id = nil, query = {})
127
+ project_id = query[:project_id] || config.project_id
128
+
129
+ directory_id || raise(ArgumentError, ':directory_id is required')
130
+ project_id || raise(ArgumentError, ':project_id is required in parameters or when initialize Client')
131
+
132
+ request = Web::Request.new(
133
+ self,
134
+ :patch,
135
+ "/projects/#{project_id}/directories/#{directory_id}",
136
+ query
137
+ )
138
+
139
+ request.perform
140
+ end
141
+
142
+ def list_files(query = {}, project_id = config.project_id)
143
+ project_id || raise(ArgumentError, ':project_id is required in parameters or when initialize Client')
144
+
145
+ request = Web::Request.new(
146
+ self,
147
+ :get,
148
+ "/projects/#{project_id}/files",
149
+ query
150
+ )
151
+
152
+ request.perform
153
+ end
154
+
155
+ # Add custom language.
156
+ #
157
+ # === Parameters
158
+ #
159
+ # * +:projectId+ [Integer] - Project Identifier. Get via list_projects. Can be initialized with the Crowdin Client
160
+ # * +:storageId+ [Integer] - Storage Identifier. Get via list_storages
161
+ # * +:name+ [String] - File name. Note: Can't contain \ / : * ? " < > | symbols. ZIP files are not allowed.
162
+ #
163
+ # === Example
164
+ #
165
+ # when you're initialized Crowdin Client with a project_id
166
+ #
167
+ # crowdin.add_file(storage_id: your_storage_id, name: 'your_filename')
168
+ #
169
+ # or you can use the specified project_id
170
+ #
171
+ # crowdin.add_file({}, your_project_id)
172
+ #
173
+ def add_file(query = {}, project_id = config.project_id)
174
+ project_id || raise(ArgumentError, ':project_id is required in parameters or when initialize Client')
175
+
176
+ request = Web::Request.new(
177
+ self,
178
+ :post,
179
+ "/projects/#{project_id}/files",
180
+ query
181
+ )
182
+
183
+ request.perform
184
+ end
185
+
186
+ def get_file(file_id = nil, project_id = config.project_id)
187
+ file_id || raise(ArgumentError, ':file_id is required')
188
+ project_id || raise(ArgumentError, ':project_id is required in parameters or when initialize Client')
189
+
190
+ request = Web::Request.new(
191
+ self,
192
+ :get,
193
+ "/projects/#{project_id}/files/#{file_id}"
194
+ )
195
+
196
+ request.perform
197
+ end
198
+
199
+ def update_or_restore_file(file_id = nil, query = {})
200
+ project_id = query[:project_id] || config.project_id
201
+
202
+ file_id || raise(ArgumentError, ':file_id is required')
203
+ project_id || raise(ArgumentError, ':project_id is required in parameters or when initialize Client')
204
+
205
+ request = Web::Request.new(
206
+ self,
207
+ :put,
208
+ "/projects/#{project_id}/files/#{file_id}",
209
+ query
210
+ )
211
+
212
+ request.perform
213
+ end
214
+
215
+ def delete_file(file_id = nil, project_id = config.project_id)
216
+ file_id || raise(ArgumentError, ':file_id is required')
217
+ project_id || raise(ArgumentError, ':project_id is required in parameters or when initialize Client')
218
+
219
+ request = Web::Request.new(
220
+ self,
221
+ :delete,
222
+ "/projects/#{project_id}/files/#{file_id}"
223
+ )
224
+
225
+ request.perform
226
+ end
227
+
228
+ def edit_file(file_id = nil, query = {})
229
+ project_id = query[:project_id] || config.project_id
230
+
231
+ file_id || raise(ArgumentError, ':file_id is required')
232
+ project_id || raise(ArgumentError, ':project_id is required in parameters or when initialize Client')
233
+
234
+ request = Web::Request.new(
235
+ self,
236
+ :patch,
237
+ "/projects/#{project_id}/files/#{file_id}",
238
+ query
239
+ )
240
+
241
+ request.perform
242
+ end
243
+
244
+ def download_file(destination = nil, file_id = nil, project_id = config.project_id)
245
+ destination || raise(ArgumentError, ':destination is required for downlaods')
246
+ file_id || raise(ArgumentError, ':file_id is required')
247
+ project_id || raise(ArgumentError, ':project_id is required in parameters or when initialize Client')
248
+
249
+ request = Web::Request.new(
250
+ self,
251
+ :get,
252
+ "/projects/#{project_id}/files/#{file_id}/download",
253
+ {},
254
+ {},
255
+ destination
256
+ )
257
+
258
+ request.perform
259
+ end
260
+
261
+ # List file revisions.
262
+ #
263
+ # === Parameters
264
+ #
265
+ # * +:projectId+ [Integer] - Project Identifier. Get via list_projects. Can be initialized with the Crowdin Client
266
+ # * +:fileId+ [Integer] - File Identifier. Get via list_files
267
+ #
268
+ # Optional:
269
+ # * +:limit+ [Integer 1..500] - A maximum number of items to retrieve, default - 25
270
+ # * +:offset+ [Integer >= 0] - A starting offset in the collection, default - 0
271
+ #
272
+ # === Example
273
+ #
274
+ # when you're initialized Crowdin Client with a project_id
275
+ #
276
+ # crowdin.list_file_revisions(your_file_id, { limit: your_value })
277
+ #
278
+ # or you can use the specified project_id
279
+ #
280
+ # crowdin.list_file_revisions(your_file_id, { project_id: your_project_id ..})
281
+ #
282
+ def list_file_revisions(file_id = nil, query = {})
283
+ project_id = query[:project_id] || config.project_id
284
+
285
+ file_id || raise(ArgumentError, ':file_id is required')
286
+ project_id || raise(ArgumentError, ':project_id is required in parameters or when initialize Client')
287
+
288
+ request = Web::Request.new(
289
+ self,
290
+ :get,
291
+ "/projects/#{project_id}/files/#{file_id}/revisions",
292
+ query
293
+ )
294
+
295
+ request.perform
296
+ end
297
+
298
+ def get_file_revision(file_id = nil, revision_id = nil, project_id = config.project_id)
299
+ file_id || raise(ArgumentError, ':file_id is required')
300
+ revision_id || raise(ArgumentError, ':revision_id is required')
301
+ project_id || raise(ArgumentError, ':project_id is required in parameters or when initialize Client')
302
+
303
+ request = Web::Request.new(
304
+ self,
305
+ :get,
306
+ "/projects/#{project_id}/files/#{file_id}/revisions/#{revision_id}"
307
+ )
308
+
309
+ request.perform
310
+ end
311
+ end
312
+ end
313
+ 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'))
38
+ # or
39
+ # crowdin.add_storage('your_filename.extension')
40
+ #
41
+ def add_storage(file = nil)
42
+ file || raise(ArgumentError, ':file is required')
43
+
44
+ file = file.is_a?(File) ? file : File.open(file)
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(ArgumentError, ':storage_id is required')
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(ArgumentError, ':storage_id is required')
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,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crowdin
4
+ module ApiResources
5
+ module TranslationStatus
6
+ def get_branch_progress(branch_id = nil, query = {})
7
+ project_id = query[:project_id] || config.project_id
8
+
9
+ branch_id || raise(ArgumentError, ':file_id is required')
10
+ project_id || raise(ArgumentError, ':project_id is required in parameters or when initialize Client')
11
+
12
+ request = Web::Request.new(
13
+ self,
14
+ :get,
15
+ "/projects/#{project_id}/branches/#{branch_id}/languages/progress",
16
+ query
17
+ )
18
+
19
+ request.perform
20
+ end
21
+
22
+ def get_directory_progress(directory_id = nil, query = {})
23
+ project_id = query[:project_id] || config.project_id
24
+
25
+ directory_id || raise(ArgumentError, ':directory_id is required')
26
+ project_id || raise(ArgumentError, ':project_id is required in parameters or when initialize Client')
27
+
28
+ request = Web::Request.new(
29
+ self,
30
+ :get,
31
+ "/projects/#{project_id}/directories/#{directory_id}/languages/progress",
32
+ query
33
+ )
34
+
35
+ request.perform
36
+ end
37
+
38
+ def get_file_progress(file_id = nil, query = {})
39
+ project_id = query[:project_id] || config.project_id
40
+
41
+ file_id || raise(ArgumentError, ':file_id is required')
42
+ project_id || raise(ArgumentError, ':project_id is required in parameters or when initialize Client')
43
+
44
+ request = Web::Request.new(
45
+ self,
46
+ :get,
47
+ "/projects/#{project_id}/files/#{file_id}/languages/progress",
48
+ query
49
+ )
50
+
51
+ request.perform
52
+ end
53
+
54
+ def get_language_progress(language_id = nil, query = {})
55
+ project_id = query[:project_id] || config.project_id
56
+
57
+ language_id || raise(ArgumentError, ':language_id is required')
58
+ project_id || raise(ArgumentError, ':project_id is required in parameters or when initialize Client')
59
+
60
+ request = Web::Request.new(
61
+ self,
62
+ :get,
63
+ "/projects/#{project_id}/languages/#{language_id}/progress",
64
+ query
65
+ )
66
+
67
+ request.perform
68
+ end
69
+
70
+ def get_project_progress(query = {}, project_id = config.project_id)
71
+ project_id || raise(ArgumentError, ':project_id is required in parameters or when initialize Client')
72
+
73
+ request = Web::Request.new(
74
+ self,
75
+ :get,
76
+ "/projects/#{project_id}/languages/progress",
77
+ query
78
+ )
79
+
80
+ request.perform
81
+ end
82
+
83
+ def get_qa_progress(query = {}, project_id = config.project_id)
84
+ project_id || raise(ArgumentError, ':project_id is required in parameters or when initialize Client')
85
+
86
+ request = Web::Request.new(
87
+ self,
88
+ :get,
89
+ "/projects/#{project_id}/qa-checks",
90
+ query
91
+ )
92
+
93
+ request.perform
94
+ end
95
+ end
96
+ end
97
+ end