crowdin-api 1.1.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) 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 +37 -30
  5. data/README.md +23 -12
  6. data/bin/crowdin-console +4 -4
  7. data/lib/crowdin-api/api-resources/dictionaries.rb +34 -0
  8. data/lib/crowdin-api/api-resources/distributions.rb +99 -0
  9. data/lib/crowdin-api/api-resources/glossaries.rb +217 -0
  10. data/lib/crowdin-api/api-resources/labels.rb +117 -0
  11. data/lib/crowdin-api/api-resources/languages.rb +1 -0
  12. data/lib/crowdin-api/api-resources/machine_translation_engines.rb +74 -0
  13. data/lib/crowdin-api/api-resources/projects.rb +15 -1
  14. data/lib/crowdin-api/api-resources/reports.rb +138 -0
  15. data/lib/crowdin-api/api-resources/screenshots.rb +186 -0
  16. data/lib/crowdin-api/api-resources/source_files.rb +3 -2
  17. data/lib/crowdin-api/api-resources/storages.rb +5 -1
  18. data/lib/crowdin-api/api-resources/string_comments.rb +73 -0
  19. data/lib/crowdin-api/api-resources/string_translations.rb +220 -0
  20. data/lib/crowdin-api/api-resources/tasks.rb +113 -0
  21. data/lib/crowdin-api/api-resources/teams.rb +144 -0
  22. data/lib/crowdin-api/api-resources/translation_memory.rb +145 -0
  23. data/lib/crowdin-api/api-resources/translations.rb +8 -6
  24. data/lib/crowdin-api/api-resources/users.rb +129 -0
  25. data/lib/crowdin-api/api-resources/vendors.rb +21 -0
  26. data/lib/crowdin-api/api-resources/webhooks.rb +73 -0
  27. data/lib/crowdin-api/api-resources/workflows.rb +3 -0
  28. data/lib/crowdin-api/client/client.rb +41 -28
  29. data/lib/crowdin-api/client/configuration.rb +10 -6
  30. data/lib/crowdin-api/client/version.rb +1 -1
  31. data/lib/crowdin-api/core/errors.rb +2 -1
  32. data/lib/crowdin-api/core/{api_errors_raiser.rb → errors_raisers.rb} +21 -11
  33. data/lib/crowdin-api/core/request.rb +8 -5
  34. data/lib/crowdin-api/core/utils.rb +10 -0
  35. data/lib/crowdin-api.rb +22 -6
  36. data/spec/client/client-instance_spec.rb +14 -0
  37. data/spec/{core/config-instance_spec.rb → client/configuration-instance_spec.rb} +7 -7
  38. metadata +21 -5
  39. data/spec/crowdin-api_spec.rb +0 -7
@@ -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
@@ -14,6 +14,7 @@ module Crowdin
14
14
  request.perform
15
15
  end
16
16
 
17
+ #
17
18
  # Add custom language.
18
19
  #
19
20
  # === Parameters
@@ -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
@@ -49,6 +49,20 @@ module Crowdin
49
49
  request.perform
50
50
  end
51
51
 
52
+ #
53
+ # Edit project.
54
+ #
55
+ # === Parameters
56
+ #
57
+ # * +:projectId+ [Integer] - Project Identifier. Get via list_projects. Can be initialized with the Crowdin Client
58
+ # * +:value+ [String] - String or Array of strings.
59
+ # * +:op+ [String] - Path operation to perform.
60
+ # * +:projectId+ [String <json-pointer>] - Enum, for instance '/name'. Full list you can see on the developers site.
61
+ #
62
+ # === Example
63
+ #
64
+ # crowdin.edit_project(project_id, [{op: 'replace', path: '/name', value: 'your_new_project_name'}])
65
+ #
52
66
  def edit_project(project_id = nil, query = {})
53
67
  project_id || raise_parameter_is_required_error(:project_id)
54
68
 
@@ -62,7 +76,7 @@ module Crowdin
62
76
  request.perform
63
77
  end
64
78
 
65
- # For Enterprise mode only
79
+ # -- For Enterprise mode only --
66
80
 
67
81
  def list_groups(query = {})
68
82
  config.enterprise_mode? || raise_only_for_enterprise_mode_error
