deepl-rb 2.5.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/add_issues_to_kanban.yml +16 -0
  3. data/.gitlab-ci.yml +135 -0
  4. data/.rubocop.yml +27 -0
  5. data/CHANGELOG.md +34 -0
  6. data/CODE_OF_CONDUCT.md +132 -0
  7. data/CONTRIBUTING.md +37 -0
  8. data/Gemfile +3 -1
  9. data/LICENSE.md +1 -0
  10. data/README.md +115 -5
  11. data/Rakefile +7 -5
  12. data/SECURITY.md +58 -0
  13. data/VERSION +1 -1
  14. data/deepl-rb.gemspec +36 -20
  15. data/lib/deepl/api.rb +11 -1
  16. data/lib/deepl/configuration.rb +34 -3
  17. data/lib/deepl/document_api.rb +120 -0
  18. data/lib/deepl/exceptions/authorization_failed.rb +3 -0
  19. data/lib/deepl/exceptions/bad_request.rb +3 -0
  20. data/lib/deepl/exceptions/document_translation_error.rb +15 -0
  21. data/lib/deepl/exceptions/error.rb +6 -0
  22. data/lib/deepl/exceptions/limit_exceeded.rb +7 -0
  23. data/lib/deepl/exceptions/not_found.rb +3 -0
  24. data/lib/deepl/exceptions/not_supported.rb +3 -0
  25. data/lib/deepl/exceptions/quota_exceeded.rb +3 -0
  26. data/lib/deepl/exceptions/request_entity_too_large.rb +4 -1
  27. data/lib/deepl/exceptions/request_error.rb +4 -2
  28. data/lib/deepl/exceptions/server_error.rb +18 -0
  29. data/lib/deepl/glossary_api.rb +3 -0
  30. data/lib/deepl/requests/base.rb +89 -34
  31. data/lib/deepl/requests/document/download.rb +44 -0
  32. data/lib/deepl/requests/document/get_status.rb +44 -0
  33. data/lib/deepl/requests/document/upload.rb +64 -0
  34. data/lib/deepl/requests/glossary/create.rb +15 -1
  35. data/lib/deepl/requests/glossary/destroy.rb +8 -1
  36. data/lib/deepl/requests/glossary/entries.rb +8 -1
  37. data/lib/deepl/requests/glossary/find.rb +8 -1
  38. data/lib/deepl/requests/glossary/language_pairs.rb +9 -2
  39. data/lib/deepl/requests/glossary/list.rb +9 -2
  40. data/lib/deepl/requests/languages.rb +9 -2
  41. data/lib/deepl/requests/translate.rb +33 -11
  42. data/lib/deepl/requests/usage.rb +9 -2
  43. data/lib/deepl/resources/base.rb +3 -0
  44. data/lib/deepl/resources/document_handle.rb +57 -0
  45. data/lib/deepl/resources/document_translation_status.rb +54 -0
  46. data/lib/deepl/resources/glossary.rb +3 -0
  47. data/lib/deepl/resources/language.rb +3 -0
  48. data/lib/deepl/resources/language_pair.rb +3 -0
  49. data/lib/deepl/resources/text.rb +3 -0
  50. data/lib/deepl/resources/usage.rb +3 -0
  51. data/lib/deepl/utils/backoff_timer.rb +46 -0
  52. data/lib/deepl/utils/exception_builder.rb +18 -13
  53. data/lib/deepl.rb +47 -0
  54. data/lib/http_client_options.rb +22 -0
  55. data/license_checker.sh +8 -0
  56. data/spec/api/api_spec.rb +8 -4
  57. data/spec/api/configuration_spec.rb +92 -18
  58. data/spec/api/deepl_spec.rb +225 -86
  59. data/spec/fixtures/vcr_cassettes/deepl_document.yml +95 -0
  60. data/spec/fixtures/vcr_cassettes/deepl_document_download.yml +1214 -0
  61. data/spec/fixtures/vcr_cassettes/deepl_glossaries.yml +812 -23
  62. data/spec/fixtures/vcr_cassettes/deepl_languages.yml +28 -17
  63. data/spec/fixtures/vcr_cassettes/deepl_translate.yml +161 -53
  64. data/spec/fixtures/vcr_cassettes/deepl_usage.yml +93 -3
  65. data/spec/fixtures/vcr_cassettes/glossaries.yml +1237 -15
  66. data/spec/fixtures/vcr_cassettes/languages.yml +159 -44
  67. data/spec/fixtures/vcr_cassettes/translate_texts.yml +9742 -12
  68. data/spec/fixtures/vcr_cassettes/usage.yml +134 -2
  69. data/spec/integration_tests/document_api_spec.rb +143 -0
  70. data/spec/integration_tests/integration_test_utils.rb +170 -0
  71. data/spec/requests/glossary/create_spec.rb +23 -13
  72. data/spec/requests/glossary/destroy_spec.rb +33 -17
  73. data/spec/requests/glossary/entries_spec.rb +31 -17
  74. data/spec/requests/glossary/find_spec.rb +31 -17
  75. data/spec/requests/glossary/language_pairs_spec.rb +17 -7
  76. data/spec/requests/glossary/list_spec.rb +21 -11
  77. data/spec/requests/languages_spec.rb +31 -21
  78. data/spec/requests/translate_spec.rb +125 -131
  79. data/spec/requests/usage_spec.rb +17 -7
  80. data/spec/resources/glossary_spec.rb +15 -12
  81. data/spec/resources/language_pair_spec.rb +10 -7
  82. data/spec/resources/language_spec.rb +21 -18
  83. data/spec/resources/text_spec.rb +10 -7
  84. data/spec/resources/usage_spec.rb +16 -13
  85. data/spec/spec_helper.rb +63 -6
  86. metadata +32 -9
