deepl-rb 3.3.0 → 3.4.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce04c17b4585b9813713f61db8fe35e3a61b777c48ec22011f81b7febe106527
4
- data.tar.gz: 3c4432516a14b2fb0e8886f2ff3e6d31c5ba5c88590d4e28a9631fc0a233f724
3
+ metadata.gz: 4c41f4e48cdf057f165925df1ba47e6fa2748d49816a16e137e4ed8acaed7000
4
+ data.tar.gz: b169350c8f173e15bc502d7eaa26c6b9b4b255961224a6508ac41eaa0d7466c3
5
5
  SHA512:
6
- metadata.gz: 8a736f2b2cc257c26cd47e67bdbdcbc89afbb6de444176f0dab5b0a470fe2c713e3c32396391a05c007ddfbfbbc80953b0f6c6afb1fdf9b138c0eca97ae02a52
7
- data.tar.gz: 1828bdede7c38bec246302645e39ec7f01950096f3c52fb1b119766bbdf11b6c2b6d3ab881ebdf2875f736ab8f47778e87abcb5f107ca2ef6f4848c66d11d680
6
+ metadata.gz: 0d260ad680a40b28865127fd0eaccd469c7dc5fed1203424c3737077b6d5b6a7dc6116b3d458633f8c3d4835159b5deb1e49bafa43409a1255abd3f11ccbbba6
7
+ data.tar.gz: 1d684b486e4286f02d6bbc194bcf983ee7e5555d263d52cc5b41d68abba2fbafe79bae96f014b1db841b9fb893b173dc66f12365b7734bbd3bfb9a891ff97b41
data/CHANGELOG.md CHANGED
@@ -4,7 +4,20 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [Unreleased]
7
+ ## [3.4.1] - 2025-12-19
8
+ ### Fixed
9
+ - Fixed broken 3.4.0 release
10
+
11
+ ## [3.4.0] - 2025-11-17
12
+ ### Added
13
+ - Added support for the `GET /v3/style_rules` endpoint in the client library, the
14
+ implementation can be found in the `StyleRuleApi` class. Please refer to the
15
+ README for usage instructions
16
+ - Added `style_id` option to `translate()` which allows text translation with
17
+ style rules.
18
+
19
+ ### Fixed
20
+ - Send correct library version in user-agent. Expose library version in the module as a variable.
8
21
 
9
22
  ## [3.3.0] - 2025-11-04
10
23
  ### Added
@@ -62,7 +75,8 @@ The change in major version is only due to the change in maintainership, there i
62
75
  ### Fixed
63
76
  - Make RequestEntityTooLarge error message more clear
64
77
 
65
- [Unreleased]: https://github.com/DeepLcom/deepl-rb/compare/v3.3.0...HEAD
78
+ [3.4.1]: https://github.com/DeepLcom/deepl-rb/compare/v3.4.0...v3.4.1
79
+ [3.4.0]: https://github.com/DeepLcom/deepl-rb/compare/v3.3.0...v3.4.0
66
80
  [3.3.0]: https://github.com/DeepLcom/deepl-rb/compare/v3.2.0...v3.3.0
67
81
  [3.2.0]: https://github.com/DeepLcom/deepl-rb/compare/v3.1.0...v3.2.0
68
82
  [3.1.0]: https://github.com/DeepLcom/deepl-rb/compare/v3.0.2...v3.1.0
data/README.md CHANGED
@@ -166,6 +166,8 @@ The following parameters will be automatically converted:
166
166
  | `ignore_tags` | Converts arrays to strings joining by commas
167
167
  | `formality` | No conversion applied
168
168
  | `glossary_id` | No conversion applied
169
+ | `style_id` | No conversion applied
170
+ | `style_rule` | No conversion applied (can be a string ID or a StyleRule object)
169
171
  | `context` | No conversion applied
