deepl-rb 3.3.0 → 3.4.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 (97) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -2
  3. data/README.md +58 -0
  4. metadata +2 -95
  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 -54
  13. data/SECURITY.md +0 -58
  14. data/VERSION +0 -1
  15. data/deepl-rb.gemspec +0 -133
  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/translate.rb +0 -82
  51. data/lib/deepl/requests/usage.rb +0 -33
  52. data/lib/deepl/resources/base.rb +0 -17
  53. data/lib/deepl/resources/document_handle.rb +0 -57
  54. data/lib/deepl/resources/document_translation_status.rb +0 -54
  55. data/lib/deepl/resources/glossary.rb +0 -28
  56. data/lib/deepl/resources/language.rb +0 -30
  57. data/lib/deepl/resources/language_pair.rb +0 -23
  58. data/lib/deepl/resources/text.rb +0 -24
  59. data/lib/deepl/resources/usage.rb +0 -27
  60. data/lib/deepl/utils/backoff_timer.rb +0 -46
  61. data/lib/deepl/utils/exception_builder.rb +0 -34
  62. data/lib/deepl.rb +0 -147
  63. data/lib/http_client_options.rb +0 -22
  64. data/spec/api/api_spec.rb +0 -20
  65. data/spec/api/configuration_spec.rb +0 -122
  66. data/spec/api/deepl_spec.rb +0 -460
  67. data/spec/constants/constants_spec.rb +0 -158
  68. data/spec/fixtures/vcr_cassettes/deepl_document.yml +0 -95
  69. data/spec/fixtures/vcr_cassettes/deepl_document_download.yml +0 -1214
  70. data/spec/fixtures/vcr_cassettes/deepl_glossaries.yml +0 -1163
  71. data/spec/fixtures/vcr_cassettes/deepl_languages.yml +0 -54
  72. data/spec/fixtures/vcr_cassettes/deepl_rephrase.yml +0 -87
  73. data/spec/fixtures/vcr_cassettes/deepl_translate.yml +0 -358
  74. data/spec/fixtures/vcr_cassettes/deepl_usage.yml +0 -129
  75. data/spec/fixtures/vcr_cassettes/glossaries.yml +0 -1702
  76. data/spec/fixtures/vcr_cassettes/languages.yml +0 -229
  77. data/spec/fixtures/vcr_cassettes/rephrase_texts.yml +0 -401
  78. data/spec/fixtures/vcr_cassettes/translate_texts.yml +0 -10415
  79. data/spec/fixtures/vcr_cassettes/usage.yml +0 -171
  80. data/spec/integration_tests/document_api_spec.rb +0 -177
  81. data/spec/integration_tests/integration_test_utils.rb +0 -170
  82. data/spec/requests/glossary/create_spec.rb +0 -65
  83. data/spec/requests/glossary/destroy_spec.rb +0 -66
  84. data/spec/requests/glossary/entries_spec.rb +0 -62
  85. data/spec/requests/glossary/find_spec.rb +0 -68
  86. data/spec/requests/glossary/language_pairs_spec.rb +0 -40
  87. data/spec/requests/glossary/list_spec.rb +0 -54
  88. data/spec/requests/languages_spec.rb +0 -68
  89. data/spec/requests/rephrase_spec.rb +0 -172
  90. data/spec/requests/translate_spec.rb +0 -422
  91. data/spec/requests/usage_spec.rb +0 -43
  92. data/spec/resources/glossary_spec.rb +0 -38
  93. data/spec/resources/language_pair_spec.rb +0 -23
  94. data/spec/resources/language_spec.rb +0 -45
  95. data/spec/resources/text_spec.rb +0 -23
  96. data/spec/resources/usage_spec.rb +0 -35
  97. data/spec/spec_helper.rb +0 -92
