deepl-rb 3.4.1 → 3.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 (103) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -4
  3. data/README.md +14 -0
  4. metadata +2 -101
  5. data/.circleci/config.yml +0 -27
  6. data/.github/workflows/add_issues_to_kanban.yml +0 -16
  7. data/.gitlab-ci.yml +0 -172
  8. data/.rubocop.yml +0 -51
  9. data/CODE_OF_CONDUCT.md +0 -132
  10. data/CONTRIBUTING.md +0 -37
  11. data/Gemfile +0 -24
  12. data/Rakefile +0 -56
  13. data/SECURITY.md +0 -58
  14. data/VERSION +0 -1
  15. data/deepl-rb.gemspec +0 -139
  16. data/lib/deepl/api.rb +0 -22
  17. data/lib/deepl/configuration.rb +0 -59
  18. data/lib/deepl/constants/base_constant.rb +0 -18
  19. data/lib/deepl/constants/formality.rb +0 -16
  20. data/lib/deepl/constants/model_type.rb +0 -14
  21. data/lib/deepl/constants/split_sentences.rb +0 -14
  22. data/lib/deepl/constants/tag_handling.rb +0 -13
  23. data/lib/deepl/constants/tone.rb +0 -20
  24. data/lib/deepl/constants/writing_style.rb +0 -20
  25. data/lib/deepl/document_api.rb +0 -121
  26. data/lib/deepl/exceptions/authorization_failed.rb +0 -14
  27. data/lib/deepl/exceptions/bad_request.rb +0 -16
  28. data/lib/deepl/exceptions/document_translation_error.rb +0 -15
  29. data/lib/deepl/exceptions/error.rb +0 -14
  30. data/lib/deepl/exceptions/limit_exceeded.rb +0 -18
  31. data/lib/deepl/exceptions/not_found.rb +0 -16
  32. data/lib/deepl/exceptions/not_supported.rb +0 -14
  33. data/lib/deepl/exceptions/quota_exceeded.rb +0 -14
  34. data/lib/deepl/exceptions/request_entity_too_large.rb +0 -15
  35. data/lib/deepl/exceptions/request_error.rb +0 -21
  36. data/lib/deepl/exceptions/server_error.rb +0 -18
  37. data/lib/deepl/glossary_api.rb +0 -38
  38. data/lib/deepl/requests/base.rb +0 -196
  39. data/lib/deepl/requests/document/download.rb +0 -44
  40. data/lib/deepl/requests/document/get_status.rb +0 -44
  41. data/lib/deepl/requests/document/upload.rb +0 -74
  42. data/lib/deepl/requests/glossary/create.rb +0 -59
  43. data/lib/deepl/requests/glossary/destroy.rb +0 -37
  44. data/lib/deepl/requests/glossary/entries.rb +0 -37
  45. data/lib/deepl/requests/glossary/find.rb +0 -38
  46. data/lib/deepl/requests/glossary/language_pairs.rb +0 -38
  47. data/lib/deepl/requests/glossary/list.rb +0 -37
  48. data/lib/deepl/requests/languages.rb +0 -37
  49. data/lib/deepl/requests/rephrase.rb +0 -55
  50. data/lib/deepl/requests/style_rule/list.rb +0 -59
  51. data/lib/deepl/requests/translate.rb +0 -92
  52. data/lib/deepl/requests/usage.rb +0 -33
  53. data/lib/deepl/resources/base.rb +0 -17
  54. data/lib/deepl/resources/document_handle.rb +0 -57
  55. data/lib/deepl/resources/document_translation_status.rb +0 -54
  56. data/lib/deepl/resources/glossary.rb +0 -28
  57. data/lib/deepl/resources/language.rb +0 -30
  58. data/lib/deepl/resources/language_pair.rb +0 -23
  59. data/lib/deepl/resources/style_rule.rb +0 -85
  60. data/lib/deepl/resources/text.rb +0 -24
  61. data/lib/deepl/resources/usage.rb +0 -27
  62. data/lib/deepl/style_rule_api.rb +0 -17
  63. data/lib/deepl/utils/backoff_timer.rb +0 -46
  64. data/lib/deepl/utils/exception_builder.rb +0 -34
  65. data/lib/deepl.rb +0 -158
  66. data/lib/http_client_options.rb +0 -22
  67. data/lib/version.rb +0 -8
  68. data/spec/api/api_spec.rb +0 -20
  69. data/spec/api/configuration_spec.rb +0 -122
  70. data/spec/api/deepl_spec.rb +0 -460
  71. data/spec/constants/constants_spec.rb +0 -158
  72. data/spec/fixtures/vcr_cassettes/deepl_document.yml +0 -95
  73. data/spec/fixtures/vcr_cassettes/deepl_document_download.yml +0 -1214
  74. data/spec/fixtures/vcr_cassettes/deepl_glossaries.yml +0 -1163
  75. data/spec/fixtures/vcr_cassettes/deepl_languages.yml +0 -54
  76. data/spec/fixtures/vcr_cassettes/deepl_rephrase.yml +0 -87
  77. data/spec/fixtures/vcr_cassettes/deepl_translate.yml +0 -358
  78. data/spec/fixtures/vcr_cassettes/deepl_usage.yml +0 -129
  79. data/spec/fixtures/vcr_cassettes/glossaries.yml +0 -1702
  80. data/spec/fixtures/vcr_cassettes/languages.yml +0 -229
  81. data/spec/fixtures/vcr_cassettes/rephrase_texts.yml +0 -401
  82. data/spec/fixtures/vcr_cassettes/style_rules.yml +0 -92
  83. data/spec/fixtures/vcr_cassettes/translate_texts.yml +0 -10415
  84. data/spec/fixtures/vcr_cassettes/usage.yml +0 -171
  85. data/spec/integration_tests/document_api_spec.rb +0 -178
  86. data/spec/integration_tests/integration_test_utils.rb +0 -170
  87. data/spec/integration_tests/style_rule_api_spec.rb +0 -79
  88. data/spec/requests/glossary/create_spec.rb +0 -65
  89. data/spec/requests/glossary/destroy_spec.rb +0 -66
  90. data/spec/requests/glossary/entries_spec.rb +0 -62
  91. data/spec/requests/glossary/find_spec.rb +0 -68
  92. data/spec/requests/glossary/language_pairs_spec.rb +0 -40
  93. data/spec/requests/glossary/list_spec.rb +0 -54
  94. data/spec/requests/languages_spec.rb +0 -68
  95. data/spec/requests/rephrase_spec.rb +0 -172
  96. data/spec/requests/translate_spec.rb +0 -422
  97. data/spec/requests/usage_spec.rb +0 -43
  98. data/spec/resources/glossary_spec.rb +0 -38
  99. data/spec/resources/language_pair_spec.rb +0 -23
  100. data/spec/resources/language_spec.rb +0 -45
  101. data/spec/resources/text_spec.rb +0 -23
  102. data/spec/resources/usage_spec.rb +0 -35
  103. data/spec/spec_helper.rb +0 -92
