deepl-rb 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +1 -13
  3. data/.rubocop.yml +1 -0
  4. data/Gemfile +6 -0
  5. data/README.md +55 -24
  6. data/Rakefile +2 -0
  7. data/VERSION +1 -1
  8. data/deepl-rb.gemspec +16 -10
  9. data/lib/deepl.rb +9 -0
  10. data/lib/deepl/api.rb +2 -0
  11. data/lib/deepl/configuration.rb +2 -0
  12. data/lib/deepl/exceptions/authorization_failed.rb +2 -0
  13. data/lib/deepl/exceptions/bad_request.rb +4 -0
  14. data/lib/deepl/exceptions/error.rb +2 -0
  15. data/lib/deepl/exceptions/limit_exceeded.rb +2 -0
  16. data/lib/deepl/exceptions/quota_exceeded.rb +11 -0
  17. data/lib/deepl/exceptions/request_error.rb +4 -1
  18. data/lib/deepl/requests/base.rb +4 -1
  19. data/lib/deepl/requests/languages.rb +28 -0
  20. data/lib/deepl/requests/translate.rb +3 -0
  21. data/lib/deepl/requests/usage.rb +2 -0
  22. data/lib/deepl/resources/base.rb +2 -0
  23. data/lib/deepl/resources/language.rb +20 -0
  24. data/lib/deepl/resources/text.rb +2 -0
  25. data/lib/deepl/resources/usage.rb +2 -0
  26. data/spec/api/api_spec.rb +2 -0
  27. data/spec/api/configuration_spec.rb +3 -1
  28. data/spec/api/deepl_spec.rb +24 -0
  29. data/spec/fixtures/vcr_cassettes/deepl_languages.yml +41 -0
  30. data/spec/fixtures/vcr_cassettes/deepl_translate.yml +4 -5
  31. data/spec/fixtures/vcr_cassettes/deepl_usage.yml +10 -7
  32. data/spec/fixtures/vcr_cassettes/languages.yml +108 -0
  33. data/spec/fixtures/vcr_cassettes/translate_texts.yml +69 -33
  34. data/spec/fixtures/vcr_cassettes/usage.yml +10 -7
  35. data/spec/requests/languages_spec.rb +58 -0
  36. data/spec/requests/translate_spec.rb +6 -3
  37. data/spec/requests/usage_spec.rb +2 -0
  38. data/spec/resources/language_spec.rb +20 -0
  39. data/spec/resources/text_spec.rb +4 -2
  40. data/spec/resources/usage_spec.rb +5 -3
  41. data/spec/spec_helper.rb +3 -1
  42. metadata +27 -8
  43. data/Gemfile.lock +0 -113
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://api.deepl.com/v2/usage?auth_key=VALID_TOKEN
5
+ uri: https://api-free.deepl.com/v2/usage?auth_key=VALID_TOKEN
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
@@ -21,14 +21,17 @@ http_interactions:
21
21
  Server:
22
22
  - nginx
23
23
  Date:
24
- - Tue, 08 May 2018 20:42:44 GMT
24
+ - Mon, 17 May 2021 14:18:32 GMT
25
+ Content-Type:
26
+ - application/json
25
27
  Content-Length:
26
- - '52'
28
+ - '48'
27
29
  Connection:
28
30
  - keep-alive
31
+ Access-Control-Allow-Origin:
32
+ - "*"
29
33
  body:
30
34
  encoding: UTF-8
