crowdin-api 1.4.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,167 +1,231 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Crowdin::ApiResources::Glossaries do
4
- describe 'Default endpoints' do
5
- describe '#list_glossaries' do
6
- it 'when request are valid', :default do
7
- stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries")
8
- list_glossaries = @crowdin.list_glossaries
9
- expect(list_glossaries).to eq(200)
10
- end
3
+ describe Crowdin::ApiResources::Glossaries, 'Default endpoints' do
4
+ describe '#list_glossaries' do
5
+ it 'when request are valid', :default do
6
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries")
7
+ list_glossaries = @crowdin.list_glossaries
8
+ expect(list_glossaries).to eq(200)
11
9
  end
10
+ end
12
11
 
13
- describe '#add_glossary' do
14
- it 'when request are valid', :default do
15
- stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries")
16
- add_glossary = @crowdin.add_glossary
17
- expect(add_glossary).to eq(200)
18
- end
12
+ describe '#add_glossary' do
13
+ it 'when request are valid', :default do
14
+ stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries")
15
+ add_glossary = @crowdin.add_glossary
16
+ expect(add_glossary).to eq(200)
19
17
  end
18
+ end
20
19
 
21
- describe '#get_glossary' do
22
- let(:glossary_id) { 1 }
20
+ describe '#get_glossary' do
21
+ let(:glossary_id) { 1 }
23
22
 
24
- it 'when request are valid', :default do
25
- stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}")
26
- get_glossary = @crowdin.get_glossary(glossary_id)
27
- expect(get_glossary).to eq(200)
28
- end
23
+ it 'when request are valid', :default do
24
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}")
25
+ get_glossary = @crowdin.get_glossary(glossary_id)
26
+ expect(get_glossary).to eq(200)
29
27
  end
28
+ end
30
29
 
31
- describe '#delete_glossary' do
32
- let(:glossary_id) { 1 }
30
+ describe '#delete_glossary' do
31
+ let(:glossary_id) { 1 }
33
32
 
34
- it 'when request are valid', :default do
35
- stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}")
36
- delete_glossary = @crowdin.delete_glossary(glossary_id)
37
- expect(delete_glossary).to eq(200)
38
- end
33
+ it 'when request are valid', :default do
34
+ stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}")
35
+ delete_glossary = @crowdin.delete_glossary(glossary_id)
36
+ expect(delete_glossary).to eq(200)
39
37
  end
38
+ end
40
39
 
41
- describe '#edit_glossary' do
42
- let(:glossary_id) { 1 }
40
+ describe '#edit_glossary' do
41
+ let(:glossary_id) { 1 }
43
42
 
44
- it 'when request are valid', :default do
45
- stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}")
46
- edit_glossary = @crowdin.edit_glossary(glossary_id)
47
- expect(edit_glossary).to eq(200)
48
- end
43
+ it 'when request are valid', :default do
44
+ stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}")
45
+ edit_glossary = @crowdin.edit_glossary(glossary_id)
46
+ expect(edit_glossary).to eq(200)
49
47
  end
48
+ end
50
49
 
51
- describe '#export_glossary' do
52
- let(:glossary_id) { 1 }
50
+ describe '#export_glossary' do
51
+ let(:glossary_id) { 1 }
53
52
 
54
- it 'when request are valid', :default do
55
- stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/exports")
56
- export_glossary = @crowdin.export_glossary({}, glossary_id)
57
- expect(export_glossary).to eq(200)
58
- end
53
+ it 'when request are valid', :default do
54
+ stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/exports")
55
+ export_glossary = @crowdin.export_glossary({}, glossary_id)
56
+ expect(export_glossary).to eq(200)
59
57
  end
58
+ end
60
59
 
61
- describe '#check_glossary_export_status' do
62
- let(:glossary_id) { 1 }
63
- let(:export_id) { 1 }
60
+ describe '#check_glossary_export_status' do
61
+ let(:glossary_id) { 1 }
62
+ let(:export_id) { 1 }
64
63
 
65
- it 'when request are valid', :default do
66
- stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/exports/#{export_id}")
67
- check_glossary_export_status = @crowdin.check_glossary_export_status(glossary_id, export_id)
68
- expect(check_glossary_export_status).to eq(200)
69
- end
64
+ it 'when request are valid', :default do
65
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/exports/#{export_id}")
66
+ check_glossary_export_status = @crowdin.check_glossary_export_status(glossary_id, export_id)
67
+ expect(check_glossary_export_status).to eq(200)
70
68
  end
69
+ end
71
70
 
72
- describe '#download_glossary' do
73
- let(:glossary_id) { 1 }
74
- let(:export_id) { 1 }
71
+ describe '#download_glossary' do
72
+ let(:glossary_id) { 1 }
73
+ let(:export_id) { 1 }
75
74
 
