deepl-rb 2.3.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +7 -4
  3. data/README.md +102 -1
  4. data/VERSION +1 -1
  5. data/deepl-rb.gemspec +25 -4
  6. data/lib/deepl/configuration.rb +1 -1
  7. data/lib/deepl/exceptions/not_found.rb +13 -0
  8. data/lib/deepl/exceptions/not_supported.rb +11 -0
  9. data/lib/deepl/glossary_api.rb +35 -0
  10. data/lib/deepl/requests/base.rb +21 -4
  11. data/lib/deepl/requests/glossary/create.rb +45 -0
  12. data/lib/deepl/requests/glossary/destroy.rb +30 -0
  13. data/lib/deepl/requests/glossary/entries.rb +30 -0
  14. data/lib/deepl/requests/glossary/find.rb +31 -0
  15. data/lib/deepl/requests/glossary/language_pairs.rb +31 -0
  16. data/lib/deepl/requests/glossary/list.rb +30 -0
  17. data/lib/deepl/requests/languages.rb +3 -1
  18. data/lib/deepl/requests/translate.rb +1 -0
  19. data/lib/deepl/resources/glossary.rb +25 -0
  20. data/lib/deepl/resources/language.rb +8 -1
  21. data/lib/deepl/resources/language_pair.rb +20 -0
  22. data/lib/deepl.rb +16 -0
  23. data/spec/api/deepl_spec.rb +189 -0
  24. data/spec/fixtures/vcr_cassettes/deepl_glossaries.yml +374 -0
  25. data/spec/fixtures/vcr_cassettes/deepl_languages.yml +3 -1
  26. data/spec/fixtures/vcr_cassettes/deepl_translate.yml +212 -1
  27. data/spec/fixtures/vcr_cassettes/deepl_usage.yml +3 -1
  28. data/spec/fixtures/vcr_cassettes/glossaries.yml +480 -0
  29. data/spec/fixtures/vcr_cassettes/languages.yml +9 -3
  30. data/spec/fixtures/vcr_cassettes/translate_texts.yml +340 -286
  31. data/spec/fixtures/vcr_cassettes/usage.yml +3 -1
  32. data/spec/requests/glossary/create_spec.rb +55 -0
  33. data/spec/requests/glossary/destroy_spec.rb +50 -0
  34. data/spec/requests/glossary/entries_spec.rb +48 -0
  35. data/spec/requests/glossary/find_spec.rb +54 -0
  36. data/spec/requests/glossary/language_pairs_spec.rb +30 -0
  37. data/spec/requests/glossary/list_spec.rb +44 -0
  38. data/spec/requests/translate_spec.rb +51 -0
  39. data/spec/resources/glossary_spec.rb +35 -0
  40. data/spec/resources/language_pair_spec.rb +20 -0
  41. data/spec/resources/language_spec.rb +23 -1
  42. data/spec/spec_helper.rb +2 -2
  43. metadata +24 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f531ff13d2ba139bab65f6027f2e673f6480b097847d898531ecc7a9b247faea
4
- data.tar.gz: e12727852eff8153dbb3a95d853d0fbd5ef5c703f02eaf7dedd089320e6873a2
3
+ metadata.gz: 50a94f4bc3e0633bf578ae6fd53d794632e2b7a03b8d2a78b9678ed44289043c
4
+ data.tar.gz: 74e5911707588b9fd75684bbdce7092b492deafc5c3cef4e47c2732006a3bfb9
5
5
  SHA512:
6
- metadata.gz: 1d783cba5c207fb772589bc3f328a942919eff214778ea739a6924022bb7589a1898ab62a1cad2b9f6b177f857beb1bd0c5fbe290eba1467c31b26ab9cad461e
7
- data.tar.gz: f14387ba9bc6e7ca3b97176fe1d51f4fa001ca9caba1dc6377d13e4c573896f953575f6efa682bbf55d6704657a53eb73686f9ec51711298549b49a2e5a07701
6
+ metadata.gz: 9700c6128ab06b432596131da46cbdb240c433baeecb2ece7b74860040818fd3a9e32cf9c4a9384a6a8875200c4aa69f0fa74f533ffc6a4aeb9b9736e76b577f
7
+ data.tar.gz: 5a60db0a73691310159cfc92036c36e317f247f7bd0ece2b1002723068ffa531f43d4c96741e25e0fde4aff0fa1dc6c54596d6a91183c8ad4a75eaa62848153a
data/.rubocop.yml CHANGED
@@ -4,14 +4,17 @@ AllCops:
4
4
  DisplayCopNames: true
