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,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crowdin
4
+ module ApiResources
5
+ module Distributions
6
+ def list_distributions(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}/distributions",
13
+ query
14
+ )
15
+
16
+ request.perform
17
+ end
18
+
19
+ def add_distribution(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}/distributions",
26
+ query
27
+ )
28
+
29
+ request.perform
30
+ end
31
+
32
+ def get_distribution(hash = nil, project_id = config.project_id)
33
+ hash || raise_parameter_is_required_error(:hash)
34
+ project_id || raise_project_id_is_required_error
35
+
36
+ request = Web::Request.new(
37
+ self,
38
+ :get,
39
+ "/projects/#{project_id}/distributions/#{hash}"
40
+ )
41
+
42
+ request.perform
43
+ end
44
+
45
+ def delete_distribution(hash = nil, project_id = config.project_id)
46
+ hash || raise_parameter_is_required_error(:hash)
47
+ project_id || raise_project_id_is_required_error
48
+
49
+ request = Web::Request.new(
50
+ self,
51
+ :delete,
52
+ "/projects/#{project_id}/distributions/#{hash}"
53
+ )
54
+
55
+ request.perform
56
+ end
57
+
58
+ def edit_distribution(hash = nil, query = {}, project_id = config.project_id)
59
+ hash || raise_parameter_is_required_error(:hash)
60
+ project_id || raise_project_id_is_required_error
61
+
62
+ request = Web::Request.new(
63
+ self,
64
+ :patch,
65
+ "/projects/#{project_id}/distributions/#{hash}",
66
+ query
67
+ )
68
+
69
+ request.perform
70
+ end
71
+
72
+ def get_destribution_release(hash = nil, project_id = config.project_id)
73
+ hash || raise_parameter_is_required_error(:hash)
74
+ project_id || raise_project_id_is_required_error
75
+
76
+ request = Web::Request.new(
77
+ self,
78
+ :get,
79
+ "/projects/#{project_id}/distributions/#{hash}/release"
80
+ )
81
+
82
+ request.perform
83
+ end
84
+
85
+ def release_distribution(hash = nil, project_id = config.project_id)
86
+ hash || raise_parameter_is_required_error(:hash)
87
+ project_id || raise_project_id_is_required_error
88
+
89
+ request = Web::Request.new(
90
+ self,
91
+ :post,
92
+ "/projects/#{project_id}/distributions/#{hash}/release"
93
+ )
94
+
95
+ request.perform
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,217 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crowdin
4
+ module ApiResources
5
+ module Glossaries
6
+ def list_glossaries(query = {})
7
+ request = Web::Request.new(
8
+ self,
9
+ :get,
10
+ '/glossaries',
11
+ query
12
+ )
13
+
14
+ request.perform
15
+ end
16
+
17
+ def add_glossary(query = {})
18
+ request = Web::Request.new(
19
+ self,
20
+ :post,
21
+ '/glossaries',
22
+ query
23
+ )
24
+
25
+ request.perform
26
+ end
27
+
28
+ def get_glossary(glossary_id = nil, query = {})
29
+ glossary_id || raise_parameter_is_required_error(:glossary_id)
30
+
31
+ request = Web::Request.new(
32
+ self,
33
+ :get,
34
+ "/glossaries/#{glossary_id}",
35
+ query
36
+ )
37
+
38
+ request.perform
39
+ end
40
+
41
+ def delete_glossary(glossary_id = nil, query = {})
42
+ glossary_id || raise_parameter_is_required_error(:glossary_id)
43
+
44
+ request = Web::Request.new(
45
+ self,
46
+ :delete,
47
+ "/glossaries/#{glossary_id}",
48
+ query
49
+ )
50
+
51
+ request.perform
52
+ end
53
+
54
+ def edit_glossary(glossary_id = nil, query = {})
55
+ glossary_id || raise_parameter_is_required_error(:glossary_id)
56
+
57
+ request = Web::Request.new(
58
+ self,
59
+ :patch,
60
+ "/glossaries/#{glossary_id}",
61
+ query
62
+ )
63
+
64
+ request.perform
65
+ end
66
+
67
+ def export_glossary(query = {}, glossary_id = nil, destination = nil)
68
+ glossary_id || raise_parameter_is_required_error(:glossary_id)
69
+
70
+ request = Web::Request.new(
71
+ self,
72
+ :post,
73
+ "/glossaries/#{glossary_id}/exports",
74
+ query,
75
+ {},
76
+ destination
77
+ )
78
+
79
+ request.perform
80
+ end
81
+
82
+ def check_glossary_export_status(glossary_id = nil, export_id = nil)
83
+ glossary_id || raise_parameter_is_required_error(:glossary_id)
84
+ export_id || raise_parameter_is_required_error(:export_id)
85
+
86
+ request = Web::Request.new(
87
+ self,
88
+ :get,
89
+ "/glossaries/#{glossary_id}/exports/#{export_id}"
90
+ )
91
+
92
+ request.perform
93
+ end
94
+
95
+ def download_glossary(glossary_id = nil, export_id = nil, destination = nil)
96
+ glossary_id || raise_parameter_is_required_error(:glossary_id)
97
+ export_id || raise_parameter_is_required_error(:export_id)
98
+
99
+ request = Web::Request.new(
100
+ self,
101
+ :get,
102
+ "/glossaries/#{glossary_id}/exports/#{export_id}/download",
103
+ {},
104
+ {},
105
+ destination
106
+ )
107
+
108
+ request.perform
109
+ end
110
+
111
+ def import_glossary(glossary_id = nil, query = {})
112
+ glossary_id || raise_parameter_is_required_error(:glossary_id)
113
+
114
+ request = Web::Request.new(
115
+ self,
116
+ :post,
117
+ "/glossaries/#{glossary_id}/imports",
118
+ query
119
+ )
120
+
121
+ request.perform
122
+ end
123
+
124
+ def check_glossary_import_status(glossary_id = nil, import_id = nil)
125
+ glossary_id || raise_parameter_is_required_error(:glossary_id)
126
+ import_id || raise_parameter_is_required_error(:import_id)
127
+
128
+ request = Web::Request.new(
129
+ self,
130
+ :get,
131
+ "/glossaries/#{glossary_id}/imports/#{import_id}"
132
+ )
133
+
134
+ request.perform
135
+ end
136
+
137
+ def list_terms(glossary_id = nil, query = {})
138
+ glossary_id || raise_parameter_is_required_error(:glossary_id)
139
+
140
+ request = Web::Request.new(
141
+ self,
142
+ :get,
143
+ "/glossaries/#{glossary_id}/terms",
144
+ query
145
+ )
146
+
147
+ request.perform
148
+ end
149
+
150
+ def add_term(glossary_id = nil, query = {})
151
+ glossary_id || raise_parameter_is_required_error(:glossary_id)
152
+
153
+ request = Web::Request.new(
154
+ self,
155
+ :post,
156
+ "/glossaries/#{glossary_id}/terms",
157
+ query
158
+ )
159
+
160
+ request.perform
161
+ end
162
+
163
+ def clear_glossary(glossary_id = nil, query = {})
164
+ glossary_id || raise_parameter_is_required_error(:glossary_id)
165
+
166
+ request = Web::Request.new(
167
+ self,
168
+ :delete,
169
+ "/glossaries/#{glossary_id}/terms",
170
+ query
171
+ )
172
+
173
+ request.perform
174
+ end
175
+
176
+ def get_term(glossary_id = nil, term_id = nil)
177
+ glossary_id || raise_parameter_is_required_error(:glossary_id)
178
+ term_id || raise_parameter_is_required_error(:term_id)
179
+
180
+ request = Web::Request.new(
181
+ self,
182
+ :get,
183
+ "/glossaries/#{glossary_id}/terms/#{term_id}"
184
+ )
185
+
186
+ request.perform
187
+ end
188
+
189
+ def delete_term(glossary_id = nil, term_id = nil)
190
+ glossary_id || raise_parameter_is_required_error(:glossary_id)
191
+ term_id || raise_parameter_is_required_error(:term_id)
192
+
193
+ request = Web::Request.new(
194
+ self,
195
+ :delete,
196
+ "/glossaries/#{glossary_id}/terms/#{term_id}"
197
+ )
198
+
199
+ request.perform
200
+ end
201
+
202
+ def edit_term(glossary_id = nil, term_id = nil, query = {})
203
+ glossary_id || raise_parameter_is_required_error(:glossary_id)
204
+ term_id || raise_parameter_is_required_error(:term_id)
205
+
206
+ request = Web::Request.new(
207
+ self,
208
+ :patch,
209
+ "/glossaries/#{glossary_id}/terms/#{term_id}",
210
+ query
211
+ )
212
+
213
+ request.perform
214
+ end
215
+ end
216
+ end
217
+ end
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crowdin
4
+ module ApiResources
5
+ module Labels
6
+ def list_lables(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}/labels",
13
+ query
14
+ )
15
+
16
+ request.perform
17
+ end
18
+
19
+ def add_label(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}/labels",
26
+ query
27
+ )
28
+
29
+ request.perform
30
+ end
31
+
32
+ def get_label(label_id = nil, project_id = config.project_id)
33
+ label_id || raise_parameter_is_required_error(:label_id)
34
+ project_id || raise_project_id_is_required_error
35
+
36
+ request = Web::Request.new(
37
+ self,
38
+ :get,
39
+ "/projects/#{project_id}/labels/#{label_id}"
40
+ )
41
+
42
+ request.perform
43
+ end
44
+
45
+ def delete_label(label_id = nil, project_id = config.project_id)
46
+ label_id || raise_parameter_is_required_error(:label_id)
47
+ project_id || raise_project_id_is_required_error
48
+
49
+ request = Web::Request.new(
50
+ self,
51
+ :delete,
52
+ "/projects/#{project_id}/labels/#{label_id}"
53
+ )
54
+
55
+ request.perform
56
+ end
57
+
58
+ def edit_label(label_id = nil, query = {}, project_id = config.project_id)
59
+ label_id || raise_parameter_is_required_error(:label_id)
60
+ project_id || raise_project_id_is_required_error
61
+
62
+ request = Web::Request.new(
63
+ self,
64
+ :patch,
65
+ "/projects/#{project_id}/labels/#{label_id}",
66
+ query
67
+ )
68
+
69
+ request.perform
70
+ end
71
+
72
+ def assign_label_to_strings(label_id = nil, query = {}, project_id = config.project_id)
73
+ label_id || raise_parameter_is_required_error(:label_id)
74
+ project_id || raise_project_id_is_required_error
75
+
76
+ request = Web::Request.new(
77
+ self,
78
+ :post,
79
+ "/projects/#{project_id}/labels/#{label_id}/strings",
80
+ query
81
+ )
82
+
83
+ request.perform
84
+ end
85
+
86
+ # For now Rest Client Resource aren't support payload for DELETE requests.
87
+ # So we have workaround through Rest Client Execute for this case
88
+ def unassign_label_from_strings(label_id = nil, query = {}, project_id = config.project_id)
89
+ # label_id || raise_parameter_is_required_error(:label_id)
90
+ # project_id || raise_project_id_is_required_error
91
+ #
92
+ # request = Web::Request.new(
93
+ # self,
94
+ # :delete,
95
+ # "/projects/#{project_id}/labels/#{label_id}",
96
+ # query
97
+ # )
98
+ #
99
+ # request.perform
100
+
101
+ response = ::RestClient::Request.execute(
102
+ {
103
+ method: :delete,
104
+ url: config.base_url + config.target_api_url + "/projects/#{project_id}/labels/#{label_id}",
105
+ payload: query.to_json
106
+ }.merge(@options)
107
+ )
108
+
109
+ begin
110
+ JSON.parse(response)
111
+ rescue
112
+ {}
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crowdin
4
+ module ApiResources
5
+ module Languages
6
+ def list_languages(query = {})
7
+ request = Web::Request.new(
8
+ self,
9
+ :get,
10
+ '/languages',
11
+ query
12
+ )
13
+
14
+ request.perform
15
+ end
16
+
17
+ #
18
+ # Add custom language.
19
+ #
20
+ # === Parameters
21
+ #
22
+ # * +:name+ [String] - Language name
23
+ # * +:code+ [String] - Custom language code
24
+ # * +:localeCode+ [String] - Custom language locale code
25
+ # * +:textDirection+ [String ltr/rtl] - Text direction in custom language
26
+ # * +:pluralCategoryNames+ [String] - Array with category names
27
+ # * +:threeLettersCode+ [String] - Custom language 3 letters code. Format: ISO 6393 code
28
+ #
29
+ # === Example
30
+ #
31
+ # crowdin.add_custom_language(name: 'your_name', code: 'your_code' ..)
32
+ #
33
+ def add_custom_language(query = {})
34
+ request = Web::Request.new(
35
+ self,
36
+ :post,
37
+ '/languages',
38
+ query
39
+ )
40
+
41
+ request.perform
42
+ end
43
+
44
+ def get_language(language_id = nil)
45
+ language_id || raise_parameter_is_required_error(:language_id)
46
+
47
+ request = Web::Request.new(
48
+ self,
49
+ :get,
50
+ "/languages/#{language_id}"
51
+ )
52
+
53
+ request.perform
54
+ end
55
+
56
+ def delete_custom_language(language_id = nil)
57
+ language_id || raise_parameter_is_required_error(:language_id)
58
+
59
+ request = Web::Request.new(
60
+ self,
61
+ :delete,
62
+ "/languages/#{language_id}"
63
+ )
64
+
65
+ request.perform
66
+ end
67
+
68
+ def edit_custom_language(language_id = nil)
69
+ language_id || raise_parameter_is_required_error(:language_id)
70
+
71
+ request = Web::Request.new(
72
+ self,
73
+ :patch,
74
+ "/languages/#{language_id}",
75
+ query
76
+ )
77
+
78
+ request.perform
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crowdin
4
+ module ApiResources
5
+ # -- For Enterprise mode only --
6
+ module MachineTranslationEngines
7
+ def list_mts(query = {})
8
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
9
+
10
+ request = Web::Request.new(
11
+ self,
12
+ :get,
13
+ '/mts',
14
+ query
15
+ )
16
+
17
+ request.perform
18
+ end
19
+
20
+ def add_mt(query = {})
21
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
22
+
23
+ request = Web::Request.new(
24
+ self,
25
+ :post,
26
+ '/mts',
27
+ query
28
+ )
29
+
30
+ request.perform
31
+ end
32
+
33
+ def get_mt(mt_id = nil)
34
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
35
+ mt_id || raise_parameter_is_required_error(:mt_id)
36
+
37
+ request = Web::Request.new(
38
+ self,
39
+ :get,
40
+ "/mts/#{mt_id}"
41
+ )
42
+
43
+ request.perform
44
+ end
45
+
46
+ def delete_mt(mt_id = nil)
47
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
48
+ mt_id || raise_parameter_is_required_error(:mt_id)
49
+
50
+ request = Web::Request.new(
51
+ self,
52
+ :delete,
53
+ "/mts/#{mt_id}"
54
+ )
55
+
56
+ request.perform
57
+ end
58
+
59
+ def edit_mt(mt_id = nil, query = {})
60
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
61
+ mt_id || raise_parameter_is_required_error(:mt_id)
62
+
63
+ request = Web::Request.new(
64
+ self,
65
+ :patch,
66
+ "/mts/#{mt_id}",
67
+ query
68
+ )
69
+
70
+ request.perform
71
+ end
72
+ end
73
+ end
74
+ end