0.0
No commit activity in last 3 years
No release in over 3 years
HTTP client to ABBYY Cloud API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.12
~> 10.0
~> 3.0
~> 1.2
~> 0.42
~> 2.0

Runtime

 Project Readme

[WIP] ABBYY::Cloud

Gem Version Build Status Dependency Status Code Climate Inline docs

JSON HTTP client to the ABBYY Cloud API.

Setup

The library is available as a gem abbyy-cloud.

Usage

Initialize the client with a corresponding credentials:

require "abbyy/cloud"

CLIENT = ABBYY::Cloud.new(id: "foo", token: "bar")

You can set these options explicitly:

CLIENT = ABBYY::Cloud.new id:      "foo",
                          token:   "bar",
                          engine:  "Sandbox" # default engine for translations

And then use the client to provide requests:

res = CLIENT.mt.translate("To be or not to be", from: :en, to: :ru)
res.translation  # => "Быть или не быть"

res = CLIENT.mt.translate_segments ["To be or not to be", "That is the question"], from: "en", to: "ru"
res.map(&:text) # => ["Быть или не быть", "Это вопрос"]

Namespaces and Operations

Machine Translations

The namespace mt contains (synchronous) operations with machine translation.

engines

See the specification

result = CLIENT.mt.engines
# => [#<ABBYY::Cloud::Models::Engine @name="Sandbox">]

engine

This operation is built on top of the previous one and simply takes settings for the specified engine:

result = CLIENT.mt.engine("Sandbox")

result.class                  # => ABBYY::Cloud::Models::Engine
result.name                   # => "Sandbox"
result.languages              # => ["en", "ru"]
result.translation_directions # => [#<ABBYY::Cloud::Models::Direction source: "en", target: "ru">]
result.to_h
# => { name: "Sandbox", languages: ["en", "ru"], translation_directions: [{ source: "en", target: "ru" }] }

default_engine

Returns settings for the engine used in the initializer

CLIENT = ABBYY::Cloud.new(id: "foo", token: "bar", engine: "Bing")

settings_for_bing = CLIENT.mt.default_engine

translate

Translates a string.

See the specification.

result = CLIENT.mt.translate("To be or not to be", from: :en, to: :ru)

result.class       # => ABBYY::Cloud::Models::Translation
result.translation # => "Быть или не быть"
result.id          # => "2832934"
result.to_h        # => { id: "2832934", translation: "Быть или не быть" }

translate_segments

Translates an array of strings in one request

See the specification

result = CLIENT.mt.translate_segments(["To be", "or not to be"], from: :en, to: :ru)

result.class       # => ABBYY::Cloud::Models::TranslationSequence
result.map(&:text) # => ["Быть", "или не быть"]

Files

The namespace files contains operations with files.

upload

Uploads a file

See the specification

file   = File.read("file_to_upload.xml")
result = CLIENT.files.upload file
result.id    # => "18323"
result.token # => "foobarbaz"
#  ...

download

Dowloads a file by id and token

See the specification

result = CLIENT.files.download(id: "foo", token: "bar")
# => #<StringIO ...>

Prices

The namespace prices contains operations with prices details.

details

See the specification.

list = CLIENT.prices.details

list.first.to_h
# {
#   id:          "foo",
#   account_id:  "bar",
#   type:        "qux",
#   from:        "ru",
#   to:          "en",
#   unit_prices: [{ unit_type: "Words", currency: "USD", amount: 0.03 }],
#   discounts:   [{ discount_type: "TMTextMatch", discount: 0.01 }],
#   created:     Time.now
# }

The number of items can be several thousands. You can specify skip and take options to take necessary items only, otherwise it will return all prices.

Notice, though, that every single request can return no more than 1000 items. If you request more prices, several requests will be made one-by-one. Parsing all the results can be pretty slow.

Compatibility

[WIP] Compatible to ABBYY Cloud API v.0.

Tested under rubies compatible to MRI 2.3+ using RSpec 3.0+.

License

The gem is available as open source under the terms of the MIT License.