abbyy-cloud 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -0
- data/README.md +28 -0
- data/abbyy-cloud.gemspec +1 -1
- data/lib/abbyy/cloud.rb +8 -0
- data/lib/abbyy/cloud/connection.rb +2 -2
- data/lib/abbyy/cloud/exceptions/response_error.rb +9 -1
- data/lib/abbyy/cloud/models/direction.rb +12 -0
- data/lib/abbyy/cloud/models/engine.rb +14 -0
- data/lib/abbyy/cloud/models/error.rb +3 -3
- data/lib/abbyy/cloud/namespaces/machine_translations.rb +17 -0
- data/lib/abbyy/cloud/operations/base.rb +8 -7
- data/lib/abbyy/cloud/operations/engines.rb +13 -0
- data/lib/abbyy/cloud/operations/translate.rb +1 -1
- data/lib/abbyy/cloud/settings.rb +1 -1
- data/lib/abbyy/cloud/struct.rb +9 -6
- data/lib/abbyy/cloud/types.rb +16 -3
- data/spec/abbyy/cloud/models/direction_spec.rb +40 -0
- data/spec/abbyy/cloud/models/engine_spec.rb +70 -0
- data/spec/abbyy/cloud/models/error_spec.rb +55 -0
- data/spec/abbyy/cloud/models/translation_spec.rb +40 -0
- data/spec/abbyy/cloud/response_error_spec.rb +9 -1
- data/spec/abbyy/cloud/settings_spec.rb +0 -8
- data/spec/feature/abbyy/mt_engines_spec.rb +57 -0
- data/spec/feature/abbyy/order_translate_spec.rb +6 -6
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19c1ff610b7210be89b61f821ff6642ce0d149c3
|
4
|
+
data.tar.gz: 896dbcb70a0796ef0445b7184d703bba31c2259e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca702183cde764f614c77f26bb5bafa17a2f96614d230efccf97775f7f839fea047c35ea6bdb67b24fb270cada0402f89caefe0fcc8f7264fd295218e43f4a95
|
7
|
+
data.tar.gz: f4ec867431b3eab6e736700831db4f62aaa047289c90ee81847347bdf933331a1c742973c1ed96557a8f5f69fd4206577253a628d3fd4049049ae7f07f35dcb4
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,26 @@
|
|
1
|
+
# [v0.0.3 2016-08-18](https://github.com/nepalez/abbyy-cloud/tree/v0.0.3)
|
2
|
+
|
3
|
+
### Bugs Fixed
|
4
|
+
|
5
|
+
* Fix version in root path to ABBYY Cloud API (nepalez)
|
6
|
+
* Fix validation of language names (nepalez)
|
7
|
+
* Allow ResponseError to take response with non-json body (nepalez)
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
* Operation `.mt.engines` (nepalez)
|
12
|
+
|
13
|
+
### Changed
|
14
|
+
|
15
|
+
* Remove validation of engine names (nepalez)
|
16
|
+
|
17
|
+
### Internal
|
18
|
+
|
19
|
+
* Add coverage to all models (nepalez)
|
20
|
+
* Add method `Types.register_type` for custom types (nepalez)
|
21
|
+
|
22
|
+
[Compare v0.0.2...v0.0.3](https://github.com/nepalez/abbyy-cloud/compare/v0.0.2...v0.0.3)
|
23
|
+
|
1
24
|
# [v0.0.2 2016-08-18](https://github.com/nepalez/abbyy-cloud/tree/v0.0.2)
|
2
25
|
|
3
26
|
### Changed
|
data/README.md
CHANGED
@@ -17,6 +17,8 @@ The library is available as a gem `abbyy-cloud`.
|
|
17
17
|
Initialize the client with a corresponding credentials:
|
18
18
|
|
19
19
|
```ruby
|
20
|
+
require "abbyy/cloud"
|
21
|
+
|
20
22
|
CLIENT = ABBYY::Cloud.new(id: "foo", token: "bar")
|
21
23
|
```
|
22
24
|
|
@@ -31,6 +33,32 @@ CLIENT = ABBYY::Cloud.new id: "foo",
|
|
31
33
|
version: 0 # the only supported version
|
32
34
|
```
|
33
35
|
|
36
|
+
### Machine Translations
|
37
|
+
|
38
|
+
#### Engines
|
39
|
+
|
40
|
+
See [the specification](https://api.abbyy.cloud/swagger/ui/index#!/MachineTranslation)
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
result = CLIENT.mt.engines
|
44
|
+
# => [#<ABBYY::Cloud::Models::Engine @name="Sandbox">]
|
45
|
+
```
|
46
|
+
|
47
|
+
#### Engine
|
48
|
+
|
49
|
+
This operation is built on top of the previous one and simply takes settings for the specified engine:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
result = CLIENT.mt.engine("Sandbox")
|
53
|
+
|
54
|
+
result.class # => ABBYY::Cloud::Models::Engine
|
55
|
+
result.name # => "Sandbox"
|
56
|
+
result.languages # => ["en", "ru"]
|
57
|
+
result.translation_directions # => [#<ABBYY::Cloud::Models::Direction source: "en", target: "ru">]
|
58
|
+
result.to_h
|
59
|
+
# => { name: "Sandbox", languages: ["en", "ru"], translation_directions: [{ source: "en", target: "ru" }] }
|
60
|
+
```
|
61
|
+
|
34
62
|
### Orders
|
35
63
|
|
36
64
|
#### Instant Translation
|
data/abbyy-cloud.gemspec
CHANGED
data/lib/abbyy/cloud.rb
CHANGED
@@ -17,15 +17,23 @@ module ABBYY
|
|
17
17
|
|
18
18
|
require_relative "cloud/models/error"
|
19
19
|
require_relative "cloud/models/translation"
|
20
|
+
require_relative "cloud/models/direction"
|
21
|
+
require_relative "cloud/models/engine"
|
20
22
|
|
21
23
|
require_relative "cloud/operations/base"
|
22
24
|
require_relative "cloud/operations/translate"
|
25
|
+
require_relative "cloud/operations/engines"
|
23
26
|
|
24
27
|
require_relative "cloud/namespaces/base"
|
25
28
|
require_relative "cloud/namespaces/orders"
|
29
|
+
require_relative "cloud/namespaces/machine_translations"
|
26
30
|
|
27
31
|
attr_reader :settings
|
28
32
|
|
33
|
+
def mt
|
34
|
+
Namespaces::MachineTranslations.new(settings)
|
35
|
+
end
|
36
|
+
|
29
37
|
def orders
|
30
38
|
Namespaces::Orders.new(settings)
|
31
39
|
end
|
@@ -14,7 +14,7 @@ class ABBYY::Cloud
|
|
14
14
|
|
15
15
|
def call(http_method, path, body: nil, headers: nil)
|
16
16
|
uri = root.merge(path).tap { |item| item.scheme = "https" }
|
17
|
-
req = prepare_request(http_method, uri, body.to_h, headers.to_h)
|
17
|
+
req = prepare_request(http_method, uri, JSON(body.to_h), headers.to_h)
|
18
18
|
|
19
19
|
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
20
20
|
handle_response http.request(req)
|
@@ -24,7 +24,7 @@ class ABBYY::Cloud
|
|
24
24
|
private
|
25
25
|
|
26
26
|
def root
|
27
|
-
@root ||= URI("https://api.abbyy.cloud").merge("v#{version}")
|
27
|
+
@root ||= URI("https://api.abbyy.cloud").merge("v#{version}/")
|
28
28
|
end
|
29
29
|
|
30
30
|
def prepare_request(http_method, uri, body, headers)
|
@@ -5,7 +5,7 @@ class ABBYY::Cloud
|
|
5
5
|
attr_reader :status, :data
|
6
6
|
|
7
7
|
def initialize(response)
|
8
|
-
@data = Models::Error[
|
8
|
+
@data = Models::Error[parse_response(response)]
|
9
9
|
@status = response.code.to_i
|
10
10
|
|
11
11
|
super <<-MESSAGE.gsub(/ +\|/, "")
|
@@ -15,5 +15,13 @@ class ABBYY::Cloud
|
|
15
15
|
| model_state: #{data.model_state}
|
16
16
|
MESSAGE
|
17
17
|
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def parse_response(response)
|
22
|
+
JSON.parse(response.body)
|
23
|
+
rescue
|
24
|
+
{ error: "Server error", error_description: response.body }
|
25
|
+
end
|
18
26
|
end
|
19
27
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class ABBYY::Cloud
|
2
|
+
module Models
|
3
|
+
# Description of the translation direction
|
4
|
+
class Direction < Struct
|
5
|
+
attribute :source, Types::Language
|
6
|
+
attribute :target, Types::Language
|
7
|
+
end
|
8
|
+
|
9
|
+
# Registers type Types::Direction
|
10
|
+
Types.register_type Direction
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class ABBYY::Cloud
|
2
|
+
# Collection of models returned in requests
|
3
|
+
module Models
|
4
|
+
# Description of the engine
|
5
|
+
class Engine < Struct
|
6
|
+
attribute :name, Types::Strict::String
|
7
|
+
attribute :languages, Types::Array.member(Types::Language)
|
8
|
+
attribute :translation_directions, Types::Array.member(Types::Direction)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Registers type Types::Engine
|
12
|
+
Types.register_type Engine
|
13
|
+
end
|
14
|
+
end
|
@@ -3,9 +3,9 @@ class ABBYY::Cloud
|
|
3
3
|
module Models
|
4
4
|
# An error returned by the server in case of wrong response
|
5
5
|
class Error < Struct
|
6
|
-
attribute :request_id, Types::
|
7
|
-
attribute :error, Types::
|
8
|
-
attribute :error_description, Types::
|
6
|
+
attribute :request_id, Types::Strict::String.optional
|
7
|
+
attribute :error, Types::Strict::String.optional
|
8
|
+
attribute :error_description, Types::Strict::String.optional
|
9
9
|
attribute :model_state, Types::Hash.optional
|
10
10
|
end
|
11
11
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class ABBYY::Cloud
|
2
|
+
module Namespaces
|
3
|
+
# Namespace for operations with machine translations
|
4
|
+
# @see [https://api.abbyy.cloud/swagger/ui/index#!/MachineTranslation]
|
5
|
+
class MachineTranslations < Base
|
6
|
+
# Returns list of all available engines
|
7
|
+
def engines
|
8
|
+
Operations::Engines.new(settings).call
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns settigns for the engine selected by its name
|
12
|
+
def engine(name)
|
13
|
+
engines.find { |engine| engine.name == name }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
class ABBYY::Cloud
|
7
7
|
module Operations
|
8
8
|
class Base
|
9
|
-
#
|
9
|
+
# Helpers to specify concrete operations
|
10
10
|
class << self
|
11
11
|
include Forwardable
|
12
12
|
|
@@ -34,12 +34,13 @@ class ABBYY::Cloud
|
|
34
34
|
private
|
35
35
|
|
36
36
|
def provide_struct(variable, struct, &block)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
value = instance_variable_get(variable)
|
38
|
+
return value if value && struct.nil? && block.nil?
|
39
|
+
|
40
|
+
struct ||= Class.new(Struct)
|
41
|
+
.tap { |obj| obj.instance_eval(&block) if block }
|
42
|
+
|
43
|
+
instance_variable_set(variable, struct)
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class ABBYY::Cloud
|
2
|
+
module Operations
|
3
|
+
class Engines < Base
|
4
|
+
# rubocop: disable Metrics/LineLength
|
5
|
+
link "https://api.abbyy.cloud/swagger/ui/index#!/MachineTranslation/MachineTranslation_Engines"
|
6
|
+
# rubocop: enable Metrics/LineLength
|
7
|
+
path "mt/engines"
|
8
|
+
http_method "get"
|
9
|
+
|
10
|
+
response_body Types::Array.member(Types::Engine)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -6,7 +6,7 @@ class ABBYY::Cloud
|
|
6
6
|
http_method "post"
|
7
7
|
|
8
8
|
request_body do
|
9
|
-
attribute :engine, Types::
|
9
|
+
attribute :engine, Types::Strict::String
|
10
10
|
attribute :source_language, Types::Language
|
11
11
|
attribute :target_language, Types::Language
|
12
12
|
attribute :source_text, Types::Strict::String
|
data/lib/abbyy/cloud/settings.rb
CHANGED
@@ -6,7 +6,7 @@ class ABBYY::Cloud
|
|
6
6
|
option :id, type: Types::AuthId
|
7
7
|
option :token, type: Types::AuthToken
|
8
8
|
option :version, type: Types::Version, default: proc { 0 }
|
9
|
-
option :engine, type: Types::
|
9
|
+
option :engine, type: Types::Strict::String, default: proc { "Sandbox" }
|
10
10
|
end
|
11
11
|
|
12
12
|
def connection
|
data/lib/abbyy/cloud/struct.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
class ABBYY::Cloud::Struct < Dry::Struct
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
class << self
|
3
|
+
def new(data)
|
4
|
+
default = schema.keys.each_with_object({}) { |key, hash| hash[key] = nil }
|
5
|
+
actual = data.to_hash.each_with_object({}) do |(key, val), hash|
|
6
|
+
hash[key.to_sym] = val
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
+
super default.merge(actual)
|
10
|
+
end
|
11
|
+
alias_method :[], :new
|
9
12
|
end
|
10
13
|
end
|
data/lib/abbyy/cloud/types.rb
CHANGED
@@ -1,15 +1,28 @@
|
|
1
1
|
module ABBYY::Cloud::Types
|
2
2
|
include Dry::Types.module
|
3
3
|
|
4
|
-
ENGINES = %w(Sandbox Bing Google Systran).freeze
|
5
4
|
VERSIONS = [0].freeze
|
6
|
-
LANGUAGE = /\A[
|
5
|
+
LANGUAGE = /\A[A-Za-z]{2,}(-[A-Za-z]+)*\z/
|
7
6
|
|
8
7
|
# Gem-specific primitive types
|
9
8
|
AuthId = Strict::String
|
10
9
|
AuthToken = Strict::String
|
11
|
-
Engine = Coercible::String.constrained(included_in: ENGINES)
|
12
10
|
Language = Strict::String.constrained(format: LANGUAGE)
|
13
11
|
OrderId = Strict::String
|
14
12
|
Version = Coercible::Int.constrained(included_in: VERSIONS)
|
13
|
+
|
14
|
+
# Registers new coercible type from a struct class
|
15
|
+
def self.register_type(struct, as: nil)
|
16
|
+
type_name = as || struct.name.split("::").last.downcase
|
17
|
+
definition = Dry::Types::Definition.new(struct).constructor do |value|
|
18
|
+
case value
|
19
|
+
when nil then nil
|
20
|
+
when struct then value
|
21
|
+
else struct[value]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Dry::Types.register type_name, definition
|
26
|
+
Dry::Types.define_constants self, [type_name]
|
27
|
+
end
|
15
28
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
RSpec.describe ABBYY::Cloud::Models::Direction do
|
2
|
+
let(:data) { { source: "en-Br", target: "ru" } }
|
3
|
+
|
4
|
+
subject { described_class.new(data) }
|
5
|
+
|
6
|
+
it { is_expected.to be_kind_of ABBYY::Cloud::Struct }
|
7
|
+
its(:to_h) { is_expected.to eq data }
|
8
|
+
|
9
|
+
context "with invalid source:" do
|
10
|
+
before { data[:source] = "2" }
|
11
|
+
|
12
|
+
it "fails" do
|
13
|
+
expect { subject }.to raise_error(StandardError)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "without source:" do
|
18
|
+
before { data.delete :source }
|
19
|
+
|
20
|
+
it "fails" do
|
21
|
+
expect { subject }.to raise_error(StandardError)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "with invalid target:" do
|
26
|
+
before { data[:target] = "r" }
|
27
|
+
|
28
|
+
it "fails" do
|
29
|
+
expect { subject }.to raise_error(StandardError)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "without target:" do
|
34
|
+
before { data.delete :target }
|
35
|
+
|
36
|
+
it "fails" do
|
37
|
+
expect { subject }.to raise_error(StandardError)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
RSpec.describe ABBYY::Cloud::Models::Engine do
|
2
|
+
let(:data) do
|
3
|
+
{
|
4
|
+
name: "Bing",
|
5
|
+
languages: %w(ru en),
|
6
|
+
translation_directions: [{ source: "ru", target: "en" }]
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
10
|
+
subject { described_class.new(data) }
|
11
|
+
|
12
|
+
it { is_expected.to be_kind_of ABBYY::Cloud::Struct }
|
13
|
+
its(:to_h) { is_expected.to eq data }
|
14
|
+
|
15
|
+
context "without name:" do
|
16
|
+
before { data.delete :name }
|
17
|
+
|
18
|
+
it "fails" do
|
19
|
+
expect { subject }.to raise_error(StandardError)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "with invalid languages:" do
|
24
|
+
before { data[:languages] = "wrong" }
|
25
|
+
|
26
|
+
it "fails" do
|
27
|
+
expect { subject }.to raise_error(StandardError)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "with invalid language:" do
|
32
|
+
before { data[:languages] = %w(en r) }
|
33
|
+
|
34
|
+
it "fails" do
|
35
|
+
expect { subject }.to raise_error(StandardError)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "without languages:" do
|
40
|
+
before { data.delete :languages }
|
41
|
+
|
42
|
+
it "fails" do
|
43
|
+
expect { subject }.to raise_error(StandardError)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "with invalid translation_directions:" do
|
48
|
+
before { data[:translation_directions] = "wrong" }
|
49
|
+
|
50
|
+
it "fails" do
|
51
|
+
expect { subject }.to raise_error(StandardError)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with invalid translation_direction:" do
|
56
|
+
before { data[:translation_directions] = [{ source: "r", target: "en" }] }
|
57
|
+
|
58
|
+
it "fails" do
|
59
|
+
expect { subject }.to raise_error(StandardError)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "without translation_direction:" do
|
64
|
+
before { data.delete :translation_directions }
|
65
|
+
|
66
|
+
it "fails" do
|
67
|
+
expect { subject }.to raise_error(StandardError)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
RSpec.describe ABBYY::Cloud::Models::Error do
|
2
|
+
let(:data) do
|
3
|
+
{
|
4
|
+
request_id: "foo",
|
5
|
+
error: "bar",
|
6
|
+
error_description: "baz",
|
7
|
+
model_state: {
|
8
|
+
id: 1,
|
9
|
+
value: "qux"
|
10
|
+
}
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { described_class.new(data) }
|
15
|
+
|
16
|
+
it { is_expected.to be_kind_of ABBYY::Cloud::Struct }
|
17
|
+
its(:to_h) { is_expected.to eq data }
|
18
|
+
|
19
|
+
context "without params" do
|
20
|
+
let(:data) { {} }
|
21
|
+
it { is_expected.to be_kind_of ABBYY::Cloud::Struct }
|
22
|
+
end
|
23
|
+
|
24
|
+
context "with invalid request_id:" do
|
25
|
+
before { data[:request_id] = 1 }
|
26
|
+
|
27
|
+
it "fails" do
|
28
|
+
expect { subject }.to raise_error(StandardError)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "with invalid error:" do
|
33
|
+
before { data[:error] = 1 }
|
34
|
+
|
35
|
+
it "fails" do
|
36
|
+
expect { subject }.to raise_error(StandardError)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "with invalid error_description:" do
|
41
|
+
before { data[:error_description] = 1 }
|
42
|
+
|
43
|
+
it "fails" do
|
44
|
+
expect { subject }.to raise_error(StandardError)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "with invalid model_state:" do
|
49
|
+
before { data[:model_state] = 1 }
|
50
|
+
|
51
|
+
it "fails" do
|
52
|
+
expect { subject }.to raise_error(StandardError)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
RSpec.describe ABBYY::Cloud::Models::Translation do
|
2
|
+
let(:data) { { id: "foo", translation: "bar" } }
|
3
|
+
|
4
|
+
subject { described_class.new(data) }
|
5
|
+
|
6
|
+
it { is_expected.to be_kind_of ABBYY::Cloud::Struct }
|
7
|
+
its(:to_h) { is_expected.to eq data }
|
8
|
+
|
9
|
+
context "with invalid id:" do
|
10
|
+
before { data[:id] = 1 }
|
11
|
+
|
12
|
+
it "fails" do
|
13
|
+
expect { subject }.to raise_error(StandardError)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "without id:" do
|
18
|
+
before { data.delete :id }
|
19
|
+
|
20
|
+
it "fails" do
|
21
|
+
expect { subject }.to raise_error(StandardError)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "with invalid translation:" do
|
26
|
+
before { data[:translation] = 1 }
|
27
|
+
|
28
|
+
it "fails" do
|
29
|
+
expect { subject }.to raise_error(StandardError)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "without translation:" do
|
34
|
+
before { data.delete :translation }
|
35
|
+
|
36
|
+
it "fails" do
|
37
|
+
expect { subject }.to raise_error(StandardError)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
RSpec.describe ABBYY::Cloud::ResponseError do
|
2
|
+
let(:body) { JSON(data) }
|
2
3
|
let(:data) do
|
3
4
|
{
|
4
5
|
request_id: "foobar",
|
@@ -9,7 +10,7 @@ RSpec.describe ABBYY::Cloud::ResponseError do
|
|
9
10
|
end
|
10
11
|
|
11
12
|
let(:response) do
|
12
|
-
instance_double "Net::HTTPResponse", code: "400", body:
|
13
|
+
instance_double "Net::HTTPResponse", code: "400", body: body
|
13
14
|
end
|
14
15
|
|
15
16
|
subject { described_class.new response }
|
@@ -17,4 +18,11 @@ RSpec.describe ABBYY::Cloud::ResponseError do
|
|
17
18
|
it { is_expected.to be_kind_of StandardError }
|
18
19
|
its(:status) { is_expected.to eq 400 }
|
19
20
|
its("data.to_h") { is_expected.to eq data }
|
21
|
+
|
22
|
+
context "when server returned non-json body:" do
|
23
|
+
let(:body) { "Something went wrong" }
|
24
|
+
|
25
|
+
its("data.error") { is_expected.to eq "Server error" }
|
26
|
+
its("data.error_description") { is_expected.to eq "Something went wrong" }
|
27
|
+
end
|
20
28
|
end
|
@@ -5,14 +5,6 @@ RSpec.describe ABBYY::Cloud::Settings do
|
|
5
5
|
describe ".new" do
|
6
6
|
subject { settings }
|
7
7
|
|
8
|
-
context "with wrong engine" do
|
9
|
-
before { options[:engine] = "Wrong" }
|
10
|
-
|
11
|
-
it "fails" do
|
12
|
-
expect { subject }.to raise_error(StandardError)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
8
|
context "without id" do
|
17
9
|
before { options.delete :id }
|
18
10
|
|
@@ -0,0 +1,57 @@
|
|
1
|
+
RSpec.describe "mt.engines" do
|
2
|
+
let(:client) { ABBYY::Cloud.new settings }
|
3
|
+
let(:settings) { { id: "foo", token: "bar" } }
|
4
|
+
let(:path) { "https://api.abbyy.cloud/v0/mt/engines" }
|
5
|
+
let(:response_models) do
|
6
|
+
[
|
7
|
+
{
|
8
|
+
name: "Bing",
|
9
|
+
languages: %w(ru en),
|
10
|
+
translation_directions: [{ source: "ru", target: "en" }]
|
11
|
+
}
|
12
|
+
]
|
13
|
+
end
|
14
|
+
|
15
|
+
before do
|
16
|
+
stub_request(:get, path)
|
17
|
+
.with(basic_auth: %w(foo bar))
|
18
|
+
.to_return status: 200,
|
19
|
+
headers: { "Content-Type" => "application/json" },
|
20
|
+
body: JSON(response_models)
|
21
|
+
end
|
22
|
+
|
23
|
+
subject { client.mt.engines }
|
24
|
+
|
25
|
+
it "sends a request to ABBYY Cloud API" do
|
26
|
+
subject
|
27
|
+
expect(a_request(:get, path)).to have_been_made
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns list of engines" do
|
31
|
+
expect(subject).to be_kind_of Array
|
32
|
+
expect(subject.map(&:class)).to eq [ABBYY::Cloud::Models::Engine]
|
33
|
+
expect(subject.map(&:to_h)).to eq response_models
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when API responded with error:" do
|
37
|
+
before do
|
38
|
+
stub_request(:get, path)
|
39
|
+
.with(basic_auth: %w(foo bar))
|
40
|
+
.to_return status: 500,
|
41
|
+
headers: { "Content-Type" => "application/json" },
|
42
|
+
body: "Server error"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "raises ResponseError" do
|
46
|
+
expect { subject }.to raise_error(ABBYY::Cloud::ResponseError)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when API returned invalid engine:" do
|
51
|
+
let(:response_models) { [{ name: "Wrong" }] }
|
52
|
+
|
53
|
+
it "raises TypeError" do
|
54
|
+
expect { subject }.to raise_error(ABBYY::Cloud::TypeError)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -4,9 +4,9 @@ RSpec.describe "orders.translate" do
|
|
4
4
|
let(:default_engine) { "Google" }
|
5
5
|
let(:custom_engine) { "Bing" }
|
6
6
|
let(:source_language) { "ru" }
|
7
|
-
let(:target_language) { "
|
7
|
+
let(:target_language) { "en" }
|
8
8
|
let(:source_text) { "Бить или не бить" }
|
9
|
-
let(:path) { "https://api.abbyy.cloud/order/mt/sync" }
|
9
|
+
let(:path) { "https://api.abbyy.cloud/v0/order/mt/sync" }
|
10
10
|
let(:response_status) { 200 }
|
11
11
|
let(:response_model) { { id: "42", translation: "To beat or not to beat" } }
|
12
12
|
let(:params) do
|
@@ -38,7 +38,7 @@ RSpec.describe "orders.translate" do
|
|
38
38
|
|
39
39
|
let(:expected_request) do
|
40
40
|
a_request(:post, path).with do |req|
|
41
|
-
expect(req.body).to include engine
|
41
|
+
expect(JSON.parse(req.body)).to include "engine" => "Google"
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -54,7 +54,7 @@ RSpec.describe "orders.translate" do
|
|
54
54
|
|
55
55
|
let(:expected_request) do
|
56
56
|
a_request(:post, path).with do |req|
|
57
|
-
expect(req.body).to include engine
|
57
|
+
expect(JSON.parse(req.body)).to include "engine" => "Sandbox"
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -74,7 +74,7 @@ RSpec.describe "orders.translate" do
|
|
74
74
|
end
|
75
75
|
|
76
76
|
context "with invalid source language:" do
|
77
|
-
let(:source_language) { "
|
77
|
+
let(:source_language) { "1" }
|
78
78
|
|
79
79
|
it "raises ArgumentError before sending a request" do
|
80
80
|
expect { subject }.to raise_error(ABBYY::Cloud::ArgumentError)
|
@@ -92,7 +92,7 @@ RSpec.describe "orders.translate" do
|
|
92
92
|
end
|
93
93
|
|
94
94
|
context "with invalid target language:" do
|
95
|
-
let(:target_language) { "
|
95
|
+
let(:target_language) { "1" }
|
96
96
|
|
97
97
|
it "raises ArgumentError before sending a request" do
|
98
98
|
expect { subject }.to raise_error(ABBYY::Cloud::ArgumentError)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abbyy-cloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kozin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-initializer
|
@@ -146,19 +146,28 @@ files:
|
|
146
146
|
- lib/abbyy/cloud/exceptions/argument_error.rb
|
147
147
|
- lib/abbyy/cloud/exceptions/response_error.rb
|
148
148
|
- lib/abbyy/cloud/exceptions/type_error.rb
|
149
|
+
- lib/abbyy/cloud/models/direction.rb
|
150
|
+
- lib/abbyy/cloud/models/engine.rb
|
149
151
|
- lib/abbyy/cloud/models/error.rb
|
150
152
|
- lib/abbyy/cloud/models/translation.rb
|
151
153
|
- lib/abbyy/cloud/namespaces/base.rb
|
154
|
+
- lib/abbyy/cloud/namespaces/machine_translations.rb
|
152
155
|
- lib/abbyy/cloud/namespaces/orders.rb
|
153
156
|
- lib/abbyy/cloud/operations/base.rb
|
157
|
+
- lib/abbyy/cloud/operations/engines.rb
|
154
158
|
- lib/abbyy/cloud/operations/translate.rb
|
155
159
|
- lib/abbyy/cloud/settings.rb
|
156
160
|
- lib/abbyy/cloud/struct.rb
|
157
161
|
- lib/abbyy/cloud/types.rb
|
158
162
|
- spec/abbyy/cloud/connection_spec.rb
|
163
|
+
- spec/abbyy/cloud/models/direction_spec.rb
|
164
|
+
- spec/abbyy/cloud/models/engine_spec.rb
|
165
|
+
- spec/abbyy/cloud/models/error_spec.rb
|
166
|
+
- spec/abbyy/cloud/models/translation_spec.rb
|
159
167
|
- spec/abbyy/cloud/response_error_spec.rb
|
160
168
|
- spec/abbyy/cloud/settings_spec.rb
|
161
169
|
- spec/abbyy/cloud_spec.rb
|
170
|
+
- spec/feature/abbyy/mt_engines_spec.rb
|
162
171
|
- spec/feature/abbyy/order_translate_spec.rb
|
163
172
|
- spec/spec_helper.rb
|
164
173
|
homepage: https://github.com/nepalez/abbyy-cloud
|
@@ -187,8 +196,13 @@ specification_version: 4
|
|
187
196
|
summary: HTTP client to ABBYY Cloud API
|
188
197
|
test_files:
|
189
198
|
- spec/abbyy/cloud/connection_spec.rb
|
199
|
+
- spec/abbyy/cloud/models/direction_spec.rb
|
200
|
+
- spec/abbyy/cloud/models/engine_spec.rb
|
201
|
+
- spec/abbyy/cloud/models/error_spec.rb
|
202
|
+
- spec/abbyy/cloud/models/translation_spec.rb
|
190
203
|
- spec/abbyy/cloud/response_error_spec.rb
|
191
204
|
- spec/abbyy/cloud/settings_spec.rb
|
192
205
|
- spec/abbyy/cloud_spec.rb
|
206
|
+
- spec/feature/abbyy/mt_engines_spec.rb
|
193
207
|
- spec/feature/abbyy/order_translate_spec.rb
|
194
208
|
- spec/spec_helper.rb
|