@@ -2,10 +2,10 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://api-free.deepl.com/v2/languages
5
+ uri: https://api.deepl.com/v2/languages
6
6
  body:
7
- encoding: US-ASCII
8
- string: ''
7
+ encoding: UTF-8
8
+ string: "{}"
9
9
  headers:
10
10
  Authorization:
11
11
  - DeepL-Auth-Key VALID_TOKEN
@@ -13,102 +13,217 @@ http_interactions:
13
13
  - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
14
  Accept:
15
15
  - "*/*"
16
- User-Agent:
17
- - Ruby
18
16
  response:
19
17
  status:
20
18
  code: 200
21
19
  message: OK
22
20
  headers:
23
- Server:
24
- - nginx
25
21
  Date:
26
- - Mon, 17 May 2021 14:49:42 GMT
22
+ - Mon, 08 Jul 2024 09:58:27 GMT
27
23
  Content-Type:
28
24
  - application/json
29
- Content-Length:
30
- - '845'
31
- Connection:
32
- - keep-alive
25
+ Transfer-Encoding:
26
+ - chunked
27
+ Vary:
28
+ - Accept-Encoding
33
29
  Access-Control-Allow-Origin:
34
30
  - "*"
31
+ X-Cache-Status:
32
+ - MISS
33
+ Strict-Transport-Security:
34
+ - max-age=63072000; includeSubDomains; preload
35
+ Server-Timing:
36
+ - l7_lb_tls;dur=108, l7_lb_idle;dur=0, l7_lb_receive;dur=1, l7_lb_total;dur=111
37
+ Access-Control-Expose-Headers:
38
+ - Server-Timing, X-Trace-ID
39
+ X-Trace-Id:
40
+ - 219e287aedb54e73953a9e3efba26e13
35
41
  body:
