crowdin-api 1.1.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test-and-lint.yml +1 -1
  3. data/.gitignore +2 -2
  4. data/.rubocop_todo.yml +114 -42
  5. data/README.md +26 -13
  6. data/bin/crowdin-console +5 -5
  7. data/crowdin-api.gemspec +1 -2
  8. data/lib/crowdin-api/api_resources/dictionaries.rb +32 -0
  9. data/lib/crowdin-api/api_resources/distributions.rb +92 -0
  10. data/lib/crowdin-api/api_resources/glossaries.rb +199 -0
  11. data/lib/crowdin-api/api_resources/labels.rb +98 -0
  12. data/lib/crowdin-api/api_resources/languages.rb +61 -0
  13. data/lib/crowdin-api/api_resources/machine_translation_engines.rb +79 -0
  14. data/lib/crowdin-api/api_resources/projects.rb +124 -0
  15. data/lib/crowdin-api/api_resources/reports.rb +120 -0
  16. data/lib/crowdin-api/api_resources/screenshots.rb +172 -0
  17. data/lib/crowdin-api/{api-resources → api_resources}/source_files.rb +68 -130
  18. data/lib/crowdin-api/{api-resources → api_resources}/source_strings.rb +19 -24
  19. data/lib/crowdin-api/api_resources/storages.rb +54 -0
  20. data/lib/crowdin-api/api_resources/string_comments.rb +68 -0
  21. data/lib/crowdin-api/api_resources/string_translations.rb +193 -0
  22. data/lib/crowdin-api/api_resources/tasks.rb +102 -0
  23. data/lib/crowdin-api/api_resources/teams.rb +135 -0
  24. data/lib/crowdin-api/api_resources/translation_memory.rb +131 -0
  25. data/lib/crowdin-api/{api-resources → api_resources}/translation_status.rb +24 -30
  26. data/lib/crowdin-api/{api-resources → api_resources}/translations.rb +41 -59
  27. data/lib/crowdin-api/api_resources/users.rb +161 -0
  28. data/lib/crowdin-api/api_resources/vendors.rb +21 -0
  29. data/lib/crowdin-api/api_resources/webhooks.rb +68 -0
  30. data/lib/crowdin-api/api_resources/workflows.rb +59 -0
  31. data/lib/crowdin-api/client/client.rb +72 -50
  32. data/lib/crowdin-api/client/configuration.rb +16 -12
  33. data/lib/crowdin-api/client/version.rb +1 -1
  34. data/lib/crowdin-api/core/errors.rb +2 -1
  35. data/lib/crowdin-api/core/{api_errors_raiser.rb → errors_raisers.rb} +21 -11
  36. data/lib/crowdin-api/core/request.rb +53 -88
  37. data/lib/crowdin-api/core/send_request.rb +67 -0
  38. data/lib/crowdin-api.rb +20 -11
  39. data/spec/api_resources/dictionaries_spec.rb +23 -0
  40. data/spec/api_resources/distributions_spec.rb +71 -0
  41. data/spec/api_resources/glossaries_spec.rb +167 -0
  42. data/spec/api_resources/labels_spec.rb +71 -0
  43. data/spec/api_resources/languages_spec.rb +51 -0
  44. data/spec/api_resources/machine_translation_engines_spec.rb +63 -0
  45. data/spec/api_resources/projects_spec.rb +215 -0
  46. data/spec/api_resources/reports_spec.rb +95 -0
  47. data/spec/api_resources/screenshots_spec.rb +134 -0
  48. data/spec/api_resources/source_files_spec.rb +13 -0
  49. data/spec/api_resources/source_strings_spec.rb +51 -0
  50. data/spec/api_resources/storages_spec.rb +13 -0
  51. data/spec/api_resources/string_comments_spec.rb +13 -0
  52. data/spec/api_resources/string_translations_spec.rb +13 -0
  53. data/spec/api_resources/tasks_spec.rb +79 -0
  54. data/spec/api_resources/teams_spec.rb +13 -0
  55. data/spec/api_resources/translation_memory_spec.rb +13 -0
  56. data/spec/api_resources/translation_status_spec.rb +15 -0
  57. data/spec/api_resources/translations_spec.rb +107 -0
  58. data/spec/api_resources/users_spec.rb +117 -0
  59. data/spec/api_resources/vendors_spec.rb +13 -0
  60. data/spec/api_resources/webhooks_spec.rb +51 -0
  61. data/spec/api_resources/workflows_spec.rb +41 -0
  62. data/spec/spec_helper.rb +20 -2
  63. data/spec/unit/client_spec.rb +85 -0
  64. metadata +65 -28
  65. data/bin/setup +0 -6
  66. data/lib/crowdin-api/api-resources/languages.rb +0 -81
  67. data/lib/crowdin-api/api-resources/projects.rb +0 -134
  68. data/lib/crowdin-api/api-resources/storages.rb +0 -102
  69. data/lib/crowdin-api/api-resources/workflows.rb +0 -59
  70. data/spec/core/config-instance_spec.rb +0 -72
  71. data/spec/crowdin-api_spec.rb +0 -7
