abbyy-cloud 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +7 -13
  3. data/.travis.yml +1 -1
  4. data/CHANGELOG.md +11 -0
  5. data/README.md +29 -0
  6. data/abbyy-cloud.gemspec +4 -2
  7. data/lib/abbyy/cloud.rb +14 -26
  8. data/lib/abbyy/cloud/connection.rb +3 -10
  9. data/lib/abbyy/cloud/exceptions/response_error.rb +1 -1
  10. data/lib/abbyy/cloud/models/cost_type.rb +14 -0
  11. data/lib/abbyy/cloud/models/currency.rb +14 -0
  12. data/lib/abbyy/cloud/models/direction.rb +0 -1
  13. data/lib/abbyy/cloud/models/discount.rb +2 -1
  14. data/lib/abbyy/cloud/models/discount_type.rb +19 -0
  15. data/lib/abbyy/cloud/models/engine.rb +0 -2
  16. data/lib/abbyy/cloud/models/error.rb +0 -1
  17. data/lib/abbyy/cloud/models/file_format.rb +19 -0
  18. data/lib/abbyy/cloud/models/file_info.rb +33 -0
  19. data/lib/abbyy/cloud/models/file_link.rb +18 -0
  20. data/lib/abbyy/cloud/models/file_read_error.rb +20 -0
  21. data/lib/abbyy/cloud/models/file_read_status.rb +14 -0
  22. data/lib/abbyy/cloud/models/file_reference.rb +11 -0
  23. data/lib/abbyy/cloud/models/full_order.rb +46 -0
  24. data/lib/abbyy/cloud/models/label.rb +14 -0
  25. data/lib/abbyy/cloud/models/ocr_mode.rb +19 -0
  26. data/lib/abbyy/cloud/models/ocr_quality.rb +18 -0
  27. data/lib/abbyy/cloud/models/ocr_settings.rb +16 -0
  28. data/lib/abbyy/cloud/models/ocr_statistics.rb +13 -0
  29. data/lib/abbyy/cloud/models/ocr_warning.rb +16 -0
  30. data/lib/abbyy/cloud/models/ocr_warning_type.rb +29 -0
  31. data/lib/abbyy/cloud/models/order_statistics.rb +15 -0
  32. data/lib/abbyy/cloud/models/payment_type.rb +14 -0
  33. data/lib/abbyy/cloud/models/price.rb +1 -1
  34. data/lib/abbyy/cloud/models/reading_status.rb +20 -0
  35. data/lib/abbyy/cloud/models/source_segment.rb +0 -1
  36. data/lib/abbyy/cloud/models/source_tag.rb +0 -1
  37. data/lib/abbyy/cloud/models/status.rb +25 -0
  38. data/lib/abbyy/cloud/models/text_statistics.rb +15 -0
  39. data/lib/abbyy/cloud/models/transfer_data.rb +0 -3
  40. data/lib/abbyy/cloud/models/translation.rb +0 -2
  41. data/lib/abbyy/cloud/models/translation_link.rb +18 -0
  42. data/lib/abbyy/cloud/models/translation_segment.rb +0 -1
  43. data/lib/abbyy/cloud/models/translation_type.rb +14 -0
  44. data/lib/abbyy/cloud/models/unit_price.rb +3 -0
  45. data/lib/abbyy/cloud/models/unit_type.rb +14 -0
  46. data/lib/abbyy/cloud/namespaces/files.rb +19 -0
  47. data/lib/abbyy/cloud/namespaces/orders.rb +17 -0
  48. data/lib/abbyy/cloud/namespaces/prices.rb +1 -1
  49. data/lib/abbyy/cloud/operations/base.rb +56 -19
  50. data/lib/abbyy/cloud/operations/download_file.rb +12 -0
  51. data/lib/abbyy/cloud/operations/engines.rb +1 -1
  52. data/lib/abbyy/cloud/operations/find_order.rb +13 -0
  53. data/lib/abbyy/cloud/operations/prices.rb +1 -1
  54. data/lib/abbyy/cloud/operations/submit_order.rb +32 -0
  55. data/lib/abbyy/cloud/operations/translate.rb +1 -1
  56. data/lib/abbyy/cloud/operations/translate_segments.rb +1 -1
  57. data/lib/abbyy/cloud/operations/upload_file.rb +22 -0
  58. data/lib/abbyy/cloud/types.rb +8 -17
  59. data/spec/feature/abbyy/files_download_spec.rb +57 -0
  60. data/spec/feature/abbyy/files_upload_spec.rb +129 -0
  61. data/spec/feature/abbyy/orders_create_spec.rb +245 -0
  62. data/spec/feature/abbyy/orders_find_spec.rb +116 -0
  63. data/spec/{abbyy → unit/abbyy}/cloud/connection_spec.rb +1 -1
  64. data/spec/{abbyy → unit/abbyy}/cloud/models/direction_spec.rb +0 -0
  65. data/spec/{abbyy → unit/abbyy}/cloud/models/discount_spec.rb +0 -0
  66. data/spec/{abbyy → unit/abbyy}/cloud/models/engine_spec.rb +0 -0
  67. data/spec/{abbyy → unit/abbyy}/cloud/models/error_spec.rb +0 -0
  68. data/spec/unit/abbyy/cloud/models/file_link_spec.rb +51 -0
  69. data/spec/unit/abbyy/cloud/models/file_reference_spec.rb +24 -0
  70. data/spec/unit/abbyy/cloud/models/full_order_spec.rb +192 -0
  71. data/spec/{abbyy → unit/abbyy}/cloud/models/locale_spec.rb +0 -0
  72. data/spec/unit/abbyy/cloud/models/order_statistics_spec.rb +15 -0
  73. data/spec/{abbyy → unit/abbyy}/cloud/models/price_spec.rb +0 -8
  74. data/spec/{abbyy → unit/abbyy}/cloud/models/source_segment_spec.rb +0 -0
  75. data/spec/{abbyy → unit/abbyy}/cloud/models/source_tag_spec.rb +0 -0
  76. data/spec/{abbyy → unit/abbyy}/cloud/models/transfer_data_spec.rb +0 -0
  77. data/spec/unit/abbyy/cloud/models/translation_link_spec.rb +66 -0
  78. data/spec/{abbyy → unit/abbyy}/cloud/models/translation_segment_spec.rb +0 -0
  79. data/spec/{abbyy → unit/abbyy}/cloud/models/translation_spec.rb +0 -0
  80. data/spec/{abbyy → unit/abbyy}/cloud/models/unit_price_spec.rb +0 -0
  81. data/spec/{abbyy → unit/abbyy}/cloud/response_error_spec.rb +0 -0
  82. data/spec/{abbyy → unit/abbyy}/cloud/settings_spec.rb +0 -0
  83. data/spec/{abbyy → unit/abbyy}/cloud_spec.rb +0 -0
  84. metadata +114 -37