@@ -1,27 +0,0 @@
1
- # Copyright 2018 Daniel Herzog
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 Resources
8
- class Usage < Base
9
- attr_reader :character_count, :character_limit
10
-
11
- def initialize(character_count, character_limit, *args)
12
- super(*args)
13
-
14
- @character_count = character_count
15
- @character_limit = character_limit
16
- end
17
-
18
- def to_s
19
- "#{character_count} / #{character_limit}"
20
- end
21
-
22
- def quota_exceeded?
23
- character_count >= character_limit
24
- end
25
- end
26
- end
27
- end
@@ -1,17 +0,0 @@
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
@@ -1,46 +0,0 @@
1
- # Copyright 2024 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
- module DeepL
7
- module Utils
8
- class BackoffTimer
9
- # Implements exponential-backoff strategy.
10
- # This strategy is based on the GRPC Connection Backoff Protocol:
11
- # https://github.com/grpc/grpc/blob/master/doc/connection-backoff.md
12
-
13
- BACKOFF_INITIAL = 1.0
14
- BACKOFF_MAX = 120.0
15
- BACKOFF_JITTER = 0.23
16
- BACKOFF_MULTIPLIER = 1.6
17
-
18
- attr_reader :num_retries
19
-
20
- def initialize(min_connection_timeout = 10.0)
21
- @num_retries = 0
22
- @backoff = BACKOFF_INITIAL
23
- @deadline = Time.now.to_f + @backoff
24
- @min_connection_timeout = min_connection_timeout
25
- end
26
-
27
- def current_request_timeout
28
- [time_until_deadline, @min_connection_timeout].max
29
- end
30
-
31
- def time_until_deadline
32
- [@deadline - Time.now.to_f, 0.0].max
33
- end
34
-
35
- def sleep_until_deadline
36
- sleep(time_until_deadline)
37
- # Apply multiplier to current backoff time
38
- @backoff = [@backoff * BACKOFF_MULTIPLIER, BACKOFF_MAX].min
39
- # Get deadline by applying jitter as a proportion of backoff:
40
- # if jitter is 0.1, then multiply backoff by random value in [0.9, 1.1]
41
- @deadline = Time.now.to_f + (@backoff * (1 + (BACKOFF_JITTER * rand(-1.0..1.0))))
42
- @num_retries += 1
43
- end
44
- end
45
- end
46
- end
@@ -1,34 +0,0 @@
1
- # Copyright 2022 Daniel Herzog
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 Utils
8
- class ExceptionBuilder
9
- attr_reader :request, :response
10
-
11
- def self.error_class_from_response_code(code) # rubocop:disable Metrics/CyclomaticComplexity
12
- case code
13
- when 400 then Exceptions::BadRequest
14
- when 401, 403 then Exceptions::AuthorizationFailed
15
- when 404 then Exceptions::NotFound
16
- when 413 then Exceptions::RequestEntityTooLarge
17
- when 429 then Exceptions::LimitExceeded
18
- when 456 then Exceptions::QuotaExceeded
19
- when 500..599 then Exceptions::ServerError
20
- else Exceptions::RequestError
21
- end
22
- end
23
-
24
- def initialize(response)
25
- @response = response
26
- end
27
-
28
- def build
29
- error_class = self.class.error_class_from_response_code(response.code.to_i)
30
- error_class.new(response)
31
- end
32
- end
33
- end
34
- end
data/lib/deepl.rb DELETED
@@ -1,158 +0,0 @@
1
- # Copyright 2018 Daniel Herzog
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
- # -- Dependencies
7
- require 'json'
8
- require 'net/http'
9
-
10
- # -- Exceptions
11
- require 'deepl/exceptions/error'
12
- require 'deepl/exceptions/request_error'
13
- require 'deepl/exceptions/authorization_failed'
14
- require 'deepl/exceptions/bad_request'
15
- require 'deepl/exceptions/limit_exceeded'
16
- require 'deepl/exceptions/quota_exceeded'
17
- require 'deepl/exceptions/not_found'
18
- require 'deepl/exceptions/not_supported'
19
- require 'deepl/exceptions/request_entity_too_large'
20
- require 'deepl/exceptions/document_translation_error'
21
- require 'deepl/exceptions/server_error'
22
-
23
- # -- Requests
24
- require 'deepl/requests/base'
25
- require 'deepl/requests/document/download'
26
- require 'deepl/requests/document/get_status'
27
- require 'deepl/requests/document/upload'
28
- require 'deepl/requests/glossary/create'
29
- require 'deepl/requests/glossary/destroy'
30
- require 'deepl/requests/glossary/entries'
31
- require 'deepl/requests/glossary/find'
32
- require 'deepl/requests/glossary/language_pairs'
33
- require 'deepl/requests/glossary/list'
34
- require 'deepl/requests/style_rule/list'
35
- require 'deepl/requests/languages'
36
- require 'deepl/requests/translate'
37
- require 'deepl/requests/usage'
38
- require 'deepl/requests/rephrase'
39
-
40
- # -- Responses and resources
41
- require 'deepl/resources/base'
42
- require 'deepl/resources/document_handle'
43
- require 'deepl/resources/document_translation_status'
44
- require 'deepl/resources/glossary'
45
- require 'deepl/resources/style_rule'
46
- require 'deepl/resources/language'
47
- require 'deepl/resources/language_pair'
48
- require 'deepl/resources/text'
49
- require 'deepl/resources/usage'
50
-
51
- # -- Utils
52
- require 'deepl/utils/exception_builder'
53
- require 'deepl/utils/backoff_timer'
54
-
55
- # -- Constants
56
- require 'deepl/constants/base_constant'
57
- require 'deepl/constants/formality'
58
- require 'deepl/constants/model_type'
59
- require 'deepl/constants/split_sentences'
60
- require 'deepl/constants/tag_handling'
61
- require 'deepl/constants/tone'
62
- require 'deepl/constants/writing_style'
63
-
64
- # -- HTTP Utils
65
- require 'http_client_options'
66
-
67
- # -- Version
68
- require 'version'
69
-
70
- # -- Other wrappers
71
- require 'deepl/api'
72
- require 'deepl/configuration'
73
- require 'deepl/document_api'
74
- require 'deepl/glossary_api'
75
- require 'deepl/style_rule_api'
76
-
77
- # -- Gem interface
78
- module DeepL
79
- extend self
80
-
81
- ## -- API shortcuts
82
-
83
- def api
84
- @api ||= API.new(configuration)
85
- end
86
-
87
- def languages(options = {})
88
- Requests::Languages.new(api, options).request
89
- end
90
-
91
- def translate(text, source_lang, target_lang, options = {})
92
- configure if @configuration.nil?
93
- Requests::Translate.new(api, text, source_lang, target_lang, options).request
94
- end
95
-
96
- def document(options = {})
97
- configure if @configuration.nil?
98
- DocumentApi.new(api, options)
99
- end
100
-
101
- def glossaries(options = {})
102
- configure if @configuration.nil?
103
- GlossaryApi.new(api, options)
104
- end
105
-
106
- def style_rules(options = {})
107
- configure if @configuration.nil?
108
- StyleRuleApi.new(api, options)
109
- end
110
-
111
- def rephrase(text, target_lang = nil, writing_style = nil, tone = nil, options = {}) # rubocop:disable Metrics/ParameterLists
112
- configure if @configuration.nil?
113
- Requests::Rephrase.new(api, text, target_lang, writing_style, tone, options).request
114
- end
115
-
116
- def usage(options = {})
117
- configure if @configuration.nil?
118
- Requests::Usage.new(api, options).request
119
- end
120
-
121
- def http_client
122
- @http_client
123
- end
124
-
125
- def with_session(client_options = HTTPClientOptions.new()) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
126
- raise ArgumentError 'This method requires a block to be passed in which contains the actual API calls, see README for example usage.' unless block_given? # rubocop:disable Layout/LineLength
127
-
128
- has_proxy = client_options.proxy.key?('proxy_addr') and client_options.proxy.key?('proxy_port')
129
- begin
130
- uri = URI(configuration.host)
131
- http = Net::HTTP.new(uri.host, uri.port, has_proxy ? client_options.proxy['proxy_addr'] : nil,
132
- has_proxy ? client_options.proxy['proxy_port'] : nil)
133
- http.use_ssl = client_options.enable_ssl_verification
134
- http.ca_file = client_options.cert_path if client_options.cert_path
135
- http.open_timeout = client_options.open_timeout unless client_options.open_timeout.nil?
136
- http.read_timeout = client_options.read_timeout unless client_options.read_timeout.nil?
137
- http.write_timeout = client_options.write_timeout unless client_options.write_timeout.nil?
138
- http.ssl_timeout = client_options.ssl_timeout unless client_options.ssl_timeout.nil?
139
- http.start
140
- @http_client = http
141
- api.update_http_client(http)
142
- yield
143
- ensure
144
- http.finish
145
- end
146
- end
147
-
148
- # -- Configuration
149
-
150
- def configuration
151
- @configuration ||= Configuration.new
152
- end
153
-
154
- def configure
155
- yield configuration if block_given?
156
- configuration.validate!
157
- end
158
- end
@@ -1,22 +0,0 @@
1
- # Copyright 2024 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
- module DeepL
7
- class HTTPClientOptions
8
- attr_reader :proxy, :send_platform_info, :enable_ssl_verification, :cert_path, :open_timeout,
9
- :read_timeout, :write_timeout, :ssl_timeout
10
-
11
- def initialize(proxy, cert_path, enable_ssl_verification: true, open_timeout: nil, # rubocop:disable Metrics/ParameterLists
12
- read_timeout: nil, write_timeout: nil, ssl_timeout: nil)
13
- @proxy = proxy
14
- @enable_ssl_verification = enable_ssl_verification
15
- @cert_path = cert_path
16
- @open_timeout = open_timeout
17
- @read_timeout = read_timeout
18
- @write_timeout = write_timeout
19
- @ssl_timeout = ssl_timeout
20
- end
21
- end
22
- end
data/lib/version.rb DELETED
@@ -1,8 +0,0 @@
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
data/spec/api/api_spec.rb DELETED
@@ -1,20 +0,0 @@
1
- # Copyright 2018 Daniel Herzog
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 'spec_helper'
7
-
8
- describe DeepL::API do
9
- subject(:api) { described_class.new(configuration) }
10
-
11
- let(:configuration) { DeepL::Configuration.new }
12
-
13
- describe '#initialize' do
14
- context 'when building an API object' do
15
- it 'saves the configuration' do
16
- expect(api.configuration).to be(configuration)
17
- end
18
- end
19
- end
20
- end
@@ -1,122 +0,0 @@
1
- # Copyright 2018 Daniel Herzog
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 'logger'
7
- require 'spec_helper'
8
-
9
- describe DeepL::Configuration do
10
- subject(:config) { described_class.new(attributes) }
11
-
12
- let(:attributes) { {} }
13
-
14
- around do |tests|
15
- tmp_env = ENV.to_hash
16
- ENV.clear
17
- tests.call
18
- ENV.replace(tmp_env)
19
- end
20
-
21
- describe '#initialize' do
22
- context 'when using default configuration attributes' do
23
- it 'uses default attributes' do
24
- expect(config.auth_key).to eq(ENV.fetch('DEEPL_AUTH_KEY', nil))
25
- expect(config.host).to eq('https://api.deepl.com')
26
- expect(config.max_doc_status_queries).to be_nil
27
- expect(config.version).to eq('v2')
28
- end
29
-
30
- it 'sends platform information' do
31
- expect(config.user_agent).to include('deepl-ruby/')
32
- expect(config.user_agent).to include('(')
33
- expect(config.user_agent).to include(')')
34
- expect(config.user_agent).to include(' ruby/')
35
- end
36
- end
37
-
38
- context 'when using custom configuration attributes' do
39
- let(:logger) { Logger.new($stdout) }
40
- let(:attributes) { { auth_key: 'SAMPLE', host: 'https://api-free.deepl.com', logger: logger, max_doc_status_queries: 42, max_network_retries: 43, version: 'v1' } }
41
-
42
- it 'uses custom attributes' do
43
- expect(config.auth_key).to eq(attributes[:auth_key])
44
- expect(config.host).to eq(attributes[:host])
45
- expect(config.max_doc_status_queries).to eq(attributes[:max_doc_status_queries])
46
- expect(config.max_network_retries).to eq(attributes[:max_network_retries])
47
- expect(config.version).to eq(attributes[:version])
48
- end
49
- end
50
-
51
- context 'when using a free key' do
52
- let(:attributes) { { auth_key: '123e4567-e89b-12d3-a456-426614174000:fx' } }
53
-
54
- it 'uses the free API URL' do
55
- expect(config.host).to eq('https://api-free.deepl.com')
56
- end
57
- end
58
-
59
- context 'when using a pro key' do
60
- let(:attributes) { { auth_key: '123e4567-e89b-12d3-a456-426614174000' } }
61
-
62
- it 'uses the pro API URL' do
63
- expect(config.host).to eq('https://api.deepl.com')
64
- end
65
- end
66
-
67
- context 'when opting out of sending platform info' do
68
- subject(:config) { described_class.new(attributes, nil, nil, false) }
69
-
70
- it 'does not send platform information' do
71
- expect(config.user_agent).to include('deepl-ruby/')
72
- expect(config.user_agent).not_to include('(')
73
- expect(config.user_agent).not_to include(')')
74
- expect(config.user_agent).not_to include(' ruby/')
75
- end
76
- end
77
-
78
- context 'when registering an app and sending platform info' do
79
- subject(:config) { described_class.new(attributes, 'MyTestApp', '0.1.3', true) }
80
-
81
- it 'sends platform and app info' do
82
- expect(config.user_agent).to include('deepl-ruby/')
83
- expect(config.user_agent).to include('(')
84
- expect(config.user_agent).to include(')')
85
- expect(config.user_agent).to include(' ruby/')
86
- expect(config.user_agent).to include('MyTestApp/0.1.3')
87
- end
88
- end
89
-
90
- context 'when registering an app and not sending platform info' do
91
- subject(:config) { described_class.new(attributes, 'MyTestApp', '0.1.3', false) }
92
-
93
- it 'sends app, but not platform info' do
94
- expect(config.user_agent).to include('deepl-ruby/')
95
- expect(config.user_agent).not_to include('(')
96
- expect(config.user_agent).not_to include(')')
97
- expect(config.user_agent).not_to include(' ruby/')
98
- expect(config.user_agent).to include('MyTestApp/0.1.3')
99
- end
100
- end
101
- end
102
-
103
- describe '#validate!' do
104
- let(:auth_message) { 'auth_key not provided' }
105
-
106
- context 'when providing a valid auth key' do
107
- let(:attributes) { { auth_key: '' } }
108
-
109
- it 'raises an error' do
110
- expect { config.validate! }.to raise_error(DeepL::Exceptions::Error, auth_message)
111
- end
112
- end
113
-
114
- context 'when providing an invalid auth key' do
115
- let(:attributes) { { auth_key: 'not-empty' } }
116
-
117
- it 'does not raise an error' do
118
- expect { config.validate! }.not_to raise_error
119
- end
120
- end
121
- end
122
- end