5
5
  NewCops: enable
6
6
  Exclude:
7
- - deepl-rb.gemspec
8
- - vendor/**/*
7
+ - deepl-rb.gemspec
8
+ - vendor/**/*
9
9
 
10
10
  Metrics/BlockLength:
11
11
  Exclude:
12
- - "**/*_spec.rb"
12
+ - "**/*_spec.rb"
13
13
 
14
- Metrics/LineLength:
14
+ Metrics/ParameterLists:
15
+ Max: 6
16
+
17
+ Layout/LineLength:
15
18
  Max: 100
16
19
 
17
20
  Style/Documentation:
data/README.md CHANGED
@@ -71,7 +71,10 @@ puts DeepL.languages(type: :target).count
71
71
  ```
72
72
 
73
73
  All languages are also defined on the
74
- [official API documentation](https://www.deepl.com/docs-api/translating-text/)
74
+ [official API documentation](https://www.deepl.com/docs-api/translating-text/).
75
+
76
+ Note that target languages may include the `supports_formality` flag, which may be checked
77
+ using the `DeepL::Resources::Language#supports_formality?`.
75
78
 
76
79
  ### Translate
77
80
 
@@ -124,8 +127,105 @@ The following parameters will be automatically converted:
124
127
  | --------------------- | ---------------
125
128
  | `preserve_formatting` | Converts `false` to `'0'` and `true` to `'1'`
126
129
  | `split_sentences` | Converts `false` to `'0'` and `true` to `'1'`
130
+ | `outline_detection` | Converts `false` to `'0'` and `true` to `'1'`
127
131
  | `non_splitting_tags` | Converts arrays to strings joining by commas
128
132
  | `ignore_tags` | Converts arrays to strings joining by commas
133
+ | `formality` | No conversion applied
134
+ | `glossary_id` | No conversion applied
135
+
136
+ ### Glossaries
137
+
138
+ To create a glossary, use the `glossaries.create` method. The glossary `entries` argument should be an array of text pairs. Each pair includes the source and the target translations.
139
+
140
+ ```rb
141
+ entries = [
142
+ ['Hello World', 'Hola Tierra'],
143
+ ['car', 'auto']
144
+ ]
145
+ glossary = DeepL.glossaries.create 'Mi Glosario', 'EN', 'ES', entries
146
+
147
+ puts glossary.class
148
+ # => DeepL::Resources::Glossary
149
+ puts glossary.id
150
+ # => 'aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e'
151
+ puts glossary.entry_count
152
+ # => 2
153
+ ```
154
+
155
+ Created glossaries can be used in the `translate` method by specifying the `glossary_id` option:
156
+
157
+ ```rb
158
+ translation = DeepL.translate 'Hello World', 'EN', 'ES', glossary_id: 'aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e'
159
+
160
+ puts translation.class
161
+ # => DeepL::Resources::Text
162
+ puts translation.text
163
+ # => 'Hola Tierra'
164
+
165
+ translation = DeepL.translate "I wish we had a car.", 'EN', 'ES', glossary_id: 'aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e'
166
+
167
+ puts translation.class
168
+ # => DeepL::Resources::Text
169
+ puts translation.text
170
+ # => Ojalá tuviéramos un auto.
171
+ ```
172
+
173
+ To list all the glossaries available, use the `glossaries.list` method:
174
+
175
+ ```rb
176
+ glossaries = DeepL.glossaries.list
177
+
178
+ puts glossaries.class
179
+ # => Array
180
+ puts glossaries.first.class
181
+ # => DeepL::Resources::Glossary
182
+ ```
183
+
184
+ To find an existing glossary, use the `glossaries.find` method:
185
+
186
+ ```rb
187
+ glossary = DeepL.glossaries.find 'aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e'
188
+
189
+ puts glossary.class
190
+ # => DeepL::Resources::Glossary
191
+ ```
192
+
193
+ The glossary resource does not include the glossary entries. To list the glossary entries, use the `glossaries.entries` method:
194
+
195
+ ```rb
196
+ entries = DeepL.glossaries.entries 'aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e'
197
+
198
+ puts entries.class
199
+ # => Array
200
+ puts entries.size
201
+ # => 2
202
+ pp entries.first
203
+ # => ["Hello World", "Hola Tierra"]
204
+ ```
205
+
206
+ To delete an existing glossary, use the `glossaries.destroy` method:
207
+
208
+ ```rb
209
+ glossary_id = DeepL.glossaries.destroy 'aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e'
210
+
211
+ puts glossary_id
212
+ # => aa48c7f0-0d02-413e-8a06-d5bbf0ca7a6e
213
+ ```
214
+
215
+ You can list all the language pairs supported by glossaries using the `glossaries.language_pairs` method:
216
+
217
+ ```rb
218
+ language_pairs = DeepL.glossaries.language_pairs
219
+
220
+ puts language_pairs.class
221
+ # => Array
222
+ puts language_pairs.first.class
223
+ # => DeepL::Resources::LanguagePair
224
+ puts language_pairs.first.source_lang
225
+ # => en
226
+ puts language_pairs.first.target_lang
227
+ # => de
228
+ ```
129
229
 
