deepl-rb 2.5.3 → 3.0.1

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 +39 -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 +121 -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 +3 -0
  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 +155 -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
@@ -1,31 +1,34 @@
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.
1
4
  # frozen_string_literal: true
2
5
 
3
6
  require 'spec_helper'
4
7
 
5
8
  describe DeepL::Resources::Usage do
6
- subject { described_class.new(3, 5, nil, nil) }
9
+ subject(:usage) { described_class.new(3, 5, nil, nil) }
7
10
 
8
11
  describe '#initialize' do
9
- context 'When building a basic object' do
10
- it 'should create a resource' do
11
- expect(subject).to be_a(described_class)
12
+ context 'when building a basic object' do
13
+ it 'creates a resource' do
14
+ expect(usage).to be_a(described_class)
12
15
  end
13
16
 
14
- it 'should assign the attributes' do
15
- expect(subject.character_count).to eq(3)
16
- expect(subject.character_limit).to eq(5)
17
+ it 'assigns the attributes' do
18
+ expect(usage.character_count).to eq(3)
19
+ expect(usage.character_limit).to eq(5)
17
20
  end
18
21
 
19
- it 'should not exceed the quota' do
20
- expect(subject.quota_exceeded?).to be_falsey
22
+ it 'does not exceed the quota' do
23
+ expect(usage).not_to be_quota_exceeded
21
24
  end
22
25
  end
23
26
 
24
- context 'When building a quota exceeded object' do
25
- subject { described_class.new(5, 5, nil, nil) }
27
+ context 'when building a quota exceeded object' do
28
+ subject(:usage) { described_class.new(5, 5, nil, nil) }
26
29
 
27
- it 'should exceed the quota' do
28
- expect(subject.quota_exceeded?).to be_truthy
30
+ it 'exceeds the quota' do
31
+ expect(usage).to be_quota_exceeded
29
32
  end
30
33
  end
31
34
  end
data/spec/spec_helper.rb CHANGED
@@ -1,18 +1,56 @@
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.
1
4
  # frozen_string_literal: true
2
5
 
3
6
  # Coverage
4
7
  require 'simplecov'
5
8
  SimpleCov.start
6
9
 
7
- require 'codecov'
8
- SimpleCov.formatter = SimpleCov::Formatter::Codecov
10
+ require 'simplecov-cobertura'
11
+ SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
9
12
 
10
13
  # Load lib
11
14
  require_relative '../lib/deepl'
15
+ require_relative 'integration_tests/integration_test_utils'
12
16
 
13
17
  # Lib config
14
18
  ENV['DEEPL_AUTH_KEY'] ||= 'TEST-TOKEN'
15
19
 
