deepl-rb 2.3.1 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12e4767413ff5fc13b5b91e23cdc80c99b7252045753f7c2ef197bc4b0c0a0d2
4
- data.tar.gz: 05ac02229186bc7cf8f234767f8a258b2c472e4045fa4f5c006f77bbc14314b3
3
+ metadata.gz: 9f9236d354e5ca92bb03e6c8f34e9b332dff42c1bd985a80193b39f7509bbf99
4
+ data.tar.gz: d0796f1d303279647026c81a588f1d8442b526edc9c0f7be13252fff7cbd957b
5
5
  SHA512:
6
- metadata.gz: 218d0486a3ae68ab23849762976810940d8e2efb6fadc094e0b63d62e59a5c2ef06129a8a6681d8a985875a0bcf92ba4767d769826ab1a545c0a26391529808c
7
- data.tar.gz: d991c7bb24a02f5c0f415bcd27c728f936a8365c20a1b91847f1cef4ba1b8031a01e23b17fe4ba7ad13aec58f6df5c2df112af2457f08a6e61cda54879cc12c9
6
+ metadata.gz: 9c30aea5725784be6a7766bc9d7c8a0909338937352dfbe04254341d7355f12ffad801c14364b10a8b0eefccc52dd003783e22f3b9679f65767fb664b27b710f
7
+ data.tar.gz: 3a4b61ebfdd6f130ec1d24a0d7ee81c7cab1b783dfb7a6e113a2af91f4240863fe727c5a054b9487e3d4bd2af011d644d15b426ae46a1c435b89ade536cc7c6a
data/README.md CHANGED
@@ -71,7 +71,10 @@ puts DeepL.languages(type: :target).count
71
71
  ```
72
72
 
73
73
  All languages are also defined on the
74
- [official API documentation](https://www.deepl.com/docs-api/translating-text/)
74
+ [official API documentation](https://www.deepl.com/docs-api/translating-text/).
75
+
76
+ Note that target languages may include the `supports_formality` flag, which may be checked
77
+ using the `DeepL::Resources::Language#supports_formality?`.
75
78
 
76
79
  ### Translate
77
80
 
@@ -154,6 +157,7 @@ You can capture and process exceptions that may be raised during API calls. Thes
154
157
  | `DeepL::Exceptions::LimitExceeded` | You've reached the API's call limit. |
155
158
  | `DeepL::Exceptions::QuotaExceeded` | You've reached the API's character limit. |
156
159
  | `DeepL::Exceptions::RequestError` | An unkown request error. Check `exception.response` and `exception.request` for more information. |
160
+ | `DeepL::Exceptions::NotSupported` | The requested method or API endpoint is not supported. |
157
161
 
158
162
  An exampling of handling a generic exception:
159
163
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.1
1
+ 2.4.0
data/deepl-rb.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: deepl-rb 2.3.1 ruby lib
5
+ # stub: deepl-rb 2.4.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "deepl-rb".freeze
9
- s.version = "2.3.1"
9
+ s.version = "2.4.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Daniel Herzog".freeze]
14
- s.date = "2021-09-28"
14
+ s.date = "2022-01-24"
15
15
  s.description = "A simple ruby wrapper for the DeepL translation API (v1). For more information, check this: https://www.deepl.com/docs/api-reference.html".freeze
16
16
  s.email = "info@danielherzog.es".freeze
