deepl-rb 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,177 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.deepl.com/v1/translate?auth_key=VALID_TOKEN
6
+ body:
7
+ encoding: US-ASCII
8
+ string: text=Sample+text&source_lang=EN&target_lang=ES
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - nginx
25
+ Date:
26
+ - Sun, 10 Dec 2017 20:34:26 GMT
27
+ Content-Type:
28
+ - application/json
29
+ Content-Length:
30
+ - '78'
31
+ Connection:
32
+ - keep-alive
33
+ Access-Control-Allow-Origin:
34
+ - "*"
35
+ body:
36
+ encoding: UTF-8
37
+ string: '{"translations":[{"detected_source_language":"EN","text":"Texto de
38
+ muestra"}]}'
39
+ http_version:
40
+ recorded_at: Sun, 10 Dec 2017 20:34:26 GMT
41
+ - request:
42
+ method: post
43
+ uri: https://api.deepl.com/v1/translate?auth_key=VALID_TOKEN
44
+ body:
45
+ encoding: US-ASCII
46
+ string: text=Sample&text=Word&source_lang=EN&target_lang=ES
47
+ headers:
48
+ Accept-Encoding:
49
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
50
+ Accept:
51
+ - "*/*"
52
+ User-Agent:
53
+ - Ruby
54
+ Content-Type:
55
+ - application/x-www-form-urlencoded
56
+ response:
57
+ status:
58
+ code: 200
59
+ message: OK
60
+ headers:
61
+ Server:
62
+ - nginx
63
+ Date:
64
+ - Sun, 10 Dec 2017 20:34:26 GMT
65
+ Content-Type:
66
+ - application/json
67
+ Content-Length:
68
+ - '120'
69
+ Connection:
70
+ - keep-alive
71
+ Access-Control-Allow-Origin:
72
+ - "*"
73
+ body:
74
+ encoding: UTF-8
75
+ string: '{"translations":[{"detected_source_language":"EN","text":"Muestra"},{"detected_source_language":"EN","text":"Palabra"}]}'
76
+ http_version:
77
+ recorded_at: Sun, 10 Dec 2017 20:34:26 GMT
78
+ - request:
79
+ method: post
80
+ uri: https://api.deepl.com/v1/translate?auth_key=invalid
81
+ body:
82
+ encoding: US-ASCII
83
+ string: text=Sample+text&source_lang=EN&target_lang=ES
84
+ headers:
85
+ Accept-Encoding:
86
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
87
+ Accept:
88
+ - "*/*"
89
+ User-Agent:
90
+ - Ruby
91
+ Content-Type:
92
+ - application/x-www-form-urlencoded
93
+ response:
94
+ status:
95
+ code: 403
96
+ message: Forbidden
97
+ headers:
98
+ Server:
99
+ - nginx
100
+ Date:
101
+ - Sun, 10 Dec 2017 20:34:27 GMT
102
+ Content-Length:
103
+ - '0'
104
+ Connection:
105
+ - keep-alive
106
+ body:
107
+ encoding: UTF-8
108
+ string: ''
109
+ http_version:
110
+ recorded_at: Sun, 10 Dec 2017 20:34:27 GMT
111
+ - request:
112
+ method: post
113
+ uri: https://api.deepl.com/v1/translate?auth_key=VALID_TOKEN
114
+ body:
115
+ encoding: US-ASCII
116
+ string: source_lang=EN&target_lang=ES
117
+ headers:
118
+ Accept-Encoding:
119
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
120
+ Accept:
121
+ - "*/*"
122
+ User-Agent:
123
+ - Ruby
124
+ Content-Type:
125
+ - application/x-www-form-urlencoded
126
+ response:
127
+ status:
128
+ code: 400
129
+ message: Bad Request
130
+ headers:
131
+ Server:
132
+ - nginx
133
+ Date:
134
+ - Sun, 10 Dec 2017 20:34:27 GMT
135
+ Content-Length:
136
+ - '45'
137
+ Connection:
138
+ - keep-alive
139
+ body:
140
+ encoding: UTF-8
141
+ string: '{"message":"Parameter ''text'' not specified."}'
142
+ http_version:
143
+ recorded_at: Sun, 10 Dec 2017 20:34:27 GMT
144
+ - request:
145
+ method: post
146
+ uri: https://api.deepl.com/v1/translate?auth_key=VALID_TOKEN
147
+ body:
148
+ encoding: US-ASCII
149
+ string: text=Sample+text&source_lang=EN
150
+ headers:
151
+ Accept-Encoding:
152
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
153
+ Accept:
154
+ - "*/*"
155
+ User-Agent:
156
+ - Ruby
157
+ Content-Type:
158
+ - application/x-www-form-urlencoded
159
+ response:
160
+ status:
161
+ code: 400
162
+ message: Bad Request
163
+ headers:
164
+ Server:
165
+ - nginx
166
+ Date:
167
+ - Sun, 10 Dec 2017 20:34:28 GMT
168
+ Content-Length:
169
+ - '52'
170
+ Connection:
171
+ - keep-alive
172
+ body:
173
+ encoding: UTF-8
174
+ string: '{"message":"Parameter ''target_lang'' not specified."}'
175
+ http_version:
176
+ recorded_at: Sun, 10 Dec 2017 20:34:28 GMT
177
+ recorded_with: VCR 4.0.0
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe DeepL::Requests::TranslateText do
4
+ let(:api) { build_deepl_api }
5
+ let(:text) { 'Sample text' }
6
+ let(:source_lang) { 'EN' }
7
+ let(:target_lang) { 'ES' }
8
+ subject { DeepL::Requests::TranslateText.new(api, text, source_lang, target_lang) }
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(DeepL::Requests::TranslateText)
14
+ end
15
+ end
16
+ end
17
+
18
+ describe '#request' do
19
+ around do |example|
20
+ VCR.use_cassette('translate_texts') { example.call }
21
+ end
22
+
23
+ context 'When performing a valid request with one text' do
24
+ it 'should return a text object' do
25
+ text = subject.request
26
+
27
+ expect(text).to be_a(DeepL::Resources::Text)
28
+ expect(text.text).to eq('Texto de muestra')
29
+ expect(text.detected_source_language).to eq('EN')
30
+ end
31
+ end
32
+
33
+ context 'When performing a valid request with multiple texts' do
34
+ let(:text) { %w[Sample Word] }
35
+
36
+ it 'should return a text object' do
37
+ texts = subject.request
38
+
39
+ expect(texts).to be_a(Array)
40
+ expect(texts.first.text).to eq('Muestra')
41
+ expect(texts.first.detected_source_language).to eq('EN')
42
+
43
+ expect(texts.last.text).to eq('Palabra')
44
+ expect(texts.last.detected_source_language).to eq('EN')
45
+ end
46
+ end
47
+
48
+ context 'When performing a bad request' do
49
+ context 'When using an invalid token' do
50
+ let(:api) do
51
+ api = build_deepl_api
52
+ api.configuration.auth_key = 'invalid'
53
+ api
54
+ end
55
+
56
+ it 'should raise an unauthorized error' do
57
+ expect { subject.request }.to raise_error(DeepL::Exceptions::AuthorizationFailed)
58
+ end
59
+ end
60
+
61
+ context 'When using an invalid text' do
62
+ let(:text) { nil }
63
+
64
+ it 'should raise a bad request error' do
65
+ message = "Parameter 'text' not specified."
66
+ expect { subject.request }.to raise_error(DeepL::Exceptions::BadRequest, message)
67
+ end
68
+ end
69
+
70
+ context 'When using an invalid target language' do
71
+ let(:target_lang) { nil }
72
+
73
+ it 'should raise a bad request error' do
74
+ message = "Parameter 'target_lang' not specified."
75
+ expect { subject.request }.to raise_error(DeepL::Exceptions::BadRequest, message)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe DeepL::Resources::Text do
4
+ subject { DeepL::Resources::Text.new('Target', 'es', nil, nil) }
5
+
6
+ describe '#initialize' do
7
+ context 'When building a basic object' do
8
+ it 'should create a resource' do
9
+ expect(subject).to be_a(DeepL::Resources::Text)
10
+ end
11
+
12
+ it 'should assign the attributes' do
13
+ expect(subject.text).to eq('Target')
14
+ expect(subject.detected_source_language).to eq('es')
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ require 'vcr'
2
+
3
+ require_relative '../lib/deepl'
4
+
5
+ # Lib config
6
+ ENV['DEEPL_AUTH_KEY'] ||= 'TEST-TOKEN'
7
+
8
+ # VCR tapes configuration
9
+ VCR.configure do |config|
10
+ config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
11
+ config.hook_into :webmock
12
+ config.filter_sensitive_data('VALID_TOKEN') { ENV['DEEPL_AUTH_KEY'] }
13
+ config.default_cassette_options = {
14
+ record: :new_episodes,
15
+ match_requests_on: %i[method uri body]
16
+ }
17
+ end
18
+
19
+ # General helpers
20
+ def build_deepl_api
21
+ DeepL::API.new(DeepL::Configuration.new)
22
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deepl-rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Herzog
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: juwelier
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: 'A simple ruby wrapper for the DeepL translation API (v1). For more information,
28
+ check this: https://www.deepl.com/docs/api-reference.html'
29
+ email: info@danielherzog.es
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files:
33
+ - LICENSE.md
34
+ - README.md
35
+ files:
36
+ - ".circleci/config.yml"
37
+ - ".rubocop.yml"
38
+ - Gemfile
39
+ - Gemfile.lock
40
+ - LICENSE.md
41
+ - README.md
42
+ - Rakefile
43
+ - VERSION
44
+ - deepl-rb.gemspec
45
+ - lib/deepl.rb
46
+ - lib/deepl/api.rb
47
+ - lib/deepl/configuration.rb
48
+ - lib/deepl/exceptions/authorization_failed.rb
49
+ - lib/deepl/exceptions/bad_request.rb
50
+ - lib/deepl/exceptions/error.rb
51
+ - lib/deepl/exceptions/limit_exceeded.rb
52
+ - lib/deepl/exceptions/request_error.rb
53
+ - lib/deepl/requests/base.rb
54
+ - lib/deepl/requests/translate_text.rb
55
+ - lib/deepl/resources/base.rb
56
+ - lib/deepl/resources/text.rb
57
+ - spec/api/api_spec.rb
58
+ - spec/api/configuration_spec.rb
59
+ - spec/api/deepl_spec.rb
60
+ - spec/fixtures/vcr_cassettes/deepl_translate.yml
61
+ - spec/fixtures/vcr_cassettes/translate_texts.yml
62
+ - spec/requests/translate_text_spec.rb
63
+ - spec/resources/text_spec.rb
64
+ - spec/spec_helper.rb
65
+ homepage: http://github.com/wikiti/deepl-rb
66
+ licenses:
67
+ - MIT
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.6.13
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: A simple ruby wrapper for the DeepL API
89
+ test_files: []