31
- string: '{"character_count":805718,"character_limit":1000000}'
32
- http_version:
33
- recorded_at: Tue, 08 May 2018 20:42:43 GMT
34
- recorded_with: VCR 4.0.0
35
+ string: '{"character_count":353,"character_limit":500000}'
36
+ recorded_at: Mon, 17 May 2021 14:18:32 GMT
37
+ recorded_with: VCR 6.0.0
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe DeepL::Requests::Languages do
6
+ let(:api) { build_deepl_api }
7
+ let(:options) { {} }
8
+ subject { DeepL::Requests::Languages.new(api, options) }
9
+
10
+ describe '#initialize' do
11
+ context 'When building a request' do
12
+ it 'should create a request object' do
13
+ expect(subject).to be_a(described_class)
14
+ end
15
+ end
16
+ end
17
+
18
+ describe '#request' do
19
+ around do |example|
20
+ VCR.use_cassette('languages') { example.call }
21
+ end
22
+
23
+ context 'When requesting source languages' do
24
+ it 'should return an usage object' do
25
+ languages = subject.request
26
+
27
+ expect(languages).to be_an(Array)
28
+ expect(languages.size).to eq(24)
29
+ expect(languages.any? { |l| l.code == 'EN' && l.name == 'English' }).to be_truthy
30
+ expect(languages.any? { |l| l.code == 'ES' && l.name == 'Spanish' }).to be_truthy
31
+ end
32
+ end
33
+
34
+ context 'When requesting target languages' do
35
+ let(:options) { { type: :target } }
36
+
37
+ it 'should return an usage object' do
38
+ languages = subject.request
39
+
40
+ expect(languages).to be_an(Array)
41
+ expect(languages.size).to eq(26)
42
+ expect(languages.any? { |l| l.code == 'EN' && l.name == 'English' }).to be_falsey
43
+ expect(languages.any? { |l| l.code == 'ES' && l.name == 'Spanish' }).to be_truthy
44
+ expect(languages.any? { |l| l.code == 'EN-US' && l.name == 'English (American)' })
45
+ .to be_truthy
46
+ end
47
+ end
48
+
49
+ context 'When using an invalid type' do
50
+ let(:options) { { type: :invalid } }
51
+
52
+ it 'should return an usage object' do
53
+ message = "Parameter 'type' is invalid. 'source' and 'target' are valid values."
54
+ expect { subject.request }.to raise_error(DeepL::Exceptions::BadRequest, message)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe DeepL::Requests::Translate do
@@ -149,6 +151,7 @@ describe DeepL::Requests::Translate do
149
151
 
150
152
  context 'When performing a valid request with tag handling' do
151
153
  let(:text) { '<p>Sample text</p>' }
154
+ let(:options) { { tag_handling: 'xml' } }
152
155
 
153
156
  it 'should return a text object' do
154
157
  text = subject.request
@@ -161,13 +164,13 @@ describe DeepL::Requests::Translate do
161
164
 
162
165
  context 'When performing a valid request and passing a variable' do
163
166
  let(:text) { 'Welcome and <code>Hello great World</code> Good Morning!' }
164
- let(:options) { { ignore_tags: 'code, span' } }
167
+ let(:options) { { tag_handling: 'xml', ignore_tags: 'code,span' } }
165
168
 
166
169
  it 'should return a text object' do
167
170
  text = subject.request
168
171
 
169
172
  expect(text).to be_a(DeepL::Resources::Text)
170
- expect(text.text).to eq('Bienvenido y <code>Hello great World</code> Buenos días!')
173
+ expect(text.text).to eq('Bienvenido y <code>Hello great World</code> ¡Buenos días!')
171
174
  expect(text.detected_source_language).to eq('EN')
172
175
  end
173
176
  end
@@ -198,7 +201,7 @@ describe DeepL::Requests::Translate do
198
201
  let(:target_lang) { nil }
199
202
 
200
203
  it 'should raise a bad request error' do
201
- message = "Parameter 'target_lang' not specified."
204
+ message = "Value for 'target_lang' not supported."
202
205
  expect { subject.request }.to raise_error(DeepL::Exceptions::BadRequest, message)
203
206
  end
204
207
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe DeepL::Requests::Usage do
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe DeepL::Resources::Language do
6
+ subject { described_class.new('EN', 'English', nil, nil) }
7
+
8
+ 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
+ end
13
+
14
+ it 'should assign the attributes' do
15
+ expect(subject.code).to eq('EN')
16
+ expect(subject.name).to eq('English')
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe DeepL::Resources::Text do
4
- subject { DeepL::Resources::Text.new('Target', 'es', nil, nil) }
6
+ subject { described_class.new('Target', 'es', nil, nil) }
5
7
 
6
8
  describe '#initialize' do
7
9
  context 'When building a basic object' do
8
10
  it 'should create a resource' do
9
- expect(subject).to be_a(DeepL::Resources::Text)
11
+ expect(subject).to be_a(described_class)
10
12
  end
11
13
 
12
14
  it 'should assign the attributes' do
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe DeepL::Resources::Usage do
4
- subject { DeepL::Resources::Usage.new(3, 5, nil, nil) }
6
+ subject { described_class.new(3, 5, nil, nil) }
5
7
 