130
230
  ### Monitor usage
131
231
 
@@ -151,6 +251,7 @@ You can capture and process exceptions that may be raised during API calls. Thes
151
251
  | `DeepL::Exceptions::LimitExceeded` | You've reached the API's call limit. |
152
252
  | `DeepL::Exceptions::QuotaExceeded` | You've reached the API's character limit. |
153
253
  | `DeepL::Exceptions::RequestError` | An unkown request error. Check `exception.response` and `exception.request` for more information. |
254
+ | `DeepL::Exceptions::NotSupported` | The requested method or API endpoint is not supported. |
154
255
 
155
256
  An exampling of handling a generic exception:
156
257
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.0
1
+ 2.5.0
data/deepl-rb.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: deepl-rb 2.3.0 ruby lib
5
+ # stub: deepl-rb 2.5.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "deepl-rb".freeze
9
- s.version = "2.3.0"
9
+ s.version = "2.5.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Daniel Herzog".freeze]
14
- s.date = "2021-05-17"
14
+ s.date = "2022-06-06"
15
15
  s.description = "A simple ruby wrapper for the DeepL translation API (v1). For more information, check this: https://www.deepl.com/docs/api-reference.html".freeze
16
16
  s.email = "info@danielherzog.es".freeze
17
17
  s.extra_rdoc_files = [
@@ -34,28 +34,49 @@ Gem::Specification.new do |s|
34
34
  "lib/deepl/exceptions/bad_request.rb",
35
35
  "lib/deepl/exceptions/error.rb",
36
36
  "lib/deepl/exceptions/limit_exceeded.rb",
37
+ "lib/deepl/exceptions/not_found.rb",
38
+ "lib/deepl/exceptions/not_supported.rb",
37
39
  "lib/deepl/exceptions/quota_exceeded.rb",
38
40
  "lib/deepl/exceptions/request_error.rb",
41
+ "lib/deepl/glossary_api.rb",
39
42
  "lib/deepl/requests/base.rb",
43
+ "lib/deepl/requests/glossary/create.rb",
44
+ "lib/deepl/requests/glossary/destroy.rb",
45
+ "lib/deepl/requests/glossary/entries.rb",
46
+ "lib/deepl/requests/glossary/find.rb",
47
+ "lib/deepl/requests/glossary/language_pairs.rb",
48
+ "lib/deepl/requests/glossary/list.rb",
40
49
  "lib/deepl/requests/languages.rb",
41
50
  "lib/deepl/requests/translate.rb",
42
51
  "lib/deepl/requests/usage.rb",
43
52
  "lib/deepl/resources/base.rb",
53
+ "lib/deepl/resources/glossary.rb",
44
54
  "lib/deepl/resources/language.rb",
55
+ "lib/deepl/resources/language_pair.rb",
45
56
  "lib/deepl/resources/text.rb",
46
57
  "lib/deepl/resources/usage.rb",
47
58
  "spec/api/api_spec.rb",
48
59
  "spec/api/configuration_spec.rb",
49
60
  "spec/api/deepl_spec.rb",
61
+ "spec/fixtures/vcr_cassettes/deepl_glossaries.yml",
50
62
  "spec/fixtures/vcr_cassettes/deepl_languages.yml",
51
63
  "spec/fixtures/vcr_cassettes/deepl_translate.yml",
52
64
  "spec/fixtures/vcr_cassettes/deepl_usage.yml",
65
+ "spec/fixtures/vcr_cassettes/glossaries.yml",
53
66
  "spec/fixtures/vcr_cassettes/languages.yml",
54
67
  "spec/fixtures/vcr_cassettes/translate_texts.yml",
55
68
  "spec/fixtures/vcr_cassettes/usage.yml",
69
+ "spec/requests/glossary/create_spec.rb",
70
+ "spec/requests/glossary/destroy_spec.rb",
71
+ "spec/requests/glossary/entries_spec.rb",
72
+ "spec/requests/glossary/find_spec.rb",
73
+ "spec/requests/glossary/language_pairs_spec.rb",
74
+ "spec/requests/glossary/list_spec.rb",
56
75
  "spec/requests/languages_spec.rb",
57
76
  "spec/requests/translate_spec.rb",
58
77
  "spec/requests/usage_spec.rb",
78
+ "spec/resources/glossary_spec.rb",
79
+ "spec/resources/language_pair_spec.rb",
59
80
  "spec/resources/language_spec.rb",
60
81
  "spec/resources/text_spec.rb",
61
82
  "spec/resources/usage_spec.rb",
@@ -63,7 +84,7 @@ Gem::Specification.new do |s|
63
84
  ]