@@ -0,0 +1,172 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crowdin
4
+ module ApiResources
5
+ module Screenshots
6
+ def list_screenshots(query = {}, project_id = config.project_id)
7
+ project_id || raise_project_id_is_required_error
8
+
9
+ request = Web::Request.new(
10
+ connection,
11
+ :get,
12
+ "#{config.target_api_url}/projects/#{project_id}/screenshots",
13
+ { params: query }
14
+ )
15
+ Web::SendRequest.new(request).perform
16
+ end
17
+
18
+ def add_screenshot(query = {}, project_id = config.project_id)
19
+ project_id || raise_project_id_is_required_error
20
+
21
+ request = Web::Request.new(
22
+ connection,
23
+ :post,
24
+ "#{config.target_api_url}/projects/#{project_id}/screenshots",
25
+ { params: query }
26
+ )
27
+ Web::SendRequest.new(request).perform
28
+ end
29
+
30
+ def get_screenshot(screenshot_id = nil, project_id = config.project_id)
31
+ screenshot_id || raise_parameter_is_required_error(:screenshot_id)
32
+ project_id || raise_project_id_is_required_error
33
+
34
+ request = Web::Request.new(
35
+ connection,
36
+ :get,
37
+ "#{config.target_api_url}/projects/#{project_id}/screenshots/#{screenshot_id}"
38
+ )
39
+ Web::SendRequest.new(request).perform
40
+ end
41
+
42
+ def update_screenshot(screenshot_id = nil, query = {}, project_id = config.project_id)
43
+ screenshot_id || raise_parameter_is_required_error(:screenshot_id)
44
+ project_id || raise_project_id_is_required_error
45
+
46
+ request = Web::Request.new(
47
+ connection,
48
+ :put,
49
+ "#{config.target_api_url}/projects/#{project_id}/screenshots/#{screenshot_id}",
50
+ { params: query }
51
+ )
52
+ Web::SendRequest.new(request).perform
53
+ end
54
+
55
+ def delete_screenshot(screenshot_id = nil, project_id = config.project_id)
56
+ screenshot_id || raise_parameter_is_required_error(:screenshot_id)
57
+ project_id || raise_project_id_is_required_error
58
+
59
+ request = Web::Request.new(
60
+ connection,
61
+ :delete,
62
+ "#{config.target_api_url}/projects/#{project_id}/screenshots/#{screenshot_id}"
63
+ )
64
+ Web::SendRequest.new(request).perform
65
+ end
66
+
67
+ def edit_screenshot(screenshot_id = nil, query = {}, project_id = config.project_id)
68
+ screenshot_id || raise_parameter_is_required_error(:screenshot_id)
69
+ project_id || raise_project_id_is_required_error
70
+
71
+ request = Web::Request.new(
72
+ connection,
73
+ :patch,
74
+ "#{config.target_api_url}/projects/#{project_id}/screenshots/#{screenshot_id}",
75
+ { params: query }
76
+ )
77
+ Web::SendRequest.new(request).perform
78
+ end
79
+
80
+ def list_tags(screenshot_id = nil, query = {}, project_id = config.project_id)
81
+ screenshot_id || raise_parameter_is_required_error(:screenshot_id)
82
+ project_id || raise_project_id_is_required_error
83
+
84
+ request = Web::Request.new(
85
+ connection,
86
+ :get,
87
+ "#{config.target_api_url}/projects/#{project_id}/screenshots/#{screenshot_id}/tags",
88
+ { params: query }
89
+ )
90
+ Web::SendRequest.new(request).perform
91
+ end
92
+
93
+ def replace_tags(screenshot_id = nil, query = {}, project_id = config.project_id)
94
+ screenshot_id || raise_parameter_is_required_error(:screenshot_id)
95
+ project_id || raise_project_id_is_required_error
96
+
97
+ request = Web::Request.new(
98
+ connection,
99
+ :put,
100
+ "#{config.target_api_url}/projects/#{project_id}/screenshots/#{screenshot_id}/tags",
101
+ { params: query }
102
+ )
103
+ Web::SendRequest.new(request).perform
104
+ end
105
+
106
+ def add_tag(screenshot_id = nil, query = {}, project_id = config.project_id)
107
+ screenshot_id || raise_parameter_is_required_error(:screenshot_id)
108
+ project_id || raise_project_id_is_required_error
109
+
110
+ request = Web::Request.new(
111
+ connection,
112
+ :post,
113
+ "#{config.target_api_url}/projects/#{project_id}/screenshots/#{screenshot_id}/tags",
114
+ { params: query }
115
+ )
116
+ Web::SendRequest.new(request).perform
117
+ end
118
+
119
+ def clear_tags(screenshot_id = nil, project_id = config.project_id)
120
+ screenshot_id || raise_parameter_is_required_error(:screenshot_id)
121
+ project_id || raise_project_id_is_required_error
122
+
123
+ request = Web::Request.new(
124
+ connection,
125
+ :delete,
126
+ "#{config.target_api_url}/projects/#{project_id}/screenshots/#{screenshot_id}/tags"
127
+ )
128
+ Web::SendRequest.new(request).perform
129
+ end
130
+
131
+ def get_tag(screenshot_id = nil, tag_id = nil, project_id = config.project_id)
132
+ screenshot_id || raise_parameter_is_required_error(:screenshot_id)
133
+ tag_id || raise_parameter_is_required_error(:tag_id)
134
+ project_id || raise_project_id_is_required_error
135
+
136
+ request = Web::Request.new(
137
+ connection,
138
+ :get,
139
+ "#{config.target_api_url}/projects/#{project_id}/screenshots/#{screenshot_id}/tags/#{tag_id}"
140
+ )
141
+ Web::SendRequest.new(request).perform
142
+ end
143
+
144
+ def delete_tag(screenshot_id = nil, tag_id = nil, project_id = config.project_id)
145
+ screenshot_id || raise_parameter_is_required_error(:screenshot_id)
146
+ tag_id || raise_parameter_is_required_error(:tag_id)
147
+ project_id || raise_project_id_is_required_error
148
+
149
+ request = Web::Request.new(
150
+ connection,
151
+ :delete,
152
+ "#{config.target_api_url}/projects/#{project_id}/screenshots/#{screenshot_id}/tags/#{tag_id}"
153
+ )
154
+ Web::SendRequest.new(request).perform
155
+ end
156
+
157
+ def edit_tag(screenshot_id = nil, tag_id = nil, query = {}, project_id = config.project_id)
158
+ screenshot_id || raise_parameter_is_required_error(:screenshot_id)
159
+ tag_id || raise_parameter_is_required_error(:tag_id)
160
+ project_id || raise_project_id_is_required_error
161
+
162
+ request = Web::Request.new(
163
+ connection,
164
+ :patch,
165
+ "#{config.target_api_url}/projects/#{project_id}/screenshots/#{screenshot_id}/tags/#{tag_id}",
166
+ { params: query }
167
+ )
168
+ Web::SendRequest.new(request).perform
169
+ end
170
+ end
171
+ end
172
+ end
@@ -7,26 +7,24 @@ module Crowdin
7
7
  project_id || raise_project_id_is_required_error