36
- encoding: UTF-8
37
- string: '[{"language":"BG","name":"Bulgarian"},{"language":"CS","name":"Czech"},{"language":"DA","name":"Danish"},{"language":"DE","name":"German"},{"language":"EL","name":"Greek"},{"language":"EN","name":"English"},{"language":"ES","name":"Spanish"},{"language":"ET","name":"Estonian"},{"language":"FI","name":"Finnish"},{"language":"FR","name":"French"},{"language":"HU","name":"Hungarian"},{"language":"IT","name":"Italian"},{"language":"JA","name":"Japanese"},{"language":"LT","name":"Lithuanian"},{"language":"LV","name":"Latvian"},{"language":"NL","name":"Dutch"},{"language":"PL","name":"Polish"},{"language":"PT","name":"Portuguese"},{"language":"RO","name":"Romanian"},{"language":"RU","name":"Russian"},{"language":"SK","name":"Slovak"},{"language":"SL","name":"Slovenian"},{"language":"SV","name":"Swedish"},{"language":"ZH","name":"Chinese"}]'
38
- recorded_at: Mon, 17 May 2021 14:49:42 GMT
42
+ encoding: ASCII-8BIT
43
+ string: '[{"language":"BG","name":"Bulgarian"},{"language":"CS","name":"Czech"},{"language":"DA","name":"Danish"},{"language":"DE","name":"German"},{"language":"EL","name":"Greek"},{"language":"EN","name":"English"},{"language":"ES","name":"Spanish"},{"language":"ET","name":"Estonian"},{"language":"FI","name":"Finnish"},{"language":"FR","name":"French"},{"language":"HU","name":"Hungarian"},{"language":"ID","name":"Indonesian"},{"language":"IT","name":"Italian"},{"language":"JA","name":"Japanese"},{"language":"KO","name":"Korean"},{"language":"LT","name":"Lithuanian"},{"language":"LV","name":"Latvian"},{"language":"NB","name":"Norwegian"},{"language":"NL","name":"Dutch"},{"language":"PL","name":"Polish"},{"language":"PT","name":"Portuguese"},{"language":"RO","name":"Romanian"},{"language":"RU","name":"Russian"},{"language":"SK","name":"Slovak"},{"language":"SL","name":"Slovenian"},{"language":"SV","name":"Swedish"},{"language":"TR","name":"Turkish"},{"language":"UK","name":"Ukrainian"},{"language":"ZH","name":"Chinese"}]'
44
+ recorded_at: Mon, 08 Jul 2024 09:58:27 GMT
39
45
  - request:
40
46
  method: get
41
- uri: https://api-free.deepl.com/v2/languages?type=target
47
+ uri: https://api.deepl.com/v2/languages
42
48
  body:
43
- encoding: US-ASCII
44
- string: ''
49
+ encoding: UTF-8
50
+ string: "{}"
45
51
  headers:
46
52
  Authorization:
47
53
  - DeepL-Auth-Key VALID_TOKEN
54
+ User-Agent:
55
+ - deepl-ruby/2.5.3 (darwin23) ruby/3.3.3
56
+ Content-Type:
57
+ - application/json
48
58
  Accept-Encoding:
49
59
  - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
50
60
  Accept:
51
61
  - "*/*"
52
- User-Agent:
53
- - Ruby
54
62
  response:
55
63
  status:
56
64
  code: 200
57
65
  message: OK
58
66
  headers:
59
- Server:
60
- - nginx
61
67
  Date:
62
- - Mon, 17 May 2021 14:55:30 GMT
68
+ - Mon, 08 Jul 2024 11:27:22 GMT
63
69
  Content-Type:
64
70
  - application/json
65
- Content-Length:
66
- - '1667'
67
- Connection:
68
- - keep-alive
71
+ Transfer-Encoding:
72
+ - chunked
73
+ Vary:
74
+ - Accept-Encoding
69
75
  Access-Control-Allow-Origin:
70
76
  - "*"