64
85
  s.homepage = "http://github.com/wikiti/deepl-rb".freeze
65
86
  s.licenses = ["MIT".freeze]
66
- s.rubygems_version = "3.1.2".freeze
87
+ s.rubygems_version = "3.3.7".freeze
67
88
  s.summary = "A simple ruby wrapper for the DeepL API".freeze
68
89
 
69
90
  if s.respond_to? :specification_version then
@@ -18,7 +18,7 @@ module DeepL
18
18
  end
19
19
 
20
20
  def attributes
21
- ATTRIBUTES.map { |attr| [attr, send(attr)] }.to_h
21
+ ATTRIBUTES.to_h { |attr| [attr, send(attr)] }
22
22
  end
23
23
 
24
24
  def ==(other)
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeepL
4
+ module Exceptions
5
+ class NotFound < RequestError
6
+ def message
7
+ JSON.parse(response.body)['message']
8
+ rescue JSON::ParserError
9
+ response.body
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeepL
4
+ module Exceptions
5
+ class NotSupported < Error
6
+ def initialize(msg = 'The feature is not supported')
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeepL
4
+ class GlossaryApi
5
+ def initialize(api, options = {})
6
+ @api = api
7
+ @options = options
8
+ end
9
+
10
+ def create(name, source_lang, target_lang, entries, options = {})
11
+ DeepL::Requests::Glossary::Create.new(@api, name, source_lang, target_lang, entries, options)
12
+ .request
13
+ end
14
+
15
+ def destroy(glossary_id, options = {})
16
+ DeepL::Requests::Glossary::Destroy.new(@api, glossary_id, options).request
17
+ end
18
+
19
+ def entries(glossary_id, options = {})
20
+ DeepL::Requests::Glossary::Entries.new(@api, glossary_id, options).request
21
+ end
22
+
23
+ def find(glossary_id, options = {})
24
+ DeepL::Requests::Glossary::Find.new(@api, glossary_id, options).request
25
+ end
26
+
27
+ def language_pairs(options = {})
28
+ DeepL::Requests::Glossary::LanguagePairs.new(@api, options).request
29
+ end
30
+
31
+ def list(options = {})
32
+ DeepL::Requests::Glossary::List.new(@api, options).request
33
+ end
34
+ end
35
+ end
@@ -24,6 +24,10 @@ module DeepL
24
24
  options[name.to_s] || options[name.to_sym]
25
25
  end
26
26
 
27
+ def delete_option(name)
28
+ options.delete(name.to_s) || options.delete(name.to_sym)
29
+ end
30
+
27
31
  def set_option(name, value)
28
32
  if options.key?(name.to_sym)
29
33
  options[name.to_sym] = value
@@ -33,7 +37,7 @@ module DeepL
33
37
  end
34
38
 
35
39
  def post(payload)
36
- request = Net::HTTP::Post.new(uri.request_uri)
40
+ request = Net::HTTP::Post.new(uri.request_uri, headers)
37
41
  request.set_form_data(payload.compact)