@@ -0,0 +1,11 @@
1
+ class ABBYY::Cloud
2
+ module Models
3
+ class FileReference < Struct
4
+ attribute :id, Types::Strict::String
5
+ attribute :token, Types::Strict::String
6
+ end
7
+
8
+ # Registers type Types::FileReference
9
+ Types.register_type FileReference
10
+ end
11
+ end
@@ -0,0 +1,46 @@
1
+ require_relative "currency"
2
+ require_relative "order_statistics"
3
+ require_relative "label"
4
+ require_relative "locale"
5
+ require_relative "payment_type"
6
+ require_relative "status"
7
+ require_relative "translation_link"
8
+ require_relative "translation_type"
9
+ require_relative "unit_type"
10
+
11
+ class ABBYY::Cloud
12
+ module Models
13
+ class FullOrder < Struct
14
+ attribute :amount, Types::Coercible::Float
15
+ attribute :approval_required, Types::Form::Bool
16
+ attribute :created, Types::Form::Time
17
+ attribute :currency, Types::Currency
18
+ attribute :deadline, Types::Form::Time.optional
19
+ attribute :deleted, Types::Form::Time.optional
20
+ attribute :delivered, Types::Form::Time.optional
21
+ attribute :email, Types::Strict::String
22
+ attribute :from, Types::Locale
23
+ attribute :id, Types::Strict::String
24
+ attribute :is_deleted, Types::Form::Bool
25
+ attribute :is_layout_required, Types::Form::Bool
26
+ attribute :is_manual_estimation, Types::Form::Bool
27
+ attribute :label, Types::Label.optional
28
+ attribute :number, Types::Coercible::Int
29
+ attribute :payment_provider, Types::Strict::String
30
+ attribute :payment_type, Types::PaymentType
31
+ attribute :progress, Types::Coercible::Int
32
+ attribute :started, Types::Form::Time.optional
33
+ attribute :statistics, Types::OrderStatistics
34
+ attribute :status, Types::Status
35
+ attribute :to, Types::FilledArray.member(Types::Locale)
36
+ attribute :translations, Types::Array.member(Types::TranslationLink)
37
+ attribute :type, Types::TranslationType
38
+ attribute :unit_count, Types::Coercible::Int
39
+ attribute :unit_type, Types::UnitType
40
+ attribute :units_count, Types::Hash
41
+ end
42
+
43
+ # Registers type Types::FullOrder
44
+ Types.register_type FullOrder
45
+ end
46
+ end
@@ -0,0 +1,14 @@
1
+ class ABBYY::Cloud
2
+ module Models
3
+ class Label < ::String
4
+ FORMAT = /\A.{1,80}\z/
5
+
6
+ def self.new(string)
7
+ super Types::Strict::String.constrained(format: FORMAT)[string]
8
+ end
9
+ end
10
+
11
+ # Registers type Types::Label
12
+ Types.register_type Label
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ class ABBYY::Cloud
2
+ module Models
3
+ class OcrMode < ::String
4
+ VALUES = %w(
5
+ EditableCopy
6
+ ExactCopy
7
+ FormattedText
8
+ PlainText
9
+ ).freeze
10
+
11
+ def self.new(string)
12
+ super Types::Strict::String.constrained(included_in: VALUES)[string]
13
+ end
14
+ end
15
+
16
+ # Registers type Types::OcrMode
17
+ Types.register_type OcrMode
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ class ABBYY::Cloud
2
+ module Models
3
+ class OcrQuality < ::String
4
+ VALUES = %w(
5
+ Fast
6
+ Balanced
7
+ Thorough
8
+ ).freeze
9
+
10
+ def self.new(string)
11
+ super Types::Strict::String.constrained(included_in: VALUES)[string]
12
+ end
13
+ end
14
+
15
+ # Registers type Types::OcrQuality
16
+ Types.register_type OcrQuality
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ require_relative "file_format"
2
+ require_relative "ocr_mode"
3
+ require_relative "ocr_quality"
4
+
5
+ class ABBYY::Cloud
6
+ module Models
7
+ class OcrSettings < Struct
8
+ attribute :format, Types::FileFormat
9
+ attribute :mode, Types::OcrMode
10
+ attribute :quality, Types::OcrQuality
11
+ end
12
+
13
+ # Registers type Types::OcrSettings
14
+ Types.register_type OcrSettings
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ class ABBYY::Cloud
2
+ module Models
3
+ class OcrStatistics < Struct
4
+ attribute :exported_pages, Types::Coercible::Int
5
+ attribute :total_characters, Types::Coercible::Int
6
+ attribute :uncertain_characters, Types::Coercible::Int
7
+ attribute :success_part, Types::Coercible::Float
8
+ end
9
+
10
+ # Registers type Types::OcrStatistics
11
+ Types.register_type OcrStatistics
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ require_relative "ocr_warning_type"
2
+
3
+ class ABBYY::Cloud
4
+ module Models
5
+ class OcrWarning < Struct
6
+ attribute :warning_type, Types::OcrWarningType
7
+ attribute :page_number, Types::Coercible::Int
8
+ attribute :dpi, Types::Coercible::Int.optional
9
+ attribute :language_count, Types::Coercible::Int.optional
10
+ attribute :full_warning_message, Types::Strict::String.optional
11
+ end
12
+
13
+ # Registers type Types::OcrWarning
14
+ Types.register_type OcrWarning
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+ class ABBYY::Cloud
2
+ module Models
3
+ class OcrWarningType < ::String
4
+ VALUES = %w(
5
+ BrightnessIsTooHigh
6
+ BrightnessIsTooLow
7
+ ErrorWhenUsingDocumentAuxData
8
+ NoRecognizableBlocksFound
9
+ ProbablyLanguageIsIncorrect
10
+ ResolutionIsLowForTinyTextPhoto
11
+ ResolutionIsLowForTinyTextScanned
12
+ ResolutionIsTooHigh
13
+ ResolutionIsTooLow
14
+ SuspiciousResolution
15
+ TooManyBaseLanguages
16
+ TooManyBaseLanguagesForDetection
17
+ TooManyLanguagesDetected
18
+ UnknownWarning
19
+ ).freeze
20
+
21
+ def self.new(string)
22
+ super Types::Strict::String.constrained(included_in: VALUES)[string]
23
+ end
24
+ end
25
+
26
+ # Registers type Types::OcrWarningType
27
+ Types.register_type OcrWarningType
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ require_relative "source_tag"
2
+
3
+ class ABBYY::Cloud
4
+ module Models
5
+ class OrderStatistics < Struct
6
+ attribute :documents_count, Types::Coercible::Int
7
+ attribute :pages_count, Types::Coercible::Int
8
+ attribute :words_count, Types::Coercible::Int
9
+ attribute :chars_count, Types::Coercible::Int
10
+ end
11
+
12
+ # Registers type Types::OrderStatistics
13
+ Types.register_type OrderStatistics
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ class ABBYY::Cloud
2
+ module Models
3
+ class PaymentType < ::String
4
+ VALUES = %w(Manual Balance External).freeze
5
+
6
+ def self.new(string)
7
+ super Types::Strict::String.constrained(included_in: VALUES)[string]
8
+ end
9
+ end
10
+
11
+ # Registers type Types::PaymentType
12
+ Types.register_type PaymentType
13
+ end
14
+ end
@@ -7,7 +7,7 @@ class ABBYY::Cloud
7
7
  # Price details