76
- it 'when request are valid', :default do
77
- stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/exports/#{export_id}/download")
78
- download_glossary = @crowdin.download_glossary(glossary_id, export_id)
79
- expect(download_glossary).to eq(200)
80
- end
75
+ it 'when request are valid', :default do
76
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/exports/#{export_id}/download")
77
+ download_glossary = @crowdin.download_glossary(glossary_id, export_id)
78
+ expect(download_glossary).to eq(200)
81
79
  end
80
+ end
82
81
 
83
- describe '#import_glossary' do
84
- let(:glossary_id) { 1 }
82
+ describe '#import_glossary' do
83
+ let(:glossary_id) { 1 }
85
84
 
86
- it 'when request are valid', :default do
87
- stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/imports")
88
- import_glossary = @crowdin.import_glossary(glossary_id)
89
- expect(import_glossary).to eq(200)
90
- end
85
+ it 'when request are valid', :default do
86
+ stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/imports")
87
+ import_glossary = @crowdin.import_glossary(glossary_id)
88
+ expect(import_glossary).to eq(200)
91
89
  end
90
+ end
92
91
 
93
- describe '#check_glossary_import_status' do
94
- let(:glossary_id) { 1 }
95
- let(:import_id) { 1 }
92
+ describe '#check_glossary_import_status' do
93
+ let(:glossary_id) { 1 }
94
+ let(:import_id) { 1 }
96
95
 
97
- it 'when request are valid', :default do
98
- stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/imports/#{import_id}")
99
- check_glossary_import_status = @crowdin.check_glossary_import_status(glossary_id, import_id)
100
- expect(check_glossary_import_status).to eq(200)
101
- end
96
+ it 'when request are valid', :default do
97
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/imports/#{import_id}")
98
+ check_glossary_import_status = @crowdin.check_glossary_import_status(glossary_id, import_id)
99
+ expect(check_glossary_import_status).to eq(200)
102
100
  end
101
+ end
103
102
 
104
- describe '#list_terms' do
105
- let(:glossary_id) { 1 }
103
+ describe '#clear_glossary' do
104
+ let(:glossary_id) { 1 }
106
105
 
107
- it 'when request are valid', :default do
108
- stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms")
109
- list_terms = @crowdin.list_terms(glossary_id)
110
- expect(list_terms).to eq(200)
111
- end
106
+ it 'when request are valid', :default do
107
+ stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms")
108
+ clear_glossary = @crowdin.clear_glossary(glossary_id)
109
+ expect(clear_glossary).to eq(200)
112
110
  end
111
+ end
112
+
113
+ describe '#search_glossaries_concordance' do
114
+ let(:project_id) { 1 }
113
115
 
114
- describe '#add_term' do
115
- let(:glossary_id) { 1 }
116
+ it 'returns 200 when request is valid', :default do
117
+ query = { source_language_id: 'en', target_language_id: 'ar', expression: 'Hello world!' }
118
+ stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/glossaries/concordance")
119
+ search_glossaries_concordance = @crowdin.search_glossaries_concordance(project_id, query)
120
+ expect(search_glossaries_concordance).to eq(200)
121
+ end
116
122
 
117
- it 'when request are valid', :default do
118
- stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms")
119
- add_term = @crowdin.add_term(glossary_id)
120
- expect(add_term).to eq(200)
121
- end
123
+ it 'raises ArgumentError when request is missing required query parameter', :default do
124
+ query = { source_language_id: 'en', target_language_id: 'ar' }
125
+ stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/glossaries/concordance")
126
+ expect do
127
+ @crowdin.search_glossaries_concordance(project_id, query)
128
+ end.to raise_error(ArgumentError, ':expression is required')
122
129
  end
130
+ end
131
+ end
123
132
 
124
- describe '#clear_glossary' do
125
- let(:glossary_id) { 1 }
133
+ describe Crowdin::ApiResources::Glossaries, 'Concept endpoints' do
134
+ describe '#list_concepts' do
135
+ let(:glossary_id) { 1 }
126
136
 
127
- it 'when request are valid', :default do
128
- stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms")
129
- clear_glossary = @crowdin.clear_glossary(glossary_id)
130
- expect(clear_glossary).to eq(200)
131
- end
137
+ it 'when request are valid', :default do
138
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/concepts")
139
+ concepts = @crowdin.list_concepts(glossary_id)
140
+ expect(concepts).to eq(200)
132
141
  end
142
+ end
133
143
 
134
- describe '#get_term' do
135
- let(:glossary_id) { 1 }
136
- let(:term_id) { 1 }
144
+ describe '#get_concept' do
145
+ let(:glossary_id) { 1 }
146
+ let(:concept_id) { 1 }
137
147
 