8
8
 
9
9
  request = Web::Request.new(
10
- self,
10
+ connection,
11
11
  :get,
12
- "/projects/#{project_id}/branches",
13
- query
12
+ "#{config.target_api_url}/projects/#{project_id}/branches",
13
+ { params: query }
14
14
  )
15
-
16
- request.perform
15
+ Web::SendRequest.new(request).perform
17
16
  end
18
17
 
19
18
  def add_branch(query = {}, project_id = config.project_id)
20
19
  project_id || raise_project_id_is_required_error
21
20
 
22
21
  request = Web::Request.new(
23
- self,
22
+ connection,
24
23
  :post,
25
- "/projects/#{project_id}/branches",
26
- query
24
+ "#{config.target_api_url}/projects/#{project_id}/branches",
25
+ { params: query }
27
26
  )
28
-
29
- request.perform
27
+ Web::SendRequest.new(request).perform
30
28
  end
31
29
 
32
30
  def get_branch(branch_id = nil, project_id = config.project_id)
@@ -34,12 +32,11 @@ module Crowdin
34
32
  project_id || raise_project_id_is_required_error
35
33
 
36
34
  request = Web::Request.new(
37
- self,
35
+ connection,
38
36
  :get,
39
- "/projects/#{project_id}/branches/#{branch_id}"
37
+ "#{config.target_api_url}/projects/#{project_id}/branches/#{branch_id}"
40
38
  )