170
172
  | `extra_body_parameters` | Hash of extra parameters to pass in the body of the HTTP request. Can be used to access beta features, or to override built-in parameters for testing purposes. Extra parameters can override keys explicitly set by the client.
171
173
 
@@ -294,6 +296,62 @@ puts language_pairs.first.target_lang
294
296
  # => de
295
297
  ```
296
298
 
299
+ ### Style Rules
300
+
301
+ Style rules allow you to customize your translations using a managed, shared list
302
+ of rules for style, formatting, and more. Multiple style rules can be stored with
303
+ your account, each with a user-specified name and a uniquely-assigned ID.
304
+
305
+ #### Creating and managing style rules
306
+
307
+ Currently style rules must be created and managed in the DeepL UI via
308
+ https://www.deepl.com/en/custom-rules. Full CRUD functionality via the APIs will
309
+ come shortly.
310
+
311
+ #### Listing all style rules
312
+
313
+ `style_rules.list` returns a list of `StyleRule` objects
314
+ corresponding to all of your stored style rules. The method accepts optional
315
+ parameters: `page` (page number for pagination, 0-indexed), `page_size` (number
316
+ of items per page), and `detailed` (whether to include detailed configuration
317
+ rules in the `configured_rules` property).
318
+
319
+ ```rb
320
+ # Get all style rules
321
+ style_rules = DeepL.style_rules.list
322
+ style_rules.each do |rule|
323
+ puts "#{rule.name} (#{rule.style_id})"
324
+ end
325
+
326
+ # Get style rules with detailed configuration
327
+ style_rules = DeepL.style_rules.list(detailed: true)
328
+ style_rules.each do |rule|
329
+ if rule.configured_rules
330
+ puts " Number formatting: #{rule.configured_rules.numbers.keys.join(', ')}"
331
+ end
332
+ end
333
+ ```
334
+
335
+ Created style rules can be used in the `translate` method by specifying the `style_id` option:
336
+
337
+ ```rb
338
+ translation = DeepL.translate 'Hello World', 'EN', 'ES', style_id: 'dca2e053-8ae5-45e6-a0d2-881156e7f4e4'
339
+
340
+ puts translation.class
341
+ # => DeepL::Resources::Text
342
+ puts translation.text
343
+ # => 'Hola Mundo'
344
+ ```
345
+
346
+ You can also pass a `StyleRule` object directly:
347
+
348
+ ```rb
349
+ style_rules = DeepL.style_rules.list
350
+ style_rule = style_rules.first
351
+
352
+ translation = DeepL.translate 'Hello World', 'EN', 'ES', style_rule: style_rule
353
+ ```
354
+
297
355
  ### Monitor usage
298
356
 
299
357
  To check current API usage, use:
data/Rakefile CHANGED
@@ -13,6 +13,7 @@ end
13
13
 
14
14
  require 'rake'
15
15
  require 'juwelier'
16
+ require_relative 'lib/version'
16
17
 
17
18
  Juwelier::Tasks.new do |gem|
18
19
  gem.name = 'deepl-rb'
@@ -22,6 +23,7 @@ Juwelier::Tasks.new do |gem|
22
23
  gem.description =
23
24
  'Official Ruby library for the DeepL language translation API (v2). ' \
24
25
  'For more information, check this: https://www.deepl.com/docs/api-reference.html'
26
+ gem.version = DeepL::VERSION
25
27
 
26
28
  gem.email = 'open-source@deepl.com'
27
29
  gem.authors = ['DeepL SE']
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.3.0
1
+ 3.4.1
data/deepl-rb.gemspec CHANGED
@@ -2,17 +2,17 @@
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 3.3.0 ruby lib
5
+ # stub: deepl-rb 3.4.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "deepl-rb".freeze
9
- s.version = "3.3.0"
9
+ s.version = "3.4.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.metadata = { "bug_tracker_uri" => "https://github.com/DeepLcom/deepl-rb/issues", "changelog_uri" => "https://github.com/DeepLcom/deepl-rb/blob/main/CHANGELOG.md", "documentation_uri" => "https://github.com/DeepLcom/deepl-rb/blob/main/README.md", "homepage_uri" => "https://github.com/DeepLcom/deepl-rb" } if s.respond_to? :metadata=
13
13
  s.require_paths = ["lib".freeze]
14
14
  s.authors = ["DeepL SE".freeze]
15
- s.date = "2025-11-04"
15
+ s.date = "2025-12-19"
16
16
  s.description = "Official Ruby library for the DeepL language translation API (v2). For more information, check this: https://www.deepl.com/docs/api-reference.html".freeze
17
17
  s.email = "open-source@deepl.com".freeze
18
18
  s.extra_rdoc_files = [
@@ -71,6 +71,7 @@ Gem::Specification.new do |s|
71
71
  "lib/deepl/requests/glossary/list.rb",
72
72
  "lib/deepl/requests/languages.rb",
73
73
  "lib/deepl/requests/rephrase.rb",
74
+ "lib/deepl/requests/style_rule/list.rb",
74
75
  "lib/deepl/requests/translate.rb",
75
76
  "lib/deepl/requests/usage.rb",
76
77
  "lib/deepl/resources/base.rb",
@@ -79,11 +80,14 @@ Gem::Specification.new do |s|
79
80
  "lib/deepl/resources/glossary.rb",
80
81
  "lib/deepl/resources/language.rb",
81
82
  "lib/deepl/resources/language_pair.rb",
83
+ "lib/deepl/resources/style_rule.rb",
82
84
  "lib/deepl/resources/text.rb",
83
85
  "lib/deepl/resources/usage.rb",
86
+ "lib/deepl/style_rule_api.rb",
84
87
  "lib/deepl/utils/backoff_timer.rb",
85
88
  "lib/deepl/utils/exception_builder.rb",
86
89
  "lib/http_client_options.rb",
90
+ "lib/version.rb",
87
91
  "license_checker.sh",
88
92
  "spec/api/api_spec.rb",
89
93
  "spec/api/configuration_spec.rb",
@@ -99,10 +103,12 @@ Gem::Specification.new do |s|
99
103
  "spec/fixtures/vcr_cassettes/glossaries.yml",
100
104
  "spec/fixtures/vcr_cassettes/languages.yml",
101
105
  "spec/fixtures/vcr_cassettes/rephrase_texts.yml",
106
+ "spec/fixtures/vcr_cassettes/style_rules.yml",
102
107
  "spec/fixtures/vcr_cassettes/translate_texts.yml",
103
108
  "spec/fixtures/vcr_cassettes/usage.yml",
104
109
  "spec/integration_tests/document_api_spec.rb",
105
110
  "spec/integration_tests/integration_test_utils.rb",
111
+ "spec/integration_tests/style_rule_api_spec.rb",
106
112
  "spec/requests/glossary/create_spec.rb",
107
113
  "spec/requests/glossary/destroy_spec.rb",
108
114
  "spec/requests/glossary/entries_spec.rb",
@@ -46,7 +46,7 @@ module DeepL
46
46
  end
47
47
 
48
48
  def construct_user_agent(send_platform_info, app_info_name, app_info_version)
49
- library_info_str = 'deepl-ruby/3.0.2'
49
+ library_info_str = "deepl-ruby/#{DeepL::VERSION}"
50
50
  if send_platform_info
51
51
  library_info_str += " (#{RbConfig::CONFIG['host_os']}) ruby/#{RUBY_VERSION}"
52
52
  end
@@ -0,0 +1,59 @@
1
+ # Copyright 2025 DeepL SE (https://www.deepl.com)
2
+ # Use of this source code is governed by an MIT
3
+ # license that can be found in the LICENSE.md file.
4
+ # frozen_string_literal: true
5
+
6
+ module DeepL
7
+ module Requests
8
+ module StyleRule
9
+ class List < Base
10
+ def initialize(api, options = {})
11
+ super
12
+ end
13
+
14
+ def request
15
+ build_style_rule_list(*execute_request_with_retries(get_request))
16
+ end
17
+
18
+ def to_s
19
+ "GET #{uri.request_uri}"
20
+ end
21
+
22
+ private
23
+
24
+ def get_request # rubocop:disable Naming/AccessorMethodName
25
+ http_headers = add_json_content_type(headers)
26
+ Net::HTTP::Get.new(uri.request_uri, http_headers)
27
+ end
28
+
29
+ def build_style_rule_list(request, response)
30
+ data = JSON.parse(response.body)
31
+ data['style_rules'].map do |style_rule|
32
+ Resources::StyleRule.new(style_rule, request, response)
33
+ end
34
+ end
35
+
36
+ def uri
37
+ @uri ||= begin
38
+ base_uri = URI("#{host}/v3/#{path}")
39
+ query_string = build_query_string
40
+ base_uri.query = query_string unless query_string.empty?
41
+ base_uri
42
+ end
43
+ end
44
+
45
+ def build_query_string
46
+ params = {}
47
+ params['page'] = option(:page).to_s if option?(:page)
48
+ params['page_size'] = option(:page_size).to_s if option?(:page_size)
49
+ params['detailed'] = option(:detailed).to_s.downcase if option?(:detailed)
50
+ URI.encode_www_form(params)
51
+ end
52
+
53
+ def path
54
+ 'style_rules'
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -38,9 +38,19 @@ module DeepL
38
38
  tweak_parameters!
39
39
  end
40
40
 
41
- def request
41
+ def request # rubocop:disable Metrics/MethodLength
42
42
  text_arrayified = text.is_a?(Array) ? text : [text]
43
43
  payload = { text: text_arrayified, source_lang: source_lang, target_lang: target_lang }
44
+
45
+ if option?(:style_rule)
46
+ style_rule = option(:style_rule)
47
+ payload[:style_id] = if style_rule.is_a?(DeepL::Resources::StyleRule)
48
+ style_rule.style_id
49
+ else
50
+ style_rule.to_s
51
+ end
52
+ end
53
+
44
54
  build_texts(*execute_request_with_retries(post_request(payload)))
45
55
  end
46
56
 
@@ -0,0 +1,85 @@
1
+ # Copyright 2025 DeepL SE (https://www.deepl.com)
2
+ # Use of this source code is governed by an MIT
3
+ # license that can be found in the LICENSE.md file.
4
+ # frozen_string_literal: true
5
+
6
+ require 'time'
7
+
8
+ module DeepL
9
+ module Resources
10
+ class ConfiguredRules
11
+ attr_reader :dates_and_times, :formatting, :numbers, :punctuation,
12
+ :spelling_and_grammar, :style_and_tone, :vocabulary
13
+
14
+ def initialize(configured_rules_data)
15
+ @dates_and_times = extract_rule(configured_rules_data, 'dates_and_times')
16
+ @formatting = extract_rule(configured_rules_data, 'formatting')
17
+ @numbers = extract_rule(configured_rules_data, 'numbers')
18
+ @punctuation = extract_rule(configured_rules_data, 'punctuation')
19
+ @spelling_and_grammar = extract_rule(configured_rules_data, 'spelling_and_grammar')
20
+ @style_and_tone = extract_rule(configured_rules_data, 'style_and_tone')
21
+ @vocabulary = extract_rule(configured_rules_data, 'vocabulary')
22
+ end
23
+
24
+ private
25
+
26
+ def extract_rule(data, key)
27
+ data[key] || {}
28
+ end
29
+ end
30
+
31
+ class CustomInstruction
32
+ attr_reader :label, :prompt, :source_language
33
+
34
+ def initialize(custom_instruction_data)
35
+ @label = custom_instruction_data['label']
36
+ @prompt = custom_instruction_data['prompt']
37
+ @source_language = custom_instruction_data['source_language']
38
+ end
39
+ end
40
+
41
+ class StyleRule < Base
42
+ attr_reader :style_id, :name, :creation_time, :updated_time, :language, :version,
43
+ :configured_rules, :custom_instructions
44
+
45
+ def initialize(style_rule, *args)
46
+ super(*args)
47
+ extract_basic_fields(style_rule)
48
+ extract_configured_rules(style_rule)
49
+ extract_custom_instructions(style_rule)
50
+ end
51
+
52
+ private
53
+
54
+ def extract_basic_fields(style_rule)
55
+ @style_id = style_rule['style_id']
56
+ @name = style_rule['name']
57
+ @creation_time = parse_time(style_rule['creation_time'])
58
+ @updated_time = parse_time(style_rule['updated_time'])
59
+ @language = style_rule['language']
60
+ @version = style_rule['version']
61
+ end
62
+
63
+ def extract_configured_rules(style_rule)
64
+ configured_rules_data = style_rule['configured_rules']
65
+ @configured_rules = configured_rules_data ? ConfiguredRules.new(configured_rules_data) : nil
66
+ end
67
+
68
+ def extract_custom_instructions(style_rule)
69
+ @custom_instructions = style_rule['custom_instructions']&.map do |ci|
70
+ CustomInstruction.new(ci)
71
+ end
72
+ end
73
+
74
+ def to_s
75
+ "#{style_id} - #{name}"
76
+ end
77
+
78
+ def parse_time(time_string)
79
+ return nil unless time_string
80
+
81
+ Time.parse(time_string)
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,17 @@
1
+ # Copyright 2025 DeepL SE (https://www.deepl.com)
2
+ # Use of this source code is governed by an MIT
3
+ # license that can be found in the LICENSE.md file.
4
+ # frozen_string_literal: true
5
+
6
+ module DeepL
7
+ class StyleRuleApi
8
+ def initialize(api, options = {})
9
+ @api = api
10
+ @options = options
11
+ end
12
+
13
+ def list(options = {})
14
+ DeepL::Requests::StyleRule::List.new(@api, options).request
15
+ end
16
+ end
17
+ end
data/lib/deepl.rb CHANGED
@@ -31,6 +31,7 @@ require 'deepl/requests/glossary/entries'
31
31
  require 'deepl/requests/glossary/find'
32
32
  require 'deepl/requests/glossary/language_pairs'
33
33
  require 'deepl/requests/glossary/list'
34
+ require 'deepl/requests/style_rule/list'
34
35
  require 'deepl/requests/languages'
35
36
  require 'deepl/requests/translate'
36
37
  require 'deepl/requests/usage'
@@ -41,6 +42,7 @@ require 'deepl/resources/base'
41
42
  require 'deepl/resources/document_handle'
42
43
  require 'deepl/resources/document_translation_status'
43
44
  require 'deepl/resources/glossary'
45
+ require 'deepl/resources/style_rule'
44
46
  require 'deepl/resources/language'
45
47
  require 'deepl/resources/language_pair'
46
48
  require 'deepl/resources/text'
@@ -62,11 +64,15 @@ require 'deepl/constants/writing_style'
62
64
  # -- HTTP Utils
63
65
  require 'http_client_options'
64
66
 
67
+ # -- Version
68
+ require 'version'
69
+
65
70
  # -- Other wrappers
66
71
  require 'deepl/api'
67
72
  require 'deepl/configuration'
68
73
  require 'deepl/document_api'
69
74
  require 'deepl/glossary_api'
75
+ require 'deepl/style_rule_api'
70
76
 
71
77
  # -- Gem interface
72
78
  module DeepL
@@ -97,6 +103,11 @@ module DeepL
97
103
  GlossaryApi.new(api, options)
98
104
  end
99
105
 
106
+ def style_rules(options = {})
107
+ configure if @configuration.nil?
108
+ StyleRuleApi.new(api, options)
109
+ end
110
+
100
111
  def rephrase(text, target_lang = nil, writing_style = nil, tone = nil, options = {}) # rubocop:disable Metrics/ParameterLists
101
112
  configure if @configuration.nil?
102
113
  Requests::Rephrase.new(api, text, target_lang, writing_style, tone, options).request
data/lib/version.rb ADDED
@@ -0,0 +1,8 @@
1
+ # Copyright 2025 DeepL SE (https://www.deepl.com)
2
+ # Use of this source code is governed by an MIT
3
+ # license that can be found in the LICENSE.md file.
4
+ # frozen_string_literal: true
5
+
6
+ module DeepL
7
+ VERSION = '3.4.1'
8
+ end
@@ -0,0 +1,92 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.deepl.com/v3/style_rules
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Authorization:
11
+ - DeepL-Auth-Key VALID_TOKEN
12
+ User-Agent:
13
+ - deepl-ruby/3.0.2 (darwin24) ruby/3.2.2
14
+ Content-Type:
15
+ - application/json
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Accept:
19
+ - "*/*"
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Date:
28
+ - Tue, 11 Nov 2025 21:41:34 GMT
29
+ X-Trace-Id:
30
+ - 91581bb49e774db3a0521e222a037333
31
+ Access-Control-Expose-Headers:
32
+ - Server-Timing, X-Trace-ID
33
+ Server-Timing:
34
+ - l7_lb_tls;dur=135, l7_lb_idle;dur=0, l7_lb_receive;dur=0, l7_lb_total;dur=880
35
+ Strict-Transport-Security:
36
+ - max-age=63072000; includeSubDomains; preload
37
+ Transfer-Encoding:
38
+ - chunked
39
+ Vary:
40
+ - Accept-Encoding
41
+ body:
42
+ encoding: ASCII-8BIT
43
+ string: '{"style_rules":[{"style_id":"a4dfe768-8f34-41e3-8b22-9b832d39294c","name":"Korean
44
+ style rule","creation_time":"2025-11-04T16:59:14.940077Z","updated_time":"2025-11-04T16:59:14.940077Z","language":"ko","version":1},{"style_id":"d9c60f20-3e6a-4d62-bc44-3ce89b981ebe","name":"ZH
45
+ Style rule","creation_time":"2025-11-04T03:47:14.03409Z","updated_time":"2025-11-04T03:47:28.75149Z","language":"zh","version":3},{"style_id":"8e694a65-da89-4d30-911d-dcacbe7c962b","name":"Japanese
46
+ style rule","creation_time":"2025-11-04T03:46:45.90662Z","updated_time":"2025-11-04T03:46:49.288723Z","language":"ja","version":2},{"style_id":"5874b9c5-e353-4576-886d-0f6af62c9f02","name":"Talk
47
+ like a pirate","creation_time":"2025-10-31T12:44:26.679757Z","updated_time":"2025-10-31T12:46:20.102929Z","language":"en","version":3},{"style_id":"4f987ba6-80d1-41a3-a4aa-037c4f2a6fce","name":"My
48
+ style rule","creation_time":"2025-08-28T19:42:37.841254Z","updated_time":"2025-10-31T12:39:07.919025Z","language":"en","version":8},{"style_id":"1df39d69-d278-4353-b206-9f0d347146d0","name":"Style
49
+ Rule with Custom Instruction","creation_time":"2025-08-20T17:46:58.90728Z","updated_time":"2025-10-22T20:44:46.532386Z","language":"en","version":8}]}'
50
+ recorded_at: Tue, 11 Nov 2025 21:41:35 GMT
51
+ - request:
52
+ method: get
53
+ uri: https://api.deepl.com/v3/style_rules
54
+ body:
55
+ encoding: US-ASCII
56
+ string: ''
57
+ headers:
58
+ Authorization:
59
+ - DeepL-Auth-Key invalid
60
+ User-Agent:
61
+ - deepl-ruby/3.0.2 (darwin24) ruby/3.2.2
62
+ Content-Type:
63
+ - application/json
64
+ Accept-Encoding:
65
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
66
+ Accept:
67
+ - "*/*"
68
+ response:
69
+ status:
70
+ code: 403
71
+ message: Forbidden
72
+ headers:
73
+ Content-Type:
74
+ - application/json; charset=utf-8
75
+ Date:
76
+ - Tue, 11 Nov 2025 21:41:35 GMT
77
+ X-Trace-Id:
78
+ - e170bd92638c4c6db4e8c4d89fd4316d
79
+ Access-Control-Expose-Headers:
80
+ - Server-Timing, X-Trace-ID
81
+ Server-Timing:
82
+ - l7_lb_tls;dur=135, l7_lb_idle;dur=0, l7_lb_receive;dur=0, l7_lb_total;dur=136
83
+ Strict-Transport-Security:
84
+ - max-age=63072000; includeSubDomains; preload
85
+ Transfer-Encoding:
86
+ - chunked
87
+ body:
88
+ encoding: UTF-8
89
+ string: '{"message":"Authentication failed, provided API key is invalid. You
90
+ can find more info in our docs: https://developers.deepl.com/docs/getting-started/auth"}'
91
+ recorded_at: Tue, 11 Nov 2025 21:41:35 GMT
92
+ recorded_with: VCR 6.3.1
@@ -16,9 +16,10 @@ describe DeepL::DocumentApi do
16
16
  WebMock.disable_net_connect!
17
17
  end
18
18
 
19
- default_lang_args = { source_lang: 'EN', target_lang: 'DE' }
20
19
  include_context 'with temp dir'
21
20
 
21
+ let(:default_lang_args) { { source_lang: 'EN', target_lang: 'DE' } }
22
+
22
23
  describe '#translate_document' do
23
24
  it 'Translates a document from a filepath' do
24
25
  File.unlink(output_document_path)
@@ -0,0 +1,79 @@
1
+ # Copyright 2025 DeepL SE (https://www.deepl.com)
2
+ # Use of this source code is governed by an MIT
3
+ # license that can be found in the LICENSE file.
4
+ # frozen_string_literal: true
5
+
6
+ require 'spec_helper'
7
+
8
+ describe DeepL::StyleRuleApi do
9
+ before do
10
+ VCR.turn_off!
11
+ WebMock.allow_net_connect!
12
+ end
13
+
14
+ after do
15
+ VCR.turn_on!
16
+ WebMock.disable_net_connect!
17
+ end
18
+
19
+ describe '#translate_with_style_rules' do
20
+ it 'when performing a request with style_id' do
21
+ skip 'Only runs on mock server' if real_server?
22
+
23
+ source_lang = 'DE'
24
+ target_lang = 'EN-US'
25
+ text = 'Hallo, Welt!'
26
+ style_id = 'dca2e053-8ae5-45e6-a0d2-881156e7f4e4'
27
+
28
+ result = DeepL.translate(text, source_lang, target_lang, { style_rule: style_id })
29
+ expect(result).to be_a(DeepL::Resources::Text)
30
+ end
31
+
32
+ it 'when performing a request with style_rule object' do
33
+ skip 'Only runs on mock server' if real_server?
34
+
35
+ source_lang = 'DE'
36
+ target_lang = 'EN-US'
37
+ text = 'Hallo, Welt!'
38
+ style_rule = build_test_style_rule
39
+
40
+ result = DeepL.translate(text, source_lang, target_lang, { style_rule: style_rule })
41
+ expect(result).to be_a(DeepL::Resources::Text)
42
+ end
43
+ end
44
+
45
+ describe '#list_style_rules' do
46
+ it 'when requesting a list of all style rules' do
47
+ skip 'Only runs on mock server' if real_server?
48
+ style_rules = DeepL.style_rules.list(page: 0, page_size: 10, detailed: true)
49
+ expect(style_rules).to be_an(Array)
50
+ expect(style_rules.length).to eq(1)
51
+ expect(style_rules[0].style_id).to eq('dca2e053-8ae5-45e6-a0d2-881156e7f4e4')
52
+ expect(style_rules[0].name).to eq('Default Style Rule')
53
+ expect(style_rules[0].configured_rules).to be_a(DeepL::Resources::ConfiguredRules)
54
+ expect(style_rules[0].custom_instructions).to be_an(Array)
55
+ end
56
+
57
+ it 'when requesting a list of all style rules without detailed' do
58
+ skip 'Only runs on mock server' if real_server?
59
+ style_rules = DeepL.style_rules.list
60
+ expect(style_rules).to be_an(Array)
61
+ expect(style_rules.length).to eq(1)
62
+ expect(style_rules[0].style_id).to eq('dca2e053-8ae5-45e6-a0d2-881156e7f4e4')
63
+ expect(style_rules[0].configured_rules).to be_nil
64
+ expect(style_rules[0].custom_instructions).to be_nil
65
+ end
66
+ end
67
+
68
+ def build_test_style_rule
69
+ style_rule_data = {
70
+ 'style_id' => 'dca2e053-8ae5-45e6-a0d2-881156e7f4e4',
71
+ 'name' => 'Default Style Rule',
72
+ 'creation_time' => '2025-01-01T00:00:00Z',
73
+ 'updated_time' => '2025-01-01T00:00:00Z',
74
+ 'language' => 'en',
75
+ 'version' => 1
76
+ }
77
+ DeepL::Resources::StyleRule.new(style_rule_data, nil, nil)
78
+ end
79
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deepl-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - DeepL SE
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-11-04 00:00:00.000000000 Z
11
+ date: 2025-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: juwelier
@@ -98,6 +98,7 @@ files:
98
98
  - lib/deepl/requests/glossary/list.rb
99
99
  - lib/deepl/requests/languages.rb
100
100
  - lib/deepl/requests/rephrase.rb
101
+ - lib/deepl/requests/style_rule/list.rb
101
102
  - lib/deepl/requests/translate.rb
102
103
  - lib/deepl/requests/usage.rb
103
104
  - lib/deepl/resources/base.rb
@@ -106,11 +107,14 @@ files:
106
107
  - lib/deepl/resources/glossary.rb
107
108
  - lib/deepl/resources/language.rb
108
109
  - lib/deepl/resources/language_pair.rb
110
+ - lib/deepl/resources/style_rule.rb
109
111
  - lib/deepl/resources/text.rb
110
112
  - lib/deepl/resources/usage.rb
113
+ - lib/deepl/style_rule_api.rb
111
114
  - lib/deepl/utils/backoff_timer.rb
112
115
  - lib/deepl/utils/exception_builder.rb
113
116
  - lib/http_client_options.rb
117
+ - lib/version.rb
114
118
  - license_checker.sh
115
119
  - spec/api/api_spec.rb
116
120
  - spec/api/configuration_spec.rb
@@ -126,10 +130,12 @@ files:
126
130
  - spec/fixtures/vcr_cassettes/glossaries.yml
127
131
  - spec/fixtures/vcr_cassettes/languages.yml
128
132
  - spec/fixtures/vcr_cassettes/rephrase_texts.yml
133
+ - spec/fixtures/vcr_cassettes/style_rules.yml
129
134
  - spec/fixtures/vcr_cassettes/translate_texts.yml
130
135
  - spec/fixtures/vcr_cassettes/usage.yml
131
136
  - spec/integration_tests/document_api_spec.rb
132
137
  - spec/integration_tests/integration_test_utils.rb
138
+ - spec/integration_tests/style_rule_api_spec.rb
133
139
  - spec/requests/glossary/create_spec.rb
134
140
  - spec/requests/glossary/destroy_spec.rb
135
141
  - spec/requests/glossary/entries_spec.rb