38
42
  response = http.request(request)
39
43
 
@@ -42,7 +46,15 @@ module DeepL
42
46
  end
43
47
 
44
48
  def get
45
- request = Net::HTTP::Get.new(uri.request_uri)
49
+ request = Net::HTTP::Get.new(uri.request_uri, headers)
50
+ response = http.request(request)
51
+
52
+ validate_response!(request, response)
53
+ [request, response]
54
+ end
55
+
56
+ def delete
57
+ request = Net::HTTP::Delete.new(uri.request_uri, headers)
46
58
  response = http.request(request)
47
59
 
48
60
  validate_response!(request, response)
@@ -62,7 +74,8 @@ module DeepL
62
74
 
63
75
  case response.code
64
76
  when '400' then raise Exceptions::BadRequest.new(request, response)
65
- when '403' then raise Exceptions::AuthorizationFailed.new(request, response)
77
+ when '401', '403' then raise Exceptions::AuthorizationFailed.new(request, response)
78
+ when '404' then raise Exceptions::NotFound.new(request, response)
66
79
  when '429' then raise Exceptions::LimitExceeded.new(request, response)
67
80
  when '456' then raise Exceptions::QuotaExceeded.new(request, response)
68
81
  else raise Exceptions::RequestError.new(request, response)
@@ -91,7 +104,11 @@ module DeepL
91
104
  end
92
105
 
93
106
  def query_params
94
- { auth_key: api.configuration.auth_key }.merge(options)
107
+ options
108
+ end
109
+
110
+ def headers
111
+ { 'Authorization' => "DeepL-Auth-Key #{api.configuration.auth_key}" }
95
112
  end
96
113
  end
97
114
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeepL
4
+ module Requests
5
+ module Glossary
6
+ class Create < Base
7
+ attr_reader :name, :source_lang, :target_lang, :entries, :entries_format
8
+
9
+ def initialize(api, name, source_lang, target_lang, entries, options = {})
10
+ super(api, options)
11
+ @name = name
12
+ @source_lang = source_lang
13
+ @target_lang = target_lang
14
+ @entries = entries
15
+ @entries_format = delete_option(:entries_format) || 'tsv'
16
+ end
17
+
18
+ def request
19
+ payload = {
20
+ name: name, source_lang: source_lang, target_lang: target_lang, entries: entries_to_tsv,
21
+ entries_format: entries_format
22
+ }
23
+ build_glossary(*post(payload))
24
+ end
25
+
26
+ private
27
+
28
+ def entries_to_tsv
29
+ return entries if entries.is_a?(String)
30
+
31
+ entries.reduce('') { |tsv, entry| "#{tsv}#{entry.first}\t#{entry.last}\n" }
32
+ end
33
+
34
+ def build_glossary(request, response)
35
+ glossary = JSON.parse(response.body)
36
+ Resources::Glossary.new(glossary, request, response)
37
+ end
38
+
39
+ def path
40
+ 'glossaries'
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeepL
4
+ module Requests
5
+ module Glossary
6
+ class Destroy < Base
7
+ attr_reader :id
8
+
9
+ def initialize(api, id, options = {})
10
+ super(api, options)
11
+ @id = id
12
+ end
13
+
14
+ def request
15
+ build_response(*delete)
16
+ end
17
+
18
+ private
19
+
20
+ def build_response(_, _)
21
+ id
22
+ end
23
+
24
+ def path
25
+ "glossaries/#{id}"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeepL
4
+ module Requests
5
+ module Glossary
6
+ class Entries < Base
7
+ attr_reader :id
8
+
9
+ def initialize(api, id, options = {})
10
+ super(api, options)
11
+ @id = id
12
+ end
13
+
14
+ def request
15
+ build_entries(*get)
16
+ end
17
+
18
+ private
19
+
20
+ def build_entries(_, response)
21
+ response.body.split("\n").map { |entry| entry.split("\t") }
22
+ end
23
+
24
+ def path
25
+ "glossaries/#{id}/entries"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeepL
4
+ module Requests
5
+ module Glossary
6
+ class Find < Base
7
+ attr_reader :id
8
+
9
+ def initialize(api, id, options = {})
10
+ super(api, options)
11
+ @id = id
12
+ end
13
+
14
+ def request
15
+ build_glossary(*get)
16
+ end
17
+
18
+ private
19
+
20
+ def build_glossary(request, response)
21
+ glossary = JSON.parse(response.body)
22
+ Resources::Glossary.new(glossary, request, response)
23
+ end
24
+
25
+ def path
26
+ "glossaries/#{id}"
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeepL
4
+ module Requests
5
+ module Glossary
6
+ class LanguagePairs < Base
7
+ def initialize(api, options = {})
8
+ super(api, options)
9
+ end
10
+
11
+ def request
12
+ build_language_pair_list(*get)
13
+ end
14
+
15
+ private
16
+
17
+ def build_language_pair_list(request, response)
18
+ data = JSON.parse(response.body)
19
+ data['supported_languages'].map do |language_pair|
20
+ Resources::LanguagePair.new(language_pair['source_lang'], language_pair['target_lang'],
21
+ request, response)
22
+ end
23
+ end
24
+
25
+ def path
26
+ 'glossary-language-pairs'
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeepL
4
+ module Requests
5
+ module Glossary
6
+ class List < Base
7
+ def initialize(api, options = {})
8
+ super(api, options)
9
+ end
10
+
11
+ def request
12
+ build_glossary_list(*get)
13
+ end
14
+
15
+ private
16
+
17
+ def build_glossary_list(request, response)
18
+ data = JSON.parse(response.body)
19
+ data['glossaries'].map do |glossary|
20
+ Resources::Glossary.new(glossary, request, response)
21
+ end
22
+ end
23
+
24
+ def path
25
+ 'glossaries'
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -16,7 +16,9 @@ module DeepL
16
16
  def build_languages(request, response)