41
-
42
- request.perform
39
+ Web::SendRequest.new(request).perform
43
40
  end
44
41
 
45
42
  def delete_branch(branch_id = nil, project_id = config.project_id)
@@ -47,12 +44,11 @@ module Crowdin
47
44
  project_id || raise_project_id_is_required_error
48
45
 
49
46
  request = Web::Request.new(
50
- self,
47
+ connection,
51
48
  :delete,
52
- "/projects/#{project_id}/branches/#{branch_id}"
49
+ "#{config.target_api_url}/projects/#{project_id}/branches/#{branch_id}"
53
50
  )
54
-
55
- request.perform
51
+ Web::SendRequest.new(request).perform
56
52
  end
57
53
 
58
54
  def edit_branch(branch_id = nil, query = {}, project_id = config.project_id)
@@ -60,39 +56,36 @@ module Crowdin
60
56
  project_id || raise_project_id_is_required_error
61
57
 
62
58
  request = Web::Request.new(
63
- self,
59
+ connection,
64
60
  :patch,
65
- "/projects/#{project_id}/branches/#{branch_id}",
66
- query
61
+ "#{config.target_api_url}/projects/#{project_id}/branches/#{branch_id}",
62
+ { params: query }
67
63
  )
68
-
69
- request.perform
64
+ Web::SendRequest.new(request).perform
70
65
  end
71
66
 
72
67
  def list_directories(query = {}, project_id = config.project_id)
73
68
  project_id || raise_project_id_is_required_error
74
69
 
75
70
  request = Web::Request.new(
76
- self,
71
+ connection,
77
72
  :get,
78
- "/projects/#{project_id}/directories",
79
- query
73
+ "#{config.target_api_url}/projects/#{project_id}/directories",
74
+ { params: query }
80
75
  )
81
-
82
- request.perform
76
+ Web::SendRequest.new(request).perform
83
77
  end
84
78
 
85
79
  def add_directory(query = {}, project_id = config.project_id)
86
80
  project_id || raise_project_id_is_required_error
87
81
 
88
82
  request = Web::Request.new(
89
- self,
83
+ connection,
90
84
  :post,
91
- "/projects/#{project_id}/directories",
92
- query
85
+ "#{config.target_api_url}/projects/#{project_id}/directories",
86
+ { params: query }
93
87
  )
94
-
95
- request.perform
88
+ Web::SendRequest.new(request).perform
96
89
  end