77
+ X-Cache-Status:
78
+ - MISS
79
+ Strict-Transport-Security:
80
+ - max-age=63072000; includeSubDomains; preload
81
+ Server-Timing:
82
+ - l7_lb_tls;dur=101, l7_lb_idle;dur=1, l7_lb_receive;dur=0, l7_lb_total;dur=124
83
+ Access-Control-Expose-Headers:
84
+ - Server-Timing, X-Trace-ID
85
+ X-Trace-Id:
86
+ - a6ee4f394fe142e398267aa0ba99e1db
87
+ body:
88
+ encoding: ASCII-8BIT
89
+ string: '[{"language":"BG","name":"Bulgarian"},{"language":"CS","name":"Czech"},{"language":"DA","name":"Danish"},{"language":"DE","name":"German"},{"language":"EL","name":"Greek"},{"language":"EN","name":"English"},{"language":"ES","name":"Spanish"},{"language":"ET","name":"Estonian"},{"language":"FI","name":"Finnish"},{"language":"FR","name":"French"},{"language":"HU","name":"Hungarian"},{"language":"ID","name":"Indonesian"},{"language":"IT","name":"Italian"},{"language":"JA","name":"Japanese"},{"language":"KO","name":"Korean"},{"language":"LT","name":"Lithuanian"},{"language":"LV","name":"Latvian"},{"language":"NB","name":"Norwegian"},{"language":"NL","name":"Dutch"},{"language":"PL","name":"Polish"},{"language":"PT","name":"Portuguese"},{"language":"RO","name":"Romanian"},{"language":"RU","name":"Russian"},{"language":"SK","name":"Slovak"},{"language":"SL","name":"Slovenian"},{"language":"SV","name":"Swedish"},{"language":"TR","name":"Turkish"},{"language":"UK","name":"Ukrainian"},{"language":"ZH","name":"Chinese"}]'
90
+ recorded_at: Mon, 08 Jul 2024 11:27:22 GMT
91
+ - request:
92
+ method: get
93
+ uri: https://api.deepl.com/v2/languages
71
94
  body:
72
95
  encoding: UTF-8
96
+ string: '{"type":"target"}'
97
+ headers:
98
+ Authorization:
99
+ - DeepL-Auth-Key VALID_TOKEN
100
+ User-Agent:
101
+ - deepl-ruby/2.5.3 (darwin23) ruby/3.3.3
102
+ Content-Type:
103
+ - application/json
104
+ Accept-Encoding:
105
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
106
+ Accept:
107
+ - "*/*"
108
+ response:
109
+ status:
110
+ code: 200
111
+ message: OK
112
+ headers:
113
+ Date:
114
+ - Mon, 08 Jul 2024 11:27:22 GMT
115
+ Content-Type:
116
+ - application/json
117
+ Transfer-Encoding:
118
+ - chunked
119
+ Vary:
120
+ - Accept-Encoding
121
+ Access-Control-Allow-Origin:
122
+ - "*"
123
+ X-Cache-Status:
124
+ - MISS
125
+ Strict-Transport-Security:
126
+ - max-age=63072000; includeSubDomains; preload
127
+ Server-Timing:
128
+ - l7_lb_tls;dur=185, l7_lb_idle;dur=2, l7_lb_receive;dur=0, l7_lb_total;dur=213
129
+ Access-Control-Expose-Headers:
130
+ - Server-Timing, X-Trace-ID
131
+ X-Trace-Id:
132
+ - d6a4a3b54c1b453d8ecd106a16d69b53
133
+ body:
134
+ encoding: ASCII-8BIT
73
135
  string: '[{"language":"BG","name":"Bulgarian","supports_formality":false},{"language":"CS","name":"Czech","supports_formality":false},{"language":"DA","name":"Danish","supports_formality":false},{"language":"DE","name":"German","supports_formality":true},{"language":"EL","name":"Greek","supports_formality":false},{"language":"EN-GB","name":"English
74
136
  (British)","supports_formality":false},{"language":"EN-US","name":"English