17
17
  data = JSON.parse(response.body)
18
18
  data.map do |language|
19
- Resources::Language.new(language['language'], language['name'], request, response)
19
+ Resources::Language.new(language['language'], language['name'],
20
+ language['supports_formality'],
21
+ request, response)
20
22
  end
21
23
  end
22
24
 
@@ -8,6 +8,7 @@ module DeepL
8
8
  OPTIONS_CONVERSIONS = {
9
9
  split_sentences: BOOLEAN_CONVERSION,
10
10
  preserve_formatting: BOOLEAN_CONVERSION,
11
+ outline_detection: BOOLEAN_CONVERSION,
11
12
  non_splitting_tags: ARRAY_CONVERSION,
12
13
  ignore_tags: ARRAY_CONVERSION
13
14
  }.freeze
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeepL
4
+ module Resources
5
+ class Glossary < Base
6
+ attr_reader :id, :name, :ready, :source_lang, :target_lang, :creation_time, :entry_count
7
+
8
+ def initialize(glossary, *args)
9
+ super(*args)
10
+
11
+ @id = glossary['glossary_id']
12
+ @name = glossary['name']
13
+ @ready = glossary['ready']
14
+ @source_lang = glossary['source_lang']
15
+ @target_lang = glossary['target_lang']
16
+ @creation_time = glossary['creation_time']
17
+ @entry_count = glossary['entry_count']
18
+ end
19
+
20
+ def to_s
21
+ "#{id} - #{name}"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -5,16 +5,23 @@ module DeepL
5
5
  class Language < Base
6
6
  attr_reader :code, :name
7
7
 
8
- def initialize(code, name, *args)
8
+ def initialize(code, name, supports_formality, *args)
9
9
  super(*args)
10
10
 
11
11
  @code = code
12
12
  @name = name
13
+ @supports_formality = supports_formality
13
14
  end
14
15
 
15
16
  def to_s
16
17
  "#{code} - #{name}"
17
18
  end
19
+
20
+ def supports_formality?
21
+ return @supports_formality unless @supports_formality.nil?
22
+
23
+ raise Exceptions::NotSupported, 'Support formality is only available on target languages'
24
+ end
18
25
  end
19
26
  end
20
27
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeepL
4
+ module Resources
5
+ class LanguagePair < Base
6
+ attr_reader :source_lang, :target_lang
7
+
8
+ def initialize(source_lang, target_lang, *args)
9
+ super(*args)
10
+
11
+ @source_lang = source_lang
12
+ @target_lang = target_lang
13
+ end
14
+
15
+ def to_s
16
+ "#{source_lang} - #{target_lang}"
17
+ end
18
+ end
19
+ end
20
+ end