17
17
  s.extra_rdoc_files = [
@@ -34,6 +34,7 @@ Gem::Specification.new do |s|
34
34
  "lib/deepl/exceptions/bad_request.rb",
35
35
  "lib/deepl/exceptions/error.rb",
36
36
  "lib/deepl/exceptions/limit_exceeded.rb",
37
+ "lib/deepl/exceptions/not_supported.rb",
37
38
  "lib/deepl/exceptions/quota_exceeded.rb",
38
39
  "lib/deepl/exceptions/request_error.rb",
39
40
  "lib/deepl/requests/base.rb",
@@ -18,7 +18,7 @@ module DeepL
18
18
  end
19
19
 
20
20
  def attributes
21
- ATTRIBUTES.map { |attr| [attr, send(attr)] }.to_h
21
+ ATTRIBUTES.to_h { |attr| [attr, send(attr)] }
22
22
  end
23
23
 
24
24
  def ==(other)
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeepL
4
+ module Exceptions
5
+ class NotSupported < Error
6
+ def initialize(msg = 'The feature is not supported')
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
@@ -16,7 +16,9 @@ module DeepL
16
16
  def build_languages(request, response)
17
17
  data = JSON.parse(response.body)
18
18
  data.map do |language|
19
- Resources::Language.new(language['language'], language['name'], request, response)
19
+ Resources::Language.new(language['language'], language['name'],
20
+ language['supports_formality'],
21
+ request, response)
20
22
  end
21
23
  end
22
24
 
@@ -5,16 +5,23 @@ module DeepL
5
5
  class Language < Base
6
6
  attr_reader :code, :name
7
7
 
8
- def initialize(code, name, *args)
8
+ def initialize(code, name, supports_formality, *args)
9
9
  super(*args)
10
10
 
11
11
  @code = code
12
12
  @name = name
13
+ @supports_formality = supports_formality
13
14
  end
14
15
 
15
16
  def to_s
16
17
  "#{code} - #{name}"
17
18
  end
19
+
20
+ def supports_formality?
21
+ return @supports_formality unless @supports_formality.nil?
22
+
23
+ raise Exceptions::NotSupported, 'Support formality is only available on target languages'
24
+ end
18
25
  end
19
26
  end
20
27
  end
data/lib/deepl.rb CHANGED
@@ -11,6 +11,7 @@ require 'deepl/exceptions/authorization_failed'
11
11
  require 'deepl/exceptions/bad_request'
12
12
  require 'deepl/exceptions/limit_exceeded'
13
13
  require 'deepl/exceptions/quota_exceeded'
14
+ require 'deepl/exceptions/not_supported'
14
15
 
15
16
  # -- Requests
16
17
  require 'deepl/requests/base'
@@ -3,7 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe DeepL::Resources::Language do
6
- subject { described_class.new('EN', 'English', nil, nil) }
6
+ subject { described_class.new('EN', 'English', nil, nil, nil) }
7
7
 
8
8
  describe '#initialize' do
9
9
  context 'When building a basic object' do
@@ -15,6 +15,28 @@ describe DeepL::Resources::Language do
15
15
  expect(subject.code).to eq('EN')
16
16
  expect(subject.name).to eq('English')
17
17
  end
18
+
19
+ it 'should not define the supports formality method' do
20
+ expect { subject.supports_formality? }.to raise_error(DeepL::Exceptions::NotSupported)
21
+ end
22
+ end
23
+
24
+ context 'when building a target language object' do
25
+ subject { described_class.new('EN', 'English', true, nil, nil) }
26
+
27
+ it 'should create a resource' do
28
+ expect(subject).to be_a(described_class)
29
+ end
30
+
31
+ it 'should assign the attributes' do
32
+ expect(subject.code).to eq('EN')
33
+ expect(subject.name).to eq('English')
34
+ end
35
+
36
+ it 'should include the supports formality method' do
37
+ expect { subject.supports_formality? }.not_to raise_error
38
+ expect(subject.supports_formality?).to be_truthy
39
+ end
18
40
  end
19
41
  end
20
42
  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.3.1
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Herzog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-28 00:00:00.000000000 Z
11
+ date: 2022-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: juwelier
@@ -62,6 +62,7 @@ files:
62
62
  - lib/deepl/exceptions/bad_request.rb
63
63
  - lib/deepl/exceptions/error.rb
64
64
  - lib/deepl/exceptions/limit_exceeded.rb
65
+ - lib/deepl/exceptions/not_supported.rb
65
66
  - lib/deepl/exceptions/quota_exceeded.rb
66
67
  - lib/deepl/exceptions/request_error.rb
67
68
  - lib/deepl/requests/base.rb