75
- (American)","supports_formality":false},{"language":"ES","name":"Spanish","supports_formality":true},{"language":"ET","name":"Estonian","supports_formality":false},{"language":"FI","name":"Finnish","supports_formality":false},{"language":"FR","name":"French","supports_formality":true},{"language":"HU","name":"Hungarian","supports_formality":false},{"language":"IT","name":"Italian","supports_formality":true},{"language":"JA","name":"Japanese","supports_formality":false},{"language":"LT","name":"Lithuanian","supports_formality":false},{"language":"LV","name":"Latvian","supports_formality":false},{"language":"NL","name":"Dutch","supports_formality":true},{"language":"PL","name":"Polish","supports_formality":true},{"language":"PT-BR","name":"Portuguese
137
+ (American)","supports_formality":false},{"language":"ES","name":"Spanish","supports_formality":true},{"language":"ET","name":"Estonian","supports_formality":false},{"language":"FI","name":"Finnish","supports_formality":false},{"language":"FR","name":"French","supports_formality":true},{"language":"HU","name":"Hungarian","supports_formality":false},{"language":"ID","name":"Indonesian","supports_formality":false},{"language":"IT","name":"Italian","supports_formality":true},{"language":"JA","name":"Japanese","supports_formality":true},{"language":"KO","name":"Korean","supports_formality":false},{"language":"LT","name":"Lithuanian","supports_formality":false},{"language":"LV","name":"Latvian","supports_formality":false},{"language":"NB","name":"Norwegian","supports_formality":false},{"language":"NL","name":"Dutch","supports_formality":true},{"language":"PL","name":"Polish","supports_formality":true},{"language":"PT-BR","name":"Portuguese
76
138
  (Brazilian)","supports_formality":true},{"language":"PT-PT","name":"Portuguese
77
- (European)","supports_formality":true},{"language":"RO","name":"Romanian","supports_formality":false},{"language":"RU","name":"Russian","supports_formality":true},{"language":"SK","name":"Slovak","supports_formality":false},{"language":"SL","name":"Slovenian","supports_formality":false},{"language":"SV","name":"Swedish","supports_formality":false},{"language":"ZH","name":"Chinese","supports_formality":false}]'
78
- recorded_at: Mon, 17 May 2021 14:55:30 GMT
139
+ (European)","supports_formality":true},{"language":"RO","name":"Romanian","supports_formality":false},{"language":"RU","name":"Russian","supports_formality":true},{"language":"SK","name":"Slovak","supports_formality":false},{"language":"SL","name":"Slovenian","supports_formality":false},{"language":"SV","name":"Swedish","supports_formality":false},{"language":"TR","name":"Turkish","supports_formality":false},{"language":"UK","name":"Ukrainian","supports_formality":false},{"language":"ZH","name":"Chinese
140
+ (simplified)","supports_formality":false}]'
141
+ recorded_at: Mon, 08 Jul 2024 11:27:22 GMT
79
142
  - request:
80
143
  method: get
81
- uri: https://api-free.deepl.com/v2/languages?type=invalid
144
+ uri: https://api.deepl.com/v2/languages
82
145
  body:
83
- encoding: US-ASCII
84
- string: ''
146
+ encoding: UTF-8
147
+ string: '{"type":"invalid"}'
85
148
  headers:
86
149
  Authorization:
87
150
  - DeepL-Auth-Key VALID_TOKEN
151
+ User-Agent:
152
+ - deepl-ruby/2.5.3 (darwin23) ruby/3.3.3
153
+ Content-Type:
154
+ - application/json
88
155
  Accept-Encoding:
89
156
  - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
90
157
  Accept:
91
158
  - "*/*"
92
- User-Agent:
93
- - Ruby
94
159
  response:
95
160
  status:
96
161
  code: 400
97
162
  message: Bad Request
98
163
  headers:
99
- Server:
100
- - nginx
101
164
  Date:
102
- - Mon, 17 May 2021 14:57:00 GMT
103
- Content-Length:
104
- - '82'
105
- Connection:
106
- - keep-alive
165
+ - Mon, 08 Jul 2024 11:27:22 GMT
166
+ Content-Type:
167
+ - application/json
168
+ Transfer-Encoding:
169
+ - chunked
107
170
  Access-Control-Allow-Origin:
108
171
  - "*"
172
+ Strict-Transport-Security:
173
+ - max-age=63072000; includeSubDomains; preload
174
+ Server-Timing:
175
+ - l7_lb_tls;dur=129, l7_lb_idle;dur=2, l7_lb_receive;dur=0, l7_lb_total;dur=148
176
+ Access-Control-Expose-Headers:
177
+ - Server-Timing, X-Trace-ID
178
+ X-Trace-Id:
179
+ - 13e4846db29d425397f8f13783631f53
109
180
  body:
110
181
  encoding: UTF-8
111
182
  string: '{"message":"Parameter ''type'' is invalid. ''source'' and ''target''
112
183
  are valid values."}'
113
- recorded_at: Mon, 17 May 2021 14:57:00 GMT
114
- recorded_with: VCR 6.0.0
184
+ recorded_at: Mon, 08 Jul 2024 11:27:22 GMT
185
+ - request:
186
+ method: get
187
+ uri: https://api.deepl.com/v2/languages
188
+ body:
189
+ encoding: UTF-8
190
+ string: "{}"
191
+ headers:
192
+ Authorization:
193
+ - DeepL-Auth-Key VALID_TOKEN
194
+ Content-Type:
195
+ - application/json
196
+ Accept-Encoding:
197
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
198
+ Accept:
199
+ - "*/*"
200
+ response:
201
+ status:
202
+ code: 200
203
+ message: OK
204
+ headers:
205
+ Date:
206
+ - Tue, 09 Jul 2024 09:34:12 GMT
207
+ Content-Type:
208
+ - application/json
209
+ Transfer-Encoding:
210
+ - chunked
211
+ Vary:
212
+ - Accept-Encoding
213
+ Access-Control-Allow-Origin:
214
+ - "*"
215
+ X-Cache-Status:
216
+ - MISS
217
+ Strict-Transport-Security:
218
+ - max-age=63072000; includeSubDomains; preload
219
+ Server-Timing:
220
+ - l7_lb_tls;dur=101, l7_lb_idle;dur=1, l7_lb_receive;dur=0, l7_lb_total;dur=121
221
+ Access-Control-Expose-Headers:
222
+ - Server-Timing, X-Trace-ID
223
+ X-Trace-Id:
224
+ - 43c2bc53a69c40dfb2e30f58fca8c3ef
225
+ body:
226
+ encoding: ASCII-8BIT
227
+ string: '[{"language":"BG","name":"Bulgarian"},{"language":"CS","name":"Czech"},{"language":"DA","name":"Danish"},{"language":"DE","name":"German"},{"language":"EL","name":"Greek"},{"language":"EN","name":"English"},{"language":"ES","name":"Spanish"},{"language":"ET","name":"Estonian"},{"language":"FI","name":"Finnish"},{"language":"FR","name":"French"},{"language":"HU","name":"Hungarian"},{"language":"ID","name":"Indonesian"},{"language":"IT","name":"Italian"},{"language":"JA","name":"Japanese"},{"language":"KO","name":"Korean"},{"language":"LT","name":"Lithuanian"},{"language":"LV","name":"Latvian"},{"language":"NB","name":"Norwegian"},{"language":"NL","name":"Dutch"},{"language":"PL","name":"Polish"},{"language":"PT","name":"Portuguese"},{"language":"RO","name":"Romanian"},{"language":"RU","name":"Russian"},{"language":"SK","name":"Slovak"},{"language":"SL","name":"Slovenian"},{"language":"SV","name":"Swedish"},{"language":"TR","name":"Turkish"},{"language":"UK","name":"Ukrainian"},{"language":"ZH","name":"Chinese"}]'
228
+ recorded_at: Tue, 09 Jul 2024 09:34:12 GMT
229
+ recorded_with: VCR 6.2.0