8
8
  class Price < Struct
9
9
  attribute :id, Types::Strict::String
10
- attribute :account_id, Types::Strict::String
10
+ attribute :account_id, Types::Strict::String.optional
11
11
  attribute :type, Types::Strict::String
12
12
  attribute :from, Types::Locale
13
13
  attribute :to, Types::Locale
@@ -0,0 +1,20 @@
1
+ class ABBYY::Cloud
2
+ module Models
3
+ class ReadingStatus < ::String
4
+ VALUES = %w(
5
+ New
6
+ Submitted
7
+ InProgress
8
+ Done
9
+ Error
10
+ ).freeze
11
+
12
+ def self.new(string)
13
+ super Types::Strict::String.constrained(included_in: VALUES)[string]
14
+ end
15
+ end
16
+
17
+ # Registers type Types::ReadingStatus
18
+ Types.register_type ReadingStatus
19
+ end
20
+ end
@@ -2,7 +2,6 @@ require_relative "source_tag"
2
2
 
3
3
  class ABBYY::Cloud
4
4
  module Models
5
- # A segment for the translation
6
5
  class SourceSegment < Struct
7
6
  attribute :text, Types::Strict::String
8
7
  attribute :tags, Types::Array.member(Types::SourceTag).default([])
@@ -2,7 +2,6 @@ class ABBYY::Cloud
2
2
  module Models