data/lib/deepl.rb DELETED
@@ -1,147 +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/languages'
35
- require 'deepl/requests/translate'
36
- require 'deepl/requests/usage'
37
- require 'deepl/requests/rephrase'
38
-
39
- # -- Responses and resources
40
- require 'deepl/resources/base'
41
- require 'deepl/resources/document_handle'
42
- require 'deepl/resources/document_translation_status'
43
- require 'deepl/resources/glossary'
44
- require 'deepl/resources/language'
45
- require 'deepl/resources/language_pair'
46
- require 'deepl/resources/text'
47
- require 'deepl/resources/usage'
48
-
49
- # -- Utils
50
- require 'deepl/utils/exception_builder'
51
- require 'deepl/utils/backoff_timer'
52
-
53
- # -- Constants
54
- require 'deepl/constants/base_constant'
55
- require 'deepl/constants/formality'
56
- require 'deepl/constants/model_type'
57
- require 'deepl/constants/split_sentences'
58
- require 'deepl/constants/tag_handling'
59
- require 'deepl/constants/tone'
60
- require 'deepl/constants/writing_style'
61
-
62
- # -- HTTP Utils
63
- require 'http_client_options'
64
-
65
- # -- Other wrappers
66
- require 'deepl/api'
67
- require 'deepl/configuration'
68
- require 'deepl/document_api'
69
- require 'deepl/glossary_api'
70
-
71
- # -- Gem interface
72
- module DeepL
73
- extend self
74
-
75
- ## -- API shortcuts
76
-
77
- def api
78
- @api ||= API.new(configuration)
79
- end
80
-
81
- def languages(options = {})
82
- Requests::Languages.new(api, options).request
83
- end
84
-
85
- def translate(text, source_lang, target_lang, options = {})
86
- configure if @configuration.nil?
87
- Requests::Translate.new(api, text, source_lang, target_lang, options).request
88
- end
89
-
90
- def document(options = {})
91
- configure if @configuration.nil?
92
- DocumentApi.new(api, options)
93
- end
94
-
95
- def glossaries(options = {})
96
- configure if @configuration.nil?
97
- GlossaryApi.new(api, options)
98
- end
99
-
100
- def rephrase(text, target_lang = nil, writing_style = nil, tone = nil, options = {}) # rubocop:disable Metrics/ParameterLists
101
- configure if @configuration.nil?
102
- Requests::Rephrase.new(api, text, target_lang, writing_style, tone, options).request
103
- end
104
-
105
- def usage(options = {})
106
- configure if @configuration.nil?
107
- Requests::Usage.new(api, options).request
108
- end
109
-
110
- def http_client
111
- @http_client
112
- end
113
-
114
- def with_session(client_options = HTTPClientOptions.new()) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
115
- 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
116
-
117
- has_proxy = client_options.proxy.key?('proxy_addr') and client_options.proxy.key?('proxy_port')
118
- begin
119
- uri = URI(configuration.host)
120
- http = Net::HTTP.new(uri.host, uri.port, has_proxy ? client_options.proxy['proxy_addr'] : nil,
121
- has_proxy ? client_options.proxy['proxy_port'] : nil)
122
- http.use_ssl = client_options.enable_ssl_verification
123
- http.ca_file = client_options.cert_path if client_options.cert_path
124
- http.open_timeout = client_options.open_timeout unless client_options.open_timeout.nil?
125
- http.read_timeout = client_options.read_timeout unless client_options.read_timeout.nil?
126
- http.write_timeout = client_options.write_timeout unless client_options.write_timeout.nil?
127
- http.ssl_timeout = client_options.ssl_timeout unless client_options.ssl_timeout.nil?
128
- http.start
129
- @http_client = http
130
- api.update_http_client(http)
131
- yield
132
- ensure
133
- http.finish
134
- end
135
- end
136
-
137
- # -- Configuration
138
-
139
- def configuration
140
- @configuration ||= Configuration.new
141
- end
142
-
143
- def configure
144
- yield configuration if block_given?
145
- configuration.validate!
146
- end
147
- 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/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