97
90
 
98
91
  def get_directory(directory_id = nil, project_id = config.project_id)
@@ -100,12 +93,11 @@ module Crowdin
100
93
  project_id || raise_project_id_is_required_error
101
94
 
102
95
  request = Web::Request.new(
103
- self,
96
+ connection,
104
97
  :get,
105
- "/projects/#{project_id}/directories/#{directory_id}"
98
+ "#{config.target_api_url}/projects/#{project_id}/directories/#{directory_id}"
106
99
  )
107
-
108
- request.perform
100
+ Web::SendRequest.new(request).perform
109
101
  end
110
102
 
111
103
  def delete_directory(directory_id = nil, project_id = config.project_id)
@@ -113,12 +105,11 @@ module Crowdin
113
105
  project_id || raise_project_id_is_required_error
114
106
 
115
107
  request = Web::Request.new(
116
- self,
108
+ connection,
117
109
  :delete,
118
- "/projects/#{project_id}/directories/#{directory_id}"
110
+ "#{config.target_api_url}/projects/#{project_id}/directories/#{directory_id}"
119
111
  )
120
-
121
- request.perform
112
+ Web::SendRequest.new(request).perform
122
113
  end
123
114
 
124
115
  def edit_directory(directory_id = nil, query = {}, project_id = config.project_id)
@@ -126,57 +117,36 @@ module Crowdin
126
117
  project_id || raise_project_id_is_required_error
127
118
 
128
119
  request = Web::Request.new(
129
- self,
120
+ connection,
130
121
  :patch,
131
- "/projects/#{project_id}/directories/#{directory_id}",
132
- query
122
+ "#{config.target_api_url}/projects/#{project_id}/directories/#{directory_id}",
123
+ { params: query }
133
124
  )
134
-
135
- request.perform
125
+ Web::SendRequest.new(request).perform
136
126
  end
137
127
 
138
128
  def list_files(query = {}, project_id = config.project_id)
139
129
  project_id || raise_project_id_is_required_error
140
130
 
141
131
  request = Web::Request.new(
142
- self,
132
+ connection,
143
133
  :get,
144
- "/projects/#{project_id}/files",
145
- query
134
+ "#{config.target_api_url}/projects/#{project_id}/files",
135
+ { params: query }
146
136
  )
147
-
148
- request.perform
137
+ Web::SendRequest.new(request).perform
149
138
  end
150
139
 
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
140
  def add_file(query = {}, project_id = config.project_id)
170
141
  project_id || raise_project_id_is_required_error
171
142
 
172
143
  request = Web::Request.new(
173
- self,
144
+ connection,
174
145
  :post,
175
- "/projects/#{project_id}/files",
176
- query
146
+ "#{config.target_api_url}/projects/#{project_id}/files",
147
+ { params: query }
177
148
  )
178
-
179
- request.perform
149
+ Web::SendRequest.new(request).perform
180
150
  end
181
151
 
182
152
  def get_file(file_id = nil, project_id = config.project_id)
@@ -184,12 +154,11 @@ module Crowdin
184
154
  project_id || raise_project_id_is_required_error
185
155
 
186
156
  request = Web::Request.new(
187
- self,
157
+ connection,
188
158
  :get,
189
- "/projects/#{project_id}/files/#{file_id}"
159
+ "#{config.target_api_url}/projects/#{project_id}/files/#{file_id}"
190
160
  )
191
-
192
- request.perform
161
+ Web::SendRequest.new(request).perform
193
162
  end
194
163
 
195
164
  def update_or_restore_file(file_id = nil, query = {}, project_id = config.project_id)
@@ -197,13 +166,12 @@ module Crowdin
197
166
  project_id || raise_project_id_is_required_error
198
167
 
199
168
  request = Web::Request.new(
200
- self,
169
+ connection,
201
170
  :put,
202
- "/projects/#{project_id}/files/#{file_id}",
203
- query
171
+ "#{config.target_api_url}/projects/#{project_id}/files/#{file_id}",
172
+ { params: query }
204
173
  )
