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,220 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crowdin
4
+ module ApiResources
5
+ module StringTranslations
6
+ def list_translation_approvals(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}/approvals",
13
+ query
14
+ )
15
+
16
+ request.perform
17
+ end
18
+
19
+ def add_approval(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}/approvals",
26
+ query
27
+ )
28
+
29
+ request.perform
30
+ end
31
+
32
+ def get_approval(approval_id = nil, project_id = config.project_id)
33
+ approval_id || raise_parameter_is_required_error(:approval_id)
34
+ project_id || raise_project_id_is_required_error
35
+
36
+ request = Web::Request.new(
37
+ self,
38
+ :get,
39
+ "/projects/#{project_id}/approvals/#{approval_id}"
40
+ )
41
+
42
+ request.perform
43
+ end
44
+
45
+ def remove_approval(approval_id = nil, project_id = config.project_id)
46
+ approval_id || raise_parameter_is_required_error(:approval_id)
47
+ project_id || raise_project_id_is_required_error
48
+
49
+ request = Web::Request.new(
50
+ self,
51
+ :delete,
52
+ "/projects/#{project_id}/approvals/#{approval_id}"
53
+ )
54
+
55
+ request.perform
56
+ end
57
+
58
+ def list_language_translations(language_id = nil, query = {}, project_id = config.project_id)
59
+ language_id || raise_parameter_is_required_error(:language_id)
60
+ project_id || raise_project_id_is_required_error
61
+
62
+ request = Web::Request.new(
63
+ self,
64
+ :get,
65
+ "/projects/#{project_id}/languages/#{language_id}/translations",
66
+ query
67
+ )
68
+
69
+ request.perform
70
+ end
71
+
72
+ def list_string_translations(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}/translations",
79
+ query
80
+ )
81
+
82
+ request.perform
83
+ end
84
+
85
+ def add_translation(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}/translations",
92
+ query
93
+ )
94
+
95
+ request.perform
96
+ end
97
+
98
+ # For now Rest Client Resource aren't support payload for DELETE requests.
99
+ # So we have workaround through Rest Client Execute for this case
100
+ def delete_string_translations(query = {}, project_id = config.project_id)
101
+ # project_id || raise_project_id_is_required_error
102
+ #
103
+ # request = Web::Request.new(
104
+ # self,
105
+ # :delete,
106
+ # "/projects/#{project_id}/translations",
107
+ # query
108
+ # )
109
+ #
110
+ # request.perform
111
+
112
+ response = ::RestClient::Request.execute(
113
+ {
114
+ method: :delete,
115
+ url: config.base_url + config.target_api_url + "/projects/#{project_id}/translations",
116
+ payload: query.to_json
117
+ }.merge(@options)
118
+ )
119
+
120
+ begin
121
+ JSON.parse(response)
122
+ rescue
123
+ {}
124
+ end
125
+ end
126
+
127
+ def get_translation(trnslation_id = nil, query = {}, project_id = config.project_id)
128
+ trnslation_id || raise_parameter_is_required_error(:trnslation_id)
129
+ project_id || raise_project_id_is_required_error
130
+
131
+ request = Web::Request.new(
132
+ self,
133
+ :get,
134
+ "/projects/#{project_id}/translations/#{trnslation_id}",
135
+ query
136
+ )
137
+
138
+ request.perform
139
+ end
140
+
141
+ def restore_translation(trnslation_id = nil, project_id = config.project_id)
142
+ trnslation_id || raise_parameter_is_required_error(:trnslation_id)
143
+ project_id || raise_project_id_is_required_error
144
+
145
+ request = Web::Request.new(
146
+ self,
147
+ :put,
148
+ "/projects/#{project_id}/translations/#{trnslation_id}"
149
+ )
150
+
151
+ request.perform
152
+ end
153
+
154
+ def delete_translation(trnslation_id = nil, project_id = config.project_id)
155
+ trnslation_id || raise_parameter_is_required_error(:trnslation_id)
156
+ project_id || raise_project_id_is_required_error
157
+
158
+ request = Web::Request.new(
159
+ self,
160
+ :delete,
161
+ "/projects/#{project_id}/translations/#{trnslation_id}"
162
+ )
163
+
164
+ request.perform
165
+ end
166
+
167
+ def list_translation_votes(query = {}, project_id = config.project_id)
168
+ project_id || raise_project_id_is_required_error
169
+
170
+ request = Web::Request.new(
171
+ self,
172
+ :get,
173
+ "/projects/#{project_id}/votes",
174
+ query
175
+ )
176
+
177
+ request.perform
178
+ end
179
+
180
+ def add_vote(query = {}, project_id = config.project_id)
181
+ project_id || raise_project_id_is_required_error
182
+
183
+ request = Web::Request.new(
184
+ self,
185
+ :post,
186
+ "/projects/#{project_id}/votes",
187
+ query
188
+ )
189
+
190
+ request.perform
191
+ end
192
+
193
+ def get_vote(vote_id = nil, project_id = config.project_id)
194
+ vote_id || raise_parameter_is_required_error(:vote_id)
195
+ project_id || raise_project_id_is_required_error
196
+
197
+ request = Web::Request.new(
198
+ self,
199
+ :get,
200
+ "/projects/#{project_id}/votes/#{vote_id}"
201
+ )
202
+
203
+ request.perform
204
+ end
205
+
206
+ def edit_screenshot(vote_id = nil, project_id = config.project_id)
207
+ vote_id || raise_parameter_is_required_error(:vote_id)
208
+ project_id || raise_project_id_is_required_error
209
+
210
+ request = Web::Request.new(
211
+ self,
212
+ :delete,
213
+ "/projects/#{project_id}/votes/#{vote_id}"
214
+ )
215
+
216
+ request.perform
217
+ end
218
+ end
219
+ end
220
+ end
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crowdin
4
+ module ApiResources
5
+ module Tasks
6
+ def list_tasks(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}/tasks",
13
+ query
14
+ )
15
+
16
+ request.perform
17
+ end
18
+
19
+ def add_task(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}/tasks",
26
+ query
27
+ )
28
+
29
+ request.perform
30
+ end
31
+
32
+ def export_task_strings(task_id = nil, destination = nil, project_id = config.project_id)
33
+ task_id || raise_parameter_is_required_error(:task_id)
34
+ project_id || raise_project_id_is_required_error
35
+
36
+ request = Web::Request.new(
37
+ self,
38
+ :post,
39
+ "/projects/#{project_id}/tasks/#{task_id}/exports",
40
+ {},
41
+ {},
42
+ destination
43
+ )
44
+
45
+ request.perform
46
+ end
47
+
48
+ def get_task(task_id = nil, project_id = config.project_id)
49
+ task_id || raise_parameter_is_required_error(:task_id)
50
+ project_id || raise_project_id_is_required_error
51
+
52
+ request = Web::Request.new(
53
+ self,
54
+ :get,
55
+ "/projects/#{project_id}/tasks/#{task_id}"
56
+ )
57
+
58
+ request.perform
59
+ end
60
+
61
+ def delete_task(task_id = nil, project_id = config.project_id)
62
+ task_id || raise_parameter_is_required_error(:task_id)
63
+ project_id || raise_project_id_is_required_error
64
+
65
+ request = Web::Request.new(
66
+ self,
67
+ :delete,
68
+ "/projects/#{project_id}/tasks/#{task_id}"
69
+ )
70
+
71
+ request.perform
72
+ end
73
+
74
+ def edit_task(task_id = nil, query = {}, project_id = config.project_id)
75
+ task_id || raise_parameter_is_required_error(:task_id)
76
+ project_id || raise_project_id_is_required_error
77
+
78
+ request = Web::Request.new(
79
+ self,
80
+ :patch,
81
+ "/projects/#{project_id}/tasks/#{task_id}",
82
+ query
83
+ )
84
+
85
+ request.perform
86
+ end
87
+
88
+ def list_user_tasks(query = {})
89
+ request = Web::Request.new(
90
+ self,
91
+ :get,
92
+ '/user/tasks',
93
+ query
94
+ )
95
+
96
+ request.perform
97
+ end
98
+
99
+ def edit_task_archived_status(task_id = nil, query = {})
100
+ task_id || raise_parameter_is_required_error(:task_id)
101
+
102
+ request = Web::Request.new(
103
+ self,
104
+ :get,
105
+ "/user/tasks/#{task_id}",
106
+ query
107
+ )
108
+
109
+ request.perform
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,144 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crowdin
4
+ module ApiResources
5
+ # -- For Enterprise mode only --
6
+ module Teams
7
+ def add_team_to_project(query = {}, project_id = config.project_id)
8
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
9
+ project_id || raise_project_id_is_required_error
10
+
11
+ request = Web::Request.new(
12
+ self,
13
+ :post,
14
+ "/projects/#{project_id}/teams",
15
+ query
16
+ )
17
+
18
+ request.perform
19
+ end
20
+
21
+ def list_teams(query = {})
22
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
23
+
24
+ request = Web::Request.new(
25
+ self,
26
+ :get,
27
+ '/teams',
28
+ query
29
+ )
30
+
31
+ request.perform
32
+ end
33
+
34
+ def add_team(query = {})
35
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
36
+
37
+ request = Web::Request.new(
38
+ self,
39
+ :post,
40
+ '/teams',
41
+ query
42
+ )
43
+
44
+ request.perform
45
+ end
46
+
47
+ def get_team(team_id = nil, query = {})
48
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
49
+ team_id || raise_parameter_is_required_error(:team_id)
50
+
51
+ request = Web::Request.new(
52
+ self,
53
+ :get,
54
+ "/teams/#{team_id}",
55
+ query
56
+ )
57
+
58
+ request.perform
59
+ end
60
+
61
+ def delete_team(team_id = nil)
62
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
63
+ team_id || raise_parameter_is_required_error(:team_id)
64
+
65
+ request = Web::Request.new(
66
+ self,
67
+ :delete,
68
+ "/teams/#{team_id}"
69
+ )
70
+
71
+ request.perform
72
+ end
73
+
74
+ def edit_team(team_id = nil, query = {})
75
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
76
+ team_id || raise_parameter_is_required_error(:team_id)
77
+
78
+ request = Web::Request.new(
79
+ self,
80
+ :patch,
81
+ "/teams/#{team_id}",
82
+ query
83
+ )
84
+
85
+ request.perform
86
+ end
87
+
88
+ def team_members_list(team_id = nil, query = {})
89
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
90
+ team_id || raise_parameter_is_required_error(:team_id)
91
+
92
+ request = Web::Request.new(
93
+ self,
94
+ :get,
95
+ "/teams/#{team_id}/members",
96
+ query
97
+ )
98
+
99
+ request.perform
100
+ end
101
+
102
+ def add_team_members(team_id = nil, query = {})
103
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
104
+ team_id || raise_parameter_is_required_error(:team_id)
105
+
106
+ request = Web::Request.new(
107
+ self,
108
+ :post,
109
+ "/teams/#{team_id}/members",
110
+ query
111
+ )
112
+
113
+ request.perform
114
+ end
115
+
116
+ def delete_all_team_members(team_id = nil)
117
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
118
+ team_id || raise_parameter_is_required_error(:team_id)
119
+
120
+ request = Web::Request.new(
121
+ self,
122
+ :delete,
123
+ "/teams/#{team_id}/members"
124
+ )
125
+
126
+ request.perform
127
+ end
128
+
129
+ def delete_team_member(team_id = nil, member_id = nil)
130
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
131
+ team_id || raise_parameter_is_required_error(:team_id)
132
+ member_id || raise_parameter_is_required_error(:member_id)
133
+
134
+ request = Web::Request.new(
135
+ self,
136
+ :delete,
137
+ "/teams/#{team_id}/members/#{member_id}"
138
+ )
139
+
140
+ request.perform
141
+ end
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,145 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crowdin
4
+ module ApiResources
5
+ module TranslationMemory
6
+ def list_tms(query = {})
7
+ request = Web::Request.new(
8
+ self,
9
+ :get,
10
+ '/tms',
11
+ query
12
+ )
13
+
14
+ request.perform
15
+ end
16
+
17
+ def add_tm(query = {})
18
+ request = Web::Request.new(
19
+ self,
20
+ :post,
21
+ '/tms',
22
+ query
23
+ )
24
+
25
+ request.perform
26
+ end
27
+
28
+ def get_tm(tm_id = nil)
29
+ tm_id || raise_parameter_is_required_error(:tm_id)
30
+
31
+ request = Web::Request.new(
32
+ self,
33
+ :get,
34
+ "/tms/#{tm_id}"
35
+ )
36
+
37
+ request.perform
38
+ end
39
+
40
+ def delete_tm(tm_id = nil)
41
+ tm_id || raise_parameter_is_required_error(:tm_id)
42
+
43
+ request = Web::Request.new(
44
+ self,
45
+ :delete,
46
+ "/tms/#{tm_id}"
47
+ )
48
+
49
+ request.perform
50
+ end
51
+
52
+ def edit_tm(tm_id = nil, query = {})
53
+ tm_id || raise_parameter_is_required_error(:tm_id)
54
+
55
+ request = Web::Request.new(
56
+ self,
57
+ :delete,
58
+ "/tms/#{tm_id}",
59
+ query
60
+ )
61
+
62
+ request.perform
63
+ end
64
+
65
+ def clear_tm(tm_id = nil)
66
+ tm_id || raise_parameter_is_required_error(:tm_id)
67
+
68
+ request = Web::Request.new(
69
+ self,
70
+ :delete,
71
+ "/tms/#{tm_id}/segments"
72
+ )
73
+
74
+ request.perform
75
+ end
76
+
77
+ def export_tm(tm_id = nil)
78
+ tm_id || raise_parameter_is_required_error(:tm_id)
79
+
80
+ request = Web::Request.new(
81
+ self,
82
+ :post,
83
+ "/tms/#{tm_id}/exports"
84
+ )
85
+
86
+ request.perform
87
+ end
88
+
89
+ def check_tm_export_status(tm_id = nil, export_id = nil)
90
+ tm_id || raise_parameter_is_required_error(:tm_id)
91
+ export_id || raise_parameter_is_required_error(:export_id)
92
+
93
+ request = Web::Request.new(
94
+ self,
95
+ :get,
96
+ "/tms/#{tm_id}/exports/#{export_id}"
97
+ )
98
+
99
+ request.perform
100
+ end
101
+
102
+ def download_tm(tm_id = nil, export_id = nil, destination = nil)
103
+ tm_id || raise_parameter_is_required_error(:tm_id)
104
+ export_id || raise_parameter_is_required_error(:export_id)
105
+
106
+ request = Web::Request.new(
107
+ self,
108
+ :get,
109
+ "/tms/#{tm_id}/exports/#{export_id}/download",
110
+ {},
111
+ {},
112
+ destination
113
+ )
114
+
115
+ request.perform
116
+ end
117
+
118
+ def import_tm(tm_id = nil, query = {})
119
+ tm_id || raise_parameter_is_required_error(:tm_id)
120
+
121
+ request = Web::Request.new(
122
+ self,
123
+ :post,
124
+ "/tms/#{tm_id}/imports",
125
+ query
126
+ )
127
+
128
+ request.perform
129
+ end
130
+
131
+ def check_tm_import_status(tm_id = nil, import_id = nil)
132
+ tm_id || raise_parameter_is_required_error(:tm_id)
133
+ import_id || raise_parameter_is_required_error(:import_id)
134
+
135
+ request = Web::Request.new(
136
+ self,
137
+ :get,
138
+ "/tms/#{tm_id}/imports/#{import_id}"
139
+ )
140
+
141
+ request.perform
142
+ end
143
+ end
144
+ end
145
+ 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