@@ -0,0 +1,138 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crowdin
4
+ module ApiResources
5
+ module Reports
6
+ def generate_report(query = {}, project_id = config.project_id)
7
+ project_id || raise_project_id_is_required_error
8
+
9
+ request = Web::Request.new(
10
+ self,
11
+ :post,
12
+ "/projects/#{project_id}/reports",
13
+ query
14
+ )
15
+
16
+ request.perform
17
+ end
18
+
19
+ def check_report_generation_status(report_id = nil, project_id = config.project_id)
20
+ report_id || raise_parameter_is_required_error(:report_id)
21
+ project_id || raise_project_id_is_required_error
22
+
23
+ request = Web::Request.new(
24
+ self,
25
+ :get,
26
+ "/projects/#{project_id}/reports/#{report_id}"
27
+ )
28
+
29
+ request.perform
30
+ end
31
+
32
+ def download_report(report_id = nil, destination = nil, project_id = config.project_id)
33
+ report_id || raise_parameter_is_required_error(:report_id)
34
+ project_id || raise_project_id_is_required_error
35
+
36
+ request = Web::Request.new(
37
+ self,
38
+ :get,
39
+ "/projects/#{project_id}/reports/#{report_id}/download",
40
+ {},
41
+ {},
42
+ destination
43
+ )
44
+
45
+ request.perform
46
+ end
47
+
48
+ # -- For Enterprise mode only --
49
+
50
+ def generate_group_report(group_id = nil, query = {})
51
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
52
+ group_id || raise_parameter_is_required_error(:group_id)
53
+
54
+ request = Web::Request.new(
55
+ self,
56
+ :post,
57
+ "/groups/#{group_id}/reports",
58
+ query
59
+ )
60
+
61
+ request.perform
62
+ end
63
+
64
+ def check_group_report_generation_status(group_id = nil, report_id = nil)
65
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
66
+ group_id || raise_parameter_is_required_error(:group_id)
67
+ report_id || raise_parameter_is_required_error(:report_id)
68
+
69
+ request = Web::Request.new(
70
+ self,
71
+ :get,
72
+ "/groups/#{group_id}/reports/#{report_id}"
73
+ )
74
+
75
+ request.perform
76
+ end
77
+
78
+ def download_group_report(group_id = nil, report_id = nil, destination = nil)
79
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
80
+ group_id || raise_parameter_is_required_error(:group_id)
81
+ report_id || raise_parameter_is_required_error(:report_id)
82
+
83
+ request = Web::Request.new(
84
+ self,
85
+ :get,
86
+ "/groups/#{group_id}/reports/#{report_id}/download",
87
+ {},
88
+ {},
89
+ destination
90
+ )
91
+
92
+ request.perform
93
+ end
94
+
95
+ def generate_organization_report(query = {})
96
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
97
+
98
+ request = Web::Request.new(
99
+ self,
100
+ :post,
101
+ '/reports',
102
+ query
103
+ )
104
+
105
+ request.perform
106
+ end
107
+
108
+ def check_organization_report_generation_status(report_id = nil)
109
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
110
+ report_id || raise_parameter_is_required_error(:report_id)
111
+
112
+ request = Web::Request.new(
113
+ self,
114
+ :get,
115
+ "/reports/#{report_id}"
116
+ )
117
+
118
+ request.perform
119
+ end
120
+
121
+ def download_organization_report(report_id = nil, destination = nil)
122
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
123
+ report_id || raise_parameter_is_required_error(:report_id)
124
+
125
+ request = Web::Request.new(
126
+ self,
127
+ :get,
128
+ "/reports/#{report_id}/download",
129
+ {},
130
+ {},
131
+ destination
132
+ )
133
+
134
+ request.perform
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,186 @@
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
+ self,
11
+ :get,
12
+ "/projects/#{project_id}/screenshots",
13
+ query
14
+ )
15
+
16
+ request.perform
17
+ end
18
+
19
+ def add_screenshot(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}/screenshots",
26
+ query
27
+ )
28
+
29
+ request.perform
30
+ end
31
+
32
+ def get_screenshot(screenshot_id = nil, project_id = config.project_id)
33
+ screenshot_id || raise_parameter_is_required_error(:screenshot_id)
34
+ project_id || raise_project_id_is_required_error
35
+
36
+ request = Web::Request.new(
37
+ self,
38
+ :get,
39
+ "/projects/#{project_id}/screenshots/#{screenshot_id}"
40
+ )
41
+
42
+ request.perform
43
+ end
44
+
45
+ def update_screenshot(screenshot_id = nil, query = {}, project_id = config.project_id)
46
+ screenshot_id || raise_parameter_is_required_error(:screenshot_id)
47
+ project_id || raise_project_id_is_required_error
48
+
49
+ request = Web::Request.new(
50
+ self,
51
+ :put,
52
+ "/projects/#{project_id}/screenshots/#{screenshot_id}",
53
+ query
54
+ )
55
+
56
+ request.perform
57
+ end
58
+
59
+ def delete_screenshot(screenshot_id = nil, project_id = config.project_id)
60
+ screenshot_id || raise_parameter_is_required_error(:screenshot_id)
61
+ project_id || raise_project_id_is_required_error
62
+
63
+ request = Web::Request.new(
64
+ self,
65
+ :delete,
66
+ "/projects/#{project_id}/screenshots/#{screenshot_id}"
67
+ )
68
+
69
+ request.perform
70
+ end
71
+
72
+ def edit_screenshot(screenshot_id = nil, query = {}, project_id = config.project_id)
73
+ screenshot_id || raise_parameter_is_required_error(:screenshot_id)
74
+ project_id || raise_project_id_is_required_error
75
+
76
+ request = Web::Request.new(
77
+ self,
78
+ :patch,
79
+ "/projects/#{project_id}/screenshots/#{screenshot_id}",
80
+ query
81
+ )
82
+
83
+ request.perform
84
+ end
85
+
86
+ def list_tags(screenshot_id = nil, query = {}, project_id = config.project_id)
87
+ screenshot_id || raise_parameter_is_required_error(:screenshot_id)
88
+ project_id || raise_project_id_is_required_error
89
+
90
+ request = Web::Request.new(
91
+ self,
92
+ :get,
93
+ "/projects/#{project_id}/screenshots/#{screenshot_id}/tags",
94
+ query
95
+ )
96
+
97
+ request.perform
98
+ end
99
+
100
+ # Auto tag
101
+ def replace_tags(screenshot_id = nil, query = {}, project_id = config.project_id)
102
+ screenshot_id || raise_parameter_is_required_error(:screenshot_id)
103
+ project_id || raise_project_id_is_required_error
104
+
105
+ request = Web::Request.new(
106
+ self,
107
+ :put,
108
+ "/projects/#{project_id}/screenshots/#{screenshot_id}/tags",
109
+ query
110
+ )
111
+
112
+ request.perform
113
+ end
114
+
115
+ def add_tag(screenshot_id = nil, query = {}, project_id = config.project_id)
116
+ screenshot_id || raise_parameter_is_required_error(:screenshot_id)
117
+ project_id || raise_project_id_is_required_error
118
+
119
+ request = Web::Request.new(
120
+ self,
121
+ :post,
122
+ "/projects/#{project_id}/screenshots/#{screenshot_id}/tags",
123
+ query
124
+ )
125
+
126
+ request.perform
127
+ end
128
+
129
+ def clear_tags(screenshot_id = nil, project_id = config.project_id)
130
+ screenshot_id || raise_parameter_is_required_error(:screenshot_id)
131
+ project_id || raise_project_id_is_required_error
132
+
133
+ request = Web::Request.new(
134
+ self,
135
+ :delete,
136
+ "/projects/#{project_id}/screenshots/#{screenshot_id}/tags"
137
+ )
138
+
139
+ request.perform
140
+ end
141
+
142
+ def get_tag(screenshot_id = nil, tag_id = nil, project_id = config.project_id)
143
+ screenshot_id || raise_parameter_is_required_error(:screenshot_id)
144
+ tag_id || raise_parameter_is_required_error(:tag_id)
145
+ project_id || raise_project_id_is_required_error
146
+
147
+ request = Web::Request.new(
148
+ self,
149
+ :get,
150
+ "/projects/#{project_id}/screenshots/#{screenshot_id}/tags/#{tag_id}"
151
+ )
152
+
153
+ request.perform
154
+ end
155
+
156
+ def delete_tag(screenshot_id = nil, tag_id = nil, project_id = config.project_id)
157
+ screenshot_id || raise_parameter_is_required_error(:screenshot_id)
158
+ tag_id || raise_parameter_is_required_error(:tag_id)
159
+ project_id || raise_project_id_is_required_error
160
+
161
+ request = Web::Request.new(
162
+ self,
163
+ :delete,
164
+ "/projects/#{project_id}/screenshots/#{screenshot_id}/tags/#{tag_id}"
165
+ )
166
+
167
+ request.perform
168
+ end
169
+
170
+ def edit_tag(screenshot_id = nil, tag_id = nil, query = {}, project_id = config.project_id)
171
+ screenshot_id || raise_parameter_is_required_error(:screenshot_id)
172
+ tag_id || raise_parameter_is_required_error(:tag_id)
173
+ project_id || raise_project_id_is_required_error
174
+
175
+ request = Web::Request.new(
176
+ self,
177
+ :patch,
178
+ "/projects/#{project_id}/screenshots/#{screenshot_id}/tags/#{tag_id}",
179
+ query
180
+ )
181
+
182
+ request.perform
183
+ end
184
+ end
185
+ end
186
+ end
@@ -148,6 +148,7 @@ module Crowdin
148
148
  request.perform