205
-
206
- request.perform
174
+ Web::SendRequest.new(request).perform
207
175
  end
208
176
 
209
177
  def delete_file(file_id = nil, project_id = config.project_id)
@@ -211,12 +179,11 @@ module Crowdin
211
179
  project_id || raise_project_id_is_required_error
212
180
 
213
181
  request = Web::Request.new(
214
- self,
182
+ connection,
215
183
  :delete,
216
- "/projects/#{project_id}/files/#{file_id}"
184
+ "#{config.target_api_url}/projects/#{project_id}/files/#{file_id}"
217
185
  )
218
-
219
- request.perform
186
+ Web::SendRequest.new(request).perform
220
187
  end
221
188
 
222
189
  def edit_file(file_id = nil, query = {}, project_id = config.project_id)
@@ -224,65 +191,37 @@ module Crowdin
224
191
  project_id || raise_project_id_is_required_error
225
192
 
226
193
  request = Web::Request.new(
227
- self,
194
+ connection,
228
195
  :patch,
229
- "/projects/#{project_id}/files/#{file_id}",
230
- query
196
+ "#{config.target_api_url}/projects/#{project_id}/files/#{file_id}",
197
+ { params: query }
231
198
  )
232
-
233
- request.perform
199
+ Web::SendRequest.new(request).perform
234
200
  end
235
201
 
236
202
  def download_file(file_id = nil, destination = nil, project_id = config.project_id)
237
- destination || raise_parameter_is_required_error(:destination)
238
203
  file_id || raise_parameter_is_required_error(:file_id)
239
204
  project_id || raise_project_id_is_required_error
240
205
 
241
206
  request = Web::Request.new(
242
- self,
207
+ connection,
243
208
  :get,
244
- "/projects/#{project_id}/files/#{file_id}/download",
245
- {},
246
- {},
247
- destination
209
+ "#{config.target_api_url}/projects/#{project_id}/files/#{file_id}/download"
248
210
  )
249
-
250
- request.perform
211
+ Web::SendRequest.new(request, destination).perform
251
212
  end
252
213
 
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
214
  def list_file_revisions(file_id = nil, query = {}, project_id = config.project_id)
275
215
  file_id || raise_parameter_is_required_error(:file_id)
276
216
  project_id || raise_project_id_is_required_error
277
217
 
278
218
  request = Web::Request.new(
279
- self,
219
+ connection,
280
220
  :get,
281
- "/projects/#{project_id}/files/#{file_id}/revisions",
282
- query
221
+ "#{config.target_api_url}/projects/#{project_id}/files/#{file_id}/revisions",
222
+ { params: query }
283
223
  )
284
-
285
- request.perform
224
+ Web::SendRequest.new(request).perform
286
225
  end
287
226
 
288
227
  def get_file_revision(file_id = nil, revision_id = nil, project_id = config.project_id)
@@ -291,12 +230,11 @@ module Crowdin
291
230
  project_id || raise_project_id_is_required_error
292
231
 
293
232
  request = Web::Request.new(
294
- self,
233
+ connection,
295
234
  :get,
296
- "/projects/#{project_id}/files/#{file_id}/revisions/#{revision_id}"
235
+ "#{config.target_api_url}/projects/#{project_id}/files/#{file_id}/revisions/#{revision_id}"
297
236
  )
298
-
299
- request.perform
237
+ Web::SendRequest.new(request).perform
300
238
  end
301
239
  end
302
240
  end
@@ -7,26 +7,24 @@ module Crowdin
7
7
  project_id || raise_project_id_is_required_error
8
8
 
9
9
  request = Web::Request.new(
10
- self,
10
+ connection,
11
11
  :get,
12
- "/projects/#{project_id}/strings",
13
- query
12
+ "#{config.target_api_url}/projects/#{project_id}/strings",
13
+ { params: query }
14
14
  )
15
-
16
- request.perform
15
+ Web::SendRequest.new(request).perform
17
16
  end
18
17
 
19
18
  def add_string(query = {}, project_id = config.project_id)