20
+ # General helpers
21
+ def build_deepl_api
22
+ DeepL::API.new(DeepL::Configuration.new)
23
+ end
24
+
25
+ uri_ignoring_deepl_api_subdomain = lambda do |request1, request2|
26
+ deepl_api_regexp = %r{https?://api.*\.deepl\.com/}
27
+ uri1 = request1.uri
28
+ uri2 = request2.uri
29
+ uri1_match = uri1.match(deepl_api_regexp)
30
+ uri2_match = uri2.match(deepl_api_regexp)
31
+ if uri1_match && uri2_match
32
+ uri1_without_deepl_domain = uri1.gsub(uri1_match[0], '')
33
+ uri2_without_deepl_domain = uri2.gsub(uri2_match[0], '')
34
+ uri1_without_deepl_domain == uri2_without_deepl_domain
35
+ else
36
+ uri1 == uri2
37
+ end
38
+ end
39
+
40
+ headers_ignoring_user_agent = lambda do |request1, request2|
41
+ user_agent_key = 'User-Agent'
42
+ # Pass by reference, so we need to use a copy of the headers
43
+ headers1 = request1.headers.dup
44
+ headers2 = request2.headers.dup
45
+ headers1_has_user_agent = headers1.key?(user_agent_key)
46
+ headers2_has_user_agent = headers2.key?(user_agent_key)
47
+ return false if headers1_has_user_agent != headers2_has_user_agent
48
+
49
+ headers1.delete(user_agent_key)
50
+ headers2.delete(user_agent_key)
51
+ headers1 == headers2
52
+ end
53
+
16
54
  # VCR tapes configuration
17
55
  require 'vcr'
18
56
  VCR.configure do |config|
@@ -20,12 +58,31 @@ VCR.configure do |config|
20
58
  config.hook_into :webmock
21
59
  config.filter_sensitive_data('VALID_TOKEN') { ENV.fetch('DEEPL_AUTH_KEY', nil) }
22
60
  config.default_cassette_options = {
61
+ # Uncomment this line when adding new tests, run the tests once, then comment it again
23
62
  # record: :new_episodes,
24
- match_requests_on: %i[method uri body headers]
63
+ match_requests_on: [:method, uri_ignoring_deepl_api_subdomain, :body,
64
+ headers_ignoring_user_agent]
25
65
  }
26
66
  end
27
67
 
28
- # General helpers
29
- def build_deepl_api
30
- DeepL::API.new(DeepL::Configuration.new(host: 'https://api-free.deepl.com'))
68
+ # Test helpers
69
+
70
+ def replace_env_preserving_deepl_vars
71
+ env_auth_key = ENV.fetch('DEEPL_AUTH_KEY', false)
72
+ env_server_url = ENV.fetch('DEEPL_SERVER_URL', false)
73
+ env_mock_server_port = ENV.fetch('DEEPL_MOCK_SERVER_PORT', false)
74
+ tmp_env = ENV.to_hash
75
+ ENV.clear
76
+ ENV['DEEPL_AUTH_KEY'] = (env_auth_key || 'VALID')
77
+ ENV['DEEPL_SERVER_URL'] = (env_server_url || '')
78
+ ENV['DEEPL_MOCK_SERVER_PORT'] = (env_mock_server_port || '')
79
+ tmp_env
80
+ end
81
+
82
+ def replace_env_preserving_deepl_vars_except_mock_server
83
+ env_auth_key = ENV.fetch('DEEPL_AUTH_KEY', false)
84
+ tmp_env = ENV.to_hash
85
+ ENV.clear
86
+ ENV['DEEPL_AUTH_KEY'] = (env_auth_key || 'VALID')
87
+ tmp_env
31
88
  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: 2.5.3
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
- - Daniel Herzog
7
+ - DeepL SE
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-26 00:00:00.000000000 Z
11
+ date: 2024-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: juwelier
@@ -38,28 +38,38 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: 'A simple ruby wrapper for the DeepL translation API (v1). For more information,
42
- check this: https://www.deepl.com/docs/api-reference.html'
43
- email: info@danielherzog.es
41
+ description: 'Official Ruby library for the DeepL language translation API (v2). For
42
+ more information, check this: https://www.deepl.com/docs/api-reference.html'
43
+ email: open-source@deepl.com
44
44
  executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files:
47
+ - CHANGELOG.md
47
48
  - LICENSE.md
48
49
  - README.md
50
+ - license_checker.sh
49
51
  files:
50
52
  - ".circleci/config.yml"
53
+ - ".github/workflows/add_issues_to_kanban.yml"
54
+ - ".gitlab-ci.yml"
51
55
  - ".rubocop.yml"
56
+ - CHANGELOG.md
57
+ - CODE_OF_CONDUCT.md
58
+ - CONTRIBUTING.md
52
59
  - Gemfile
53
60
  - LICENSE.md
54
61
  - README.md
55
62
  - Rakefile
63
+ - SECURITY.md
56
64
  - VERSION
57
65
  - deepl-rb.gemspec
58
66
  - lib/deepl.rb
59
67
  - lib/deepl/api.rb
60
68
  - lib/deepl/configuration.rb
69
+ - lib/deepl/document_api.rb
61
70
  - lib/deepl/exceptions/authorization_failed.rb
62
71
  - lib/deepl/exceptions/bad_request.rb
72
+ - lib/deepl/exceptions/document_translation_error.rb
63
73
  - lib/deepl/exceptions/error.rb
64
74
  - lib/deepl/exceptions/limit_exceeded.rb
65
75
  - lib/deepl/exceptions/not_found.rb
@@ -67,8 +77,12 @@ files:
67
77
  - lib/deepl/exceptions/quota_exceeded.rb
68
78
  - lib/deepl/exceptions/request_entity_too_large.rb
69
79
  - lib/deepl/exceptions/request_error.rb
80
+ - lib/deepl/exceptions/server_error.rb
70
81
  - lib/deepl/glossary_api.rb
71
82
  - lib/deepl/requests/base.rb
83
+ - lib/deepl/requests/document/download.rb
84
+ - lib/deepl/requests/document/get_status.rb
85
+ - lib/deepl/requests/document/upload.rb
72
86
  - lib/deepl/requests/glossary/create.rb
73
87
  - lib/deepl/requests/glossary/destroy.rb
74
88
  - lib/deepl/requests/glossary/entries.rb
@@ -79,15 +93,22 @@ files:
79
93
  - lib/deepl/requests/translate.rb
80
94
  - lib/deepl/requests/usage.rb
81
95
  - lib/deepl/resources/base.rb
96
+ - lib/deepl/resources/document_handle.rb
97
+ - lib/deepl/resources/document_translation_status.rb
82
98
  - lib/deepl/resources/glossary.rb
83
99
  - lib/deepl/resources/language.rb
84
100
  - lib/deepl/resources/language_pair.rb
85
101
  - lib/deepl/resources/text.rb
86
102
  - lib/deepl/resources/usage.rb
103
+ - lib/deepl/utils/backoff_timer.rb
87
104
  - lib/deepl/utils/exception_builder.rb
105
+ - lib/http_client_options.rb
106
+ - license_checker.sh
88
107
  - spec/api/api_spec.rb
89
108
  - spec/api/configuration_spec.rb
90
109
  - spec/api/deepl_spec.rb
110
+ - spec/fixtures/vcr_cassettes/deepl_document.yml
111
+ - spec/fixtures/vcr_cassettes/deepl_document_download.yml
91
112
  - spec/fixtures/vcr_cassettes/deepl_glossaries.yml
92
113
  - spec/fixtures/vcr_cassettes/deepl_languages.yml
93
114
  - spec/fixtures/vcr_cassettes/deepl_translate.yml
@@ -96,6 +117,8 @@ files:
96
117
  - spec/fixtures/vcr_cassettes/languages.yml
97
118
  - spec/fixtures/vcr_cassettes/translate_texts.yml
98
119
  - spec/fixtures/vcr_cassettes/usage.yml
120
+ - spec/integration_tests/document_api_spec.rb
121
+ - spec/integration_tests/integration_test_utils.rb
99
122
  - spec/requests/glossary/create_spec.rb
100
123
  - spec/requests/glossary/destroy_spec.rb
101
124
  - spec/requests/glossary/entries_spec.rb
@@ -111,7 +134,7 @@ files:
111
134
  - spec/resources/text_spec.rb
112
135
  - spec/resources/usage_spec.rb
113
136
  - spec/spec_helper.rb
114
- homepage: http://github.com/wikiti/deepl-rb
137
+ homepage: https://github.com/DeepLcom/deepl-rb
115
138
  licenses:
116
139
  - MIT
117
140
  metadata: {}
@@ -130,8 +153,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
153
  - !ruby/object:Gem::Version
131
154
  version: '0'
132
155
  requirements: []
133
- rubygems_version: 3.3.7
156
+ rubygems_version: 3.4.6
134
157
  signing_key:
135
158
  specification_version: 4
136
- summary: A simple ruby wrapper for the DeepL API
159
+ summary: Official Ruby library for the DeepL language translation API.
137
160
  test_files: []