3
3
  TYPES = %w(Start End Placeholder).freeze
4
4
 
5
- # Tag for translation source/target
6
5
  class SourceTag < Struct
7
6
  attribute :number, Types::Strict::Int
8
7
  attribute :position, Types::Strict::Int
@@ -0,0 +1,25 @@
1
+ class ABBYY::Cloud
2
+ module Models
3
+ class Status < ::String
4
+ VALUES = %w(
5
+ New
6
+ Submitted
7
+ PaymentRequired
8
+ Paid
9
+ InProgress
10
+ Done
11
+ Failed
12
+ Accepted
13
+ ReworkRequired
14
+ Canceled
15
+ ).freeze
16
+
17
+ def self.new(string)
18
+ super Types::Strict::String.constrained(included_in: VALUES)[string]
19
+ end
20
+ end
21
+
22
+ # Registers type Types::Status
23
+ Types.register_type Status
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ require_relative "source_tag"
2
+
3
+ class ABBYY::Cloud
4
+ module Models
5
+ class TextStatistics < Struct
6
+ attribute :language, Types::Locale
7
+ attribute :pages_count, Types::Coercible::Int
8
+ attribute :words_count, Types::Coercible::Int
9
+ attribute :chars_count, Types::Coercible::Int
10
+ end
11
+
12
+ # Registers type Types::TextStatistics
13
+ Types.register_type TextStatistics
14
+ end
15
+ end
@@ -1,8 +1,5 @@
1
1
  class ABBYY::Cloud