138
- it 'when request are valid', :default do
139
- stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms/#{term_id}")
140
- get_term = @crowdin.get_term(glossary_id, term_id)
141
- expect(get_term).to eq(200)
142
- end
148
+ it 'when request are valid', :default do
149
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/concepts/#{concept_id}")
150
+ concept = @crowdin.get_concept(glossary_id, concept_id)
151
+ expect(concept).to eq(200)
143
152
  end
153
+ end
144
154
 
145
- describe '#delete_term' do
146
- let(:glossary_id) { 1 }
147
- let(:term_id) { 1 }
155
+ describe '#update_concept' do
156
+ let(:glossary_id) { 1 }
157
+ let(:concept_id) { 1 }
148
158
 
149
- it 'when request are valid', :default do
150
- stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms/#{term_id}")
151
- delete_term = @crowdin.delete_term(glossary_id, term_id)
152
- expect(delete_term).to eq(200)
153
- end
159
+ it 'when request are valid', :default do
160
+ stub_request(:put, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/concepts/#{concept_id}")
161
+ concept = @crowdin.update_concept(glossary_id, concept_id)
162
+ expect(concept).to eq(200)
154
163
  end
164
+ end
165
+
166
+ describe '#update_concept' do
167
+ let(:glossary_id) { 1 }
168
+ let(:concept_id) { 1 }
169
+
170
+ it 'when request are valid', :default do
171
+ stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/concepts/#{concept_id}")
172
+ concept = @crowdin.delete_concept(glossary_id, concept_id)
173
+ expect(concept).to eq(200)
174
+ end
175
+ end
176
+ end
177
+
178
+ describe Crowdin::ApiResources::Glossaries, 'Term endpoints' do
179
+ describe '#list_terms' do
180
+ let(:glossary_id) { 1 }
181
+
182
+ it 'when request are valid', :default do
183
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms")
184
+ list_terms = @crowdin.list_terms(glossary_id)
185
+ expect(list_terms).to eq(200)
186
+ end
187
+ end
188
+
189
+ describe '#add_term' do
190
+ let(:glossary_id) { 1 }
191
+
192
+ it 'when request are valid', :default do
193
+ stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms")
194
+ add_term = @crowdin.add_term(glossary_id)
195
+ expect(add_term).to eq(200)
196
+ end
197
+ end
198
+
199
+ describe '#get_term' do
200
+ let(:glossary_id) { 1 }
201
+ let(:term_id) { 1 }
202
+
203
+ it 'when request are valid', :default do
204
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms/#{term_id}")
205
+ get_term = @crowdin.get_term(glossary_id, term_id)
206
+ expect(get_term).to eq(200)
207
+ end
208
+ end
209
+
210
+ describe '#delete_term' do
211
+ let(:glossary_id) { 1 }
212
+ let(:term_id) { 1 }
213
+
214
+ it 'when request are valid', :default do
215
+ stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms/#{term_id}")
216
+ delete_term = @crowdin.delete_term(glossary_id, term_id)
217
+ expect(delete_term).to eq(200)
218
+ end
219
+ end
155
220
 
156
- describe '#edit_term' do
157
- let(:glossary_id) { 1 }
158
- let(:term_id) { 1 }
221
+ describe '#edit_term' do
222
+ let(:glossary_id) { 1 }
223
+ let(:term_id) { 1 }
159
224
 
160
- it 'when request are valid', :default do
161
- stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms/#{term_id}")
162
- edit_term = @crowdin.edit_term(glossary_id, term_id)
163
- expect(edit_term).to eq(200)
164
- end
225
+ it 'when request are valid', :default do
226
+ stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms/#{term_id}")
227
+ edit_term = @crowdin.edit_term(glossary_id, term_id)
228
+ expect(edit_term).to eq(200)
165
229
  end
166
230
  end
167
231
  end
@@ -92,4 +92,54 @@ describe Crowdin::ApiResources::Reports do
92
92
  end
93
93
  end
94
94
  end
95
+
96
+ describe 'Setting Templates endpoints' do
97
+ describe 'List Report Settings templates' do
98
+ it 'when request are valid', :default do
99
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/reports/settings-templates")
100
+ settings_templates = @crowdin.list_report_settings_templates({}, project_id)
101
+ expect(settings_templates).to eq(200)
102
+ end
103
+ end
104
+
105
+ describe 'Add Report Settings template' do
106
+ it 'when request are valid', :default do
107
+ stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/reports/settings-templates")
108
+ settings_templates = @crowdin.add_report_settings_template(
109
+ { name: '', currency: '', unit: '', mode: '', config: '' }, project_id
110
+ )
111
+ expect(settings_templates).to eq(200)
112
+ end
113
+ end
114
+
115
+ describe 'Get Report Settings template' do
116
+ let(:template_id) { 1 }
117
+
118
+ it 'when request are valid', :default do
119
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/reports/settings-templates/#{template_id}")
120
+ settings_templates = @crowdin.get_report_settings_template(template_id, project_id)
121
+ expect(settings_templates).to eq(200)
122
+ end
123
+ end
124
+
125
+ describe 'Get Report Settings template' do
126
+ let(:template_id) { 1 }
127
+
128
+ it 'when request are valid', :default do
129
+ stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/reports/settings-templates/#{template_id}")
130
+ settings_templates = @crowdin.edit_report_settings_template({}, template_id, project_id)
131
+ expect(settings_templates).to eq(200)
132
+ end
133
+ end
134
+
135
+ describe 'Get Report Settings template' do
136
+ let(:template_id) { 1 }
137
+
138
+ it 'when request are valid', :default do
139
+ stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/reports/settings-templates/#{template_id}")
140
+ settings_templates = @crowdin.delete_report_settings_template(template_id, project_id)
141
+ expect(settings_templates).to eq(200)
142
+ end
143
+ end
144
+ end
95
145
  end
@@ -137,5 +137,24 @@ describe Crowdin::ApiResources::StringTranslations do
137
137
  expect(cancel_vote).to eq(200)
138
138
  end
139
139
  end
140
+
141
+ describe '#add_translation_alignment' do
142
+ let(:project_id) { 1 }
143
+
144
+ it 'returns 200 when request is valid', :default do
145
+ query = { source_language_id: 'en', target_language_id: 'ar', text: 'Hello world!' }
146
+ stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/translations/alignment")
147
+ add_translation_alignment = @crowdin.add_translation_alignment(project_id, query)
148
+ expect(add_translation_alignment).to eq(200)
149
+ end
150
+
151
+ it 'raises ArgumentError when request is missing required query parameter', :default do
152
+ query = { source_language_id: 'en', target_language_id: 'ar' }
153
+ stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/translations/alignment")
154
+ expect do
155
+ @crowdin.add_translation_alignment(project_id, query)
156
+ end.to raise_error(ArgumentError, ':text is required')
157
+ end
158
+ end
140
159
  end
141
160
  end
@@ -110,5 +110,26 @@ describe Crowdin::ApiResources::TranslationMemory do
110
110
  expect(check_tm_import_status).to eq(200)
111
111
  end
112
112
  end
113
+
114
+ describe '#search_tms_concordance' do
115
+ let(:project_id) { 1 }
116
+
117
+ it 'returns 200 when request is valid', :default do
118
+ query = { source_language_id: 'en', target_language_id: 'ar', expression: 'Hello world!',
119
+ auto_substitution: true, min_relevant: 60 }
120
+ stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/tms/concordance")
121
+ search_tms_concordance = @crowdin.search_tms_concordance(project_id, query)
122
+ expect(search_tms_concordance).to eq(200)
123
+ end
124
+
125
+ it 'raises ArgumentError when request is missing required query parameter', :default do
126
+ query = { source_language_id: 'en', target_language_id: 'ar', expression: 'Hello world!',
127
+ auto_substitution: true }
128
+ stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/tms/concordance")
129
+ expect do
130
+ @crowdin.search_tms_concordance(project_id, query)
131
+ end.to raise_error(ArgumentError, ':min_relevant is required')
132
+ end
133
+ end
113
134
  end
114
135
  end
@@ -82,4 +82,16 @@ describe 'Crowdin Client' do
82
82
  expect(@crowdin.config.base_url).to eq("https://#{full_organization_domain}")
83
83
  end
84
84
  end
85
+
86
+ describe 'Crowdin Client fetch_all' do
87
+ it 'should raise error if fetch_all is called for unsupported methods' do
88
+ expect { @crowdin.fetch_all(:add_bundle).to raise_error(Crowdin::Errors::FetchAllProcessingError) }
89
+ end
90
+ end
91
+
92
+ describe 'Crowdin Client fetch_all' do
93
+ it 'should raise error if fetch_all is called for unsupported methods' do
94
+ expect { @crowdin.fetch_all(:export_bundle).to raise_error(Crowdin::Errors::FetchAllProcessingError) }
95
+ end
96
+ end
85
97
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crowdin-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Crowdin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-15 00:00:00.000000000 Z
11
+ date: 2023-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: open-uri
@@ -170,6 +170,8 @@ extensions: []
170
170
  extra_rdoc_files: []
171
171
  files:
172
172
  - ".github/workflows/build-and-publish.yml"
173
+ - ".github/workflows/docs.yml"
174
+ - ".github/workflows/lint-pr-title.yml"
173
175
  - ".github/workflows/test-and-lint.yml"
174
176
  - ".gitignore"
175
177
  - ".rspec"