149
149
  end
150
150
 
151
+ #
151
152
  # Add custom language.
152
153
  #
153
154
  # === Parameters
@@ -233,8 +234,7 @@ module Crowdin
233
234
  request.perform
234
235
  end
235
236
 
236
- def download_file(destination = nil, file_id = nil, project_id = config.project_id)
237
- destination || raise_parameter_is_required_error(:destination)
237
+ def download_file(file_id = nil, destination = nil, project_id = config.project_id)
238
238
  file_id || raise_parameter_is_required_error(:file_id)
239
239
  project_id || raise_project_id_is_required_error
240
240
 
@@ -250,6 +250,7 @@ module Crowdin
250
250
  request.perform
251
251
  end
252
252
 
253
+ #
253
254
  # List file revisions.
254
255
  #
255
256
  # === Parameters
@@ -3,6 +3,7 @@
3
3
  module Crowdin
4
4
  module ApiResources
5
5
  module Storages
6
+ #
6
7
  # Get storages list.
7
8
  #
8
9
  # === Parameters
@@ -26,11 +27,12 @@ module Crowdin
26
27
  request.perform
27
28
  end
28
29
 
30
+ #
29
31
  # Add storage.
30
32
  #
31
33
  # === Parameters
32
34
  #
33
- # * +File+ - File class object or path to file
35
+ # * +File+ - File class object or full path to file
34
36
  #