2
2
  module Models
3
- TYPES = %w(Start End Placeholder).freeze
4
-
5
- # Tag for translation source/target
6
3
  class TransferData < Struct
7
4
  attribute :position, Types::Strict::Int
8
5
  attribute :order, Types::Strict::Int
@@ -1,7 +1,5 @@
1
1
  class ABBYY::Cloud
2
- # Collection of models returned in requests
3
2
  module Models
4
- # Result of the order translation
5
3
  class Translation < Struct
6
4
  attribute :id, Types::Strict::String
7
5
  attribute :translation, Types::Strict::String
@@ -0,0 +1,18 @@
1
+ require_relative "status"
2
+ require_relative "file_link"
3
+
4
+ class ABBYY::Cloud
5
+ module Models
6
+ class TranslationLink < Struct
7
+ attribute :delivered, Types::Form::Time
8
+ attribute :started, Types::Form::Time
9
+ attribute :progress, Types::Coercible::Int
10
+ attribute :status, Types::Status
11
+ attribute :source_file, Types::FileLink
12
+ attribute :target_file, Types::FileLink
13
+ end
14
+
15
+ # Registers type Types::TranslationLink
16
+ Types.register_type TranslationLink
17
+ end
18
+ end
@@ -2,7 +2,6 @@ require_relative "transfer_data"
2
2
 
3
3
  class ABBYY::Cloud
4
4
  module Models
5
- # A segment of the translation
6
5
  class TranslationSegment < Struct
7
6
  attribute :id, Types::Strict::String
8
7
  attribute :text, Types::Strict::String
@@ -0,0 +1,14 @@
1
+ class ABBYY::Cloud
2
+ module Models
3
+ class TranslationType < ::String
4
+ VALUES = %w(mt ht_express ht_professional ht_expert).freeze
5
+
6
+ def self.new(string)
7
+ super Types::Strict::String.constrained(included_in: VALUES)[string]
8
+ end
9
+ end
10
+
11
+ # Registers type Types::TranslationType
12
+ Types.register_type TranslationType
13
+ end
14
+ end
@@ -1,3 +1,6 @@
1
+ require_relative "currency"
2
+ require_relative "unit_type"
3
+
1
4
  class ABBYY::Cloud
2
5
  module Models
3
6
  # Price details
@@ -0,0 +1,14 @@
1
+ class ABBYY::Cloud
2
+ module Models
3
+ class UnitType < ::String
4
+ VALUES = %w(Chars Words Pages Documents).freeze
5
+
6
+ def self.new(string)
7
+ super Types::Strict::String.constrained(included_in: VALUES)[string]
8
+ end
9
+ end
10
+
11
+ # Registers type Types::UnitType
12
+ Types.register_type UnitType
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ require_relative "base"
2
+
3
+ class ABBYY::Cloud
4
+ module Namespaces
5
+ # Namespace for operations with orders
6
+ # @see [https://api.abbyy.cloud/swagger/ui/index#!/File] ABBYY Cloud API
7
+ class Files < Base
8
+ def upload(file, export_format: nil, synthesis_mode: nil, **options)
9
+ options[:exportFormat] = export_format if export_format
10
+ options[:synthesisMode] = synthesis_mode if synthesis_mode
11
+ Operations::UploadFile.new(settings).call(file, **options)
12
+ end
13
+
14
+ def download(id:, token:)
15
+ Operations::DownloadFile.new(settings).call(id: id, token: token)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ require_relative "base"
2
+
3
+ class ABBYY::Cloud
4
+ module Namespaces
5
+ # Namespace for operations with orders
6
+ # @see [https://api.abbyy.cloud/swagger/ui/index#!/Orders] ABBYY Cloud API
7
+ class Orders < Base
8
+ def create(options)
9
+ Operations::SubmitOrder.new(settings).call(options)
10
+ end
11
+
12
+ def find(id)
13
+ Operations::FindOrder.new(settings).call(id: id)
14
+ end
15
+ end
16
+ end
17
+ end