20
19
  project_id || raise_project_id_is_required_error
21
20
 
22
21
  request = Web::Request.new(
23
- self,
22
+ connection,
24
23
  :post,
25
- "/projects/#{project_id}/strings",
26
- query
24
+ "#{config.target_api_url}/projects/#{project_id}/strings",
25
+ { params: query }
27
26
  )
28
-
29
- request.perform
27
+ Web::SendRequest.new(request).perform
30
28
  end
31
29
 
32
30
  def get_string(string_id = nil, query = {}, project_id = config.project_id)
@@ -34,13 +32,12 @@ module Crowdin
34
32
  project_id || raise_project_id_is_required_error
35
33
 
36
34
  request = Web::Request.new(
37
- self,
35
+ connection,
38
36
  :get,
39
- "/projects/#{project_id}/strings/#{string_id}",
40
- query
37
+ "#{config.target_api_url}/projects/#{project_id}/strings/#{string_id}",
38
+ { params: query }
41
39
  )
42
-
43
- request.perform
40
+ Web::SendRequest.new(request).perform
44
41
  end
45
42
 
46
43
  def delete_string(string_id = nil, project_id = config.project_id)
@@ -48,12 +45,11 @@ module Crowdin
48
45
  project_id || raise_project_id_is_required_error
49
46
 
50
47
  request = Web::Request.new(
51
- self,
48
+ connection,
52
49
  :delete,
53
- "/projects/#{project_id}/strings/#{string_id}"
50
+ "#{config.target_api_url}/projects/#{project_id}/strings/#{string_id}"
54
51
  )
55
-
56
- request.perform
52
+ Web::SendRequest.new(request).perform
57
53
  end
58
54
 
59
55
  def edit_string(string_id = nil, query = {}, project_id = config.project_id)
@@ -61,13 +57,12 @@ module Crowdin
61
57
  project_id || raise_project_id_is_required_error
62
58
 
63
59
  request = Web::Request.new(
64
- self,
60
+ connection,
65
61
  :patch,
66
- "/projects/#{project_id}/strings/#{string_id}",
67
- query
62
+ "#{config.target_api_url}/projects/#{project_id}/strings/#{string_id}",
63
+ { params: query }
68
64
  )
69
-
70
- request.perform
65
+ Web::SendRequest.new(request).perform
71
66
  end
72
67
  end
73
68
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crowdin
4
+ module ApiResources
5
+ module Storages
6
+ def list_storages(query = {})
7
+ request = Web::Request.new(
8
+ connection,
9
+ :get,
10
+ "#{config.target_api_url}/storages",
11
+ { params: query }
12
+ )
13
+ Web::SendRequest.new(request).perform
14
+ end
15
+
16
+ def add_storage(file = nil)
17
+ file || raise_parameter_is_required_error(:file)
18
+
19
+ file = file.is_a?(File) ? file : File.open(file, 'r')
20
+ headers = { 'Content-Type' => 'application/octet-stream', 'Crowdin-API-FileName' => File.basename(file) }
21
+
22
+ request = Web::Request.new(
23
+ connection,
24
+ :post,
25
+ "#{config.target_api_url}/storages",
26
+ { params: file, headers: headers }
27
+ )
28
+ Web::SendRequest.new(request).perform
29
+ end
30
+
31
+ def get_storage(storage_id = nil)
32
+ storage_id || raise_parameter_is_required_error(:storage_id)
33
+
34
+ request = Web::Request.new(
35
+ connection,
36
+ :get,
37
+ "#{config.target_api_url}/storages/#{storage_id}"
38
+ )
39
+ Web::SendRequest.new(request).perform
40
+ end
41
+
42
+ def delete_storage(storage_id = nil)
43
+ storage_id || raise_parameter_is_required_error(:storage_id)
44
+
45
+ request = Web::Request.new(
46
+ connection,
47
+ :delete,
48
+ "#{config.target_api_url}/storages/#{storage_id}"
49
+ )
50
+ Web::SendRequest.new(request).perform
51
+ end
52
+ end
53
+ end
54
+ end