35
37
  # === Example
36
38
  #
@@ -54,6 +56,7 @@ module Crowdin
54
56
  request.perform
55
57
  end
56
58
 
59
+ #
57
60
  # Get storage information.
58
61
  #
59
62
  # === Parameters
@@ -76,6 +79,7 @@ module Crowdin
76
79
  request.perform
77
80
  end
78
81
 
82
+ #
79
83
  # Delete storage.
80
84
  #
81
85
  # === Parameters
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crowdin
4
+ module ApiResources
5
+ module StringComments
6
+ def list_string_comments(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}/comments",
13
+ query
14
+ )
15
+
16
+ request.perform
17
+ end
18
+
19
+ def add_string_comment(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}/comments",
26
+ query
27
+ )
28
+
29
+ request.perform
30
+ end
31
+
32
+ def get_string_comment(string_comment_id = nil, project_id = config.project_id)
33
+ string_comment_id || raise_parameter_is_required_error(:string_comment_id)
34
+ project_id || raise_project_id_is_required_error
35
+
36
+ request = Web::Request.new(
37
+ self,
38
+ :get,
39
+ "/projects/#{project_id}/comments/#{string_comment_id}"
40
+ )
41
+
42
+ request.perform
43
+ end
44
+
45
+ def delete_string_comment(string_comment_id = nil, project_id = config.project_id)
46
+ string_comment_id || raise_parameter_is_required_error(:string_comment_id)
47
+ project_id || raise_project_id_is_required_error
48
+
49
+ request = Web::Request.new(
50
+ self,
51
+ :delete,
52
+ "/projects/#{project_id}/comments/#{string_comment_id}"
53
+ )
54
+
55
+ request.perform
56
+ end
57
+
58
+ def edit_string_comment(string_comment_id = nil, query = {}, project_id = config.project_id)
59
+ string_comment_id || raise_parameter_is_required_error(:string_comment_id)
60
+ project_id || raise_project_id_is_required_error
61
+
62
+ request = Web::Request.new(
63
+ self,
64
+ :patch,
65
+ "/projects/#{project_id}/comments/#{string_comment_id}",
66
+ query
67
+ )
68
+
69
+ request.perform
70
+ end
71
+ end
72
+ end
73
+ end