6
8
  describe '#initialize' do
7
9
  context 'When building a basic object' do
8
10
  it 'should create a resource' do
9
- expect(subject).to be_a(DeepL::Resources::Usage)
11
+ expect(subject).to be_a(described_class)
10
12
  end
11
13
 
12
14
  it 'should assign the attributes' do
@@ -20,7 +22,7 @@ describe DeepL::Resources::Usage do
20
22
  end
21
23
 
22
24
  context 'When building a quota exceeded object' do
23
- subject { DeepL::Resources::Usage.new(5, 5, nil, nil) }
25
+ subject { described_class.new(5, 5, nil, nil) }
24
26
 
25
27
  it 'should exceed the quota' do
26
28
  expect(subject.quota_exceeded?).to be_truthy
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Coverage
2
4
  require 'simplecov'
3
5
  SimpleCov.start
@@ -25,5 +27,5 @@ end
25
27
 
26
28
  # General helpers
27
29
  def build_deepl_api
28
- DeepL::API.new(DeepL::Configuration.new)
30
+ DeepL::API.new(DeepL::Configuration.new(host: 'https://api-free.deepl.com'))
29
31
  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.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Herzog
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-28 00:00:00.000000000 Z
11
+ date: 2021-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: juwelier
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: 'A simple ruby wrapper for the DeepL translation API (v1). For more information,
28
42
  check this: https://www.deepl.com/docs/api-reference.html'
29
43
  email: info@danielherzog.es
@@ -36,7 +50,6 @@ files:
36
50
  - ".circleci/config.yml"
37
51
  - ".rubocop.yml"
38
52
  - Gemfile
39
- - Gemfile.lock
40
53
  - LICENSE.md
41
54
  - README.md
42
55
  - Rakefile
@@ -49,22 +62,29 @@ files:
49
62
  - lib/deepl/exceptions/bad_request.rb
50
63
  - lib/deepl/exceptions/error.rb
51
64
  - lib/deepl/exceptions/limit_exceeded.rb
65
+ - lib/deepl/exceptions/quota_exceeded.rb
52
66
  - lib/deepl/exceptions/request_error.rb
53
67
  - lib/deepl/requests/base.rb
68
+ - lib/deepl/requests/languages.rb
54
69
  - lib/deepl/requests/translate.rb
55
70
  - lib/deepl/requests/usage.rb
56
71
  - lib/deepl/resources/base.rb
72
+ - lib/deepl/resources/language.rb
57
73
  - lib/deepl/resources/text.rb
58
74
  - lib/deepl/resources/usage.rb
59
75
  - spec/api/api_spec.rb
60
76
  - spec/api/configuration_spec.rb
61
77
  - spec/api/deepl_spec.rb
78
+ - spec/fixtures/vcr_cassettes/deepl_languages.yml
62
79
  - spec/fixtures/vcr_cassettes/deepl_translate.yml
63
80
  - spec/fixtures/vcr_cassettes/deepl_usage.yml
81
+ - spec/fixtures/vcr_cassettes/languages.yml
64
82
  - spec/fixtures/vcr_cassettes/translate_texts.yml
65
83
  - spec/fixtures/vcr_cassettes/usage.yml
84
+ - spec/requests/languages_spec.rb
66
85
  - spec/requests/translate_spec.rb
67
86
  - spec/requests/usage_spec.rb
87
+ - spec/resources/language_spec.rb
68
88
  - spec/resources/text_spec.rb
69
89
  - spec/resources/usage_spec.rb
70
90
  - spec/spec_helper.rb
@@ -72,7 +92,7 @@ homepage: http://github.com/wikiti/deepl-rb
72
92
  licenses:
73
93
  - MIT
74
94
  metadata: {}
75
- post_install_message:
95
+ post_install_message:
76
96
  rdoc_options: []
77
97
  require_paths:
78
98
  - lib
@@ -87,9 +107,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
107
  - !ruby/object:Gem::Version
88
108
  version: '0'
89
109
  requirements: []
90
- rubyforge_project:
91
- rubygems_version: 2.6.14
92
- signing_key:
110
+ rubygems_version: 3.1.2
111
+ signing_key:
93
112
  specification_version: 4
94
113
  summary: A simple ruby wrapper for the DeepL API
95
114
  test_files: []
data/Gemfile.lock DELETED
@@ -1,113 +0,0 @@
1
- GEM
2
- remote: https://rubygems.org/
3
- specs:
4
- addressable (2.5.2)
5
- public_suffix (>= 2.0.2, < 4.0)
6
- ast (2.3.0)
7
- builder (3.2.3)
8
- codecov (0.1.10)
9
- json
10
- simplecov
11
- url
12
- crack (0.4.3)
13
- safe_yaml (~> 1.0.0)
14
- descendants_tracker (0.0.4)
15
- thread_safe (~> 0.3, >= 0.3.1)
16
- diff-lcs (1.3)
17
- docile (1.1.5)
18
- faraday (0.12.2)
19
- multipart-post (>= 1.2, < 3)
20
- git (1.3.0)
21
- github_api (0.18.2)
22
- addressable (~> 2.4)
23
- descendants_tracker (~> 0.0.4)
24
- faraday (~> 0.8)
25
- hashie (~> 3.5, >= 3.5.2)
26
- oauth2 (~> 1.0)
27
- hashdiff (0.3.7)
28
- hashie (3.5.7)
29
- highline (1.7.10)
30
- json (2.1.0)
31
- juwelier (2.1.3)
32
- builder
33
- bundler (>= 1.13)
34
- git (>= 1.2.5)
35
- github_api
36
- highline (>= 1.6.15)
37
- nokogiri (>= 1.5.10)
38
- rake
39
- rdoc
40
- semver
41
- jwt (1.5.6)
42
- mini_portile2 (2.3.0)
43
- multi_json (1.12.2)
44
- multi_xml (0.6.0)
45
- multipart-post (2.0.0)
46
- nokogiri (1.8.1)
47
- mini_portile2 (~> 2.3.0)
48
- oauth2 (1.4.0)
49
- faraday (>= 0.8, < 0.13)
50
- jwt (~> 1.0)
51
- multi_json (~> 1.3)
52
- multi_xml (~> 0.5)
53
- rack (>= 1.2, < 3)
54
- parallel (1.12.1)
55
- parser (2.4.0.2)
56
- ast (~> 2.3)
57
- powerpack (0.1.1)
58
- public_suffix (3.0.1)
59
- rack (1.6.8)
60
- rainbow (3.0.0)
61
- rake (12.3.0)
62
- rdoc (5.1.0)
63
- rspec (3.7.0)
64
- rspec-core (~> 3.7.0)
65
- rspec-expectations (~> 3.7.0)
66
- rspec-mocks (~> 3.7.0)
67
- rspec-core (3.7.1)
68
- rspec-support (~> 3.7.0)
69
- rspec-expectations (3.7.0)
70
- diff-lcs (>= 1.2.0, < 2.0)
71
- rspec-support (~> 3.7.0)
72
- rspec-mocks (3.7.0)
73
- diff-lcs (>= 1.2.0, < 2.0)
74
- rspec-support (~> 3.7.0)
75
- rspec-support (3.7.0)
76
- rubocop (0.52.1)
77
- parallel (~> 1.10)
78
- parser (>= 2.4.0.2, < 3.0)
79
- powerpack (~> 0.1)
80
- rainbow (>= 2.2.2, < 4.0)
81
- ruby-progressbar (~> 1.7)
82
- unicode-display_width (~> 1.0, >= 1.0.1)
83
- ruby-progressbar (1.9.0)
84
- safe_yaml (1.0.4)
85
- semver (1.0.1)
86
- simplecov (0.15.1)
87
- docile (~> 1.1.0)
88
- json (>= 1.8, < 3)
89
- simplecov-html (~> 0.10.0)
90
- simplecov-html (0.10.2)
91
- thread_safe (0.3.6)
92
- unicode-display_width (1.3.0)
93
- url (0.3.2)
94
- vcr (4.0.0)
95
- webmock (3.2.1)
96
- addressable (>= 2.3.6)
97
- crack (>= 0.3.2)
98
- hashdiff
99
-
100
- PLATFORMS
101
- ruby
102
-
103
- DEPENDENCIES
104
- codecov
105
- juwelier
106
- rspec
107
- rubocop
108
- simplecov
109
- vcr
110
- webmock
111
-
112
- BUNDLED WITH
113
- 1.16.0.pre.2