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,245 @@
1
+ RSpec.describe "orders.create" do
2
+ let(:client) { ABBYY::Cloud.new settings }
3
+ let(:settings) { { id: "foo", token: "bar" } }
4
+ let(:path) { "https://api.abbyy.cloud/v0/order" }
5
+
6
+ let(:request) do
7
+ {
8
+ type: "ht_professional",
9
+ email: "user@example.com",
10
+ contact_culture: "ru",
11
+ contact_utc_offset: "+04:00Z",
12
+ label: "baz",
13
+ mt_engine: "Bing",
14
+ approval_required: true,
15
+ is_manual_estimation: true,
16
+ cost_type: "SomeDiscounts",
17
+ unit_type: "Words",
18
+ currency: "RUB",
19
+ from: "ru",
20
+ to: ["de"],
21
+ files: [{ id: "foo", token: "bar" }]
22
+ }
23
+ end
24
+
25
+ let(:response) do
26
+ {
27
+ translations: [
28
+ {
29
+ source_file: {
30
+ id: "foo",
31
+ token: "bar",
32
+ name: "ru.xml",
33
+ language: "ru",
34
+ chars_count: 107,
35
+ words_count: 32,
36
+ pages_count: 1,
37
+ is_deleted: false
38
+ },
39
+ target_file: {
40
+ id: "rab",
41
+ token: "oof",
42
+ name: "de.xml",
43
+ language: "de",
44
+ chars_count: 87,
45
+ words_count: 22,
46
+ pages_count: 1,
47
+ is_deleted: false
48
+ },
49
+ started: "2016-03-13T10:00:00Z",
50
+ delivered: "2019-03-14T11:00:00Z",
51
+ progress: 10,
52
+ status: "InProgress"
53
+ }
54
+ ],
55
+ id: "qux",
56
+ number: 1924,
57
+ email: "user@example.com",
58
+ type: "ht_professional",
59
+ from: "ru",
60
+ to: ["de"],
61
+ is_layout_required: true,
62
+ label: "baz",
63
+ payment_type: "External",
64
+ unit_type: "Words",
65
+ unit_count: 32,
66
+ units_count: 32,
67
+ currency: "RUB",
68
+ amount: 100.0,
69
+ deadline: "2019-01-23T10:00:00Z",
70
+ payment_provider: "CloudPayments",
71
+ is_manual_estimation: true,
72
+ created: "2019-02-10T12:00:00Z",
73
+ started: "2016-03-13T10:00:00Z",
74
+ delivered: "2019-03-14T11:00:00Z",
75
+ progress: 10,
76
+ status: "InProgress",
77
+ approval_required: true,
78
+ deleted: nil,
79
+ is_deleted: false,
80
+ statistics: {
81
+ documents_count: 1,
82
+ pages_count: 1,
83
+ words_count: 32,
84
+ chars_count: 103
85
+ }
86
+ }
87
+ end
88
+
89
+ before do
90
+ stub_request(:post, path)
91
+ .with(basic_auth: %w(foo bar))
92
+ .to_return status: 200,
93
+ headers: { "Content-Type" => "application/json" },
94
+ body: JSON(response)
95
+ end
96
+
97
+ subject { client.orders.create request }
98
+
99
+ context "with valid params" do
100
+ it "sends a request to ABBYY Cloud API" do
101
+ subject
102
+ expect(a_request(:post, path)).to have_been_made
103
+ end
104
+
105
+ it "returns full order data" do
106
+ expect(subject).to be_kind_of ABBYY::Cloud::Models::FullOrder
107
+ end
108
+ end
109
+
110
+ context "without type:" do
111
+ before { request.delete :type }
112
+
113
+ it "raises ArgumentError without sending a request" do
114
+ expect { subject }.to raise_error(ABBYY::Cloud::ArgumentError)
115
+ expect(a_request(:any, //)).not_to have_been_made
116
+ end
117
+ end
118
+
119
+ context "without cost_type:" do
120
+ before { request.delete :cost_type }
121
+
122
+ it "raises ArgumentError without sending a request" do
123
+ expect { subject }.to raise_error(ABBYY::Cloud::ArgumentError)
124
+ expect(a_request(:any, //)).not_to have_been_made
125
+ end
126
+ end
127
+
128
+ context "without unit_type:" do
129
+ before { request.delete :unit_type }
130
+
131
+ it "raises ArgumentError without sending a request" do
132
+ expect { subject }.to raise_error(ABBYY::Cloud::ArgumentError)
133
+ expect(a_request(:any, //)).not_to have_been_made
134
+ end
135
+ end
136
+
137
+ context "without currency:" do
138
+ before { request.delete :currency }
139
+
140
+ it "raises ArgumentError without sending a request" do
141
+ expect { subject }.to raise_error(ABBYY::Cloud::ArgumentError)
142
+ expect(a_request(:any, //)).not_to have_been_made
143
+ end
144
+ end
145
+
146
+ context "without source language:" do
147
+ before { request.delete :from }
148
+
149
+ it "raises ArgumentError without sending a request" do
150
+ expect { subject }.to raise_error(ABBYY::Cloud::ArgumentError)
151
+ expect(a_request(:any, //)).not_to have_been_made
152
+ end
153
+ end
154
+
155
+ context "when label is too long:" do
156
+ before { request[:label] = "a" * 81 }
157
+
158
+ it "raises ArgumentError without sending a request" do
159
+ expect { subject }.to raise_error(ABBYY::Cloud::ArgumentError)
160
+ expect(a_request(:any, //)).not_to have_been_made
161
+ end
162
+ end
163
+
164
+ context "without target language:" do
165
+ before { request[:to] = [] }
166
+
167
+ it "raises ArgumentError without sending a request" do
168
+ expect { subject }.to raise_error(ABBYY::Cloud::ArgumentError)
169
+ expect(a_request(:any, //)).not_to have_been_made
170
+ end
171
+ end
172
+
173
+ context "with wrong translation type:" do
174
+ before { request[:type] = "unknown" }
175
+
176
+ it "raises ArgumentError without sending a request" do
177
+ expect { subject }.to raise_error(ABBYY::Cloud::ArgumentError)
178
+ expect(a_request(:any, //)).not_to have_been_made
179
+ end
180
+ end
181
+
182
+ context "with wrong cost type:" do
183
+ before { request[:cost_type] = "Unknown" }
184
+
185
+ it "raises ArgumentError without sending a request" do
186
+ expect { subject }.to raise_error(ABBYY::Cloud::ArgumentError)
187
+ expect(a_request(:any, //)).not_to have_been_made
188
+ end
189
+ end
190
+
191
+ context "with wrong unit type:" do
192
+ before { request[:unit_type] = "Unknown" }
193
+
194
+ it "raises ArgumentError without sending a request" do
195
+ expect { subject }.to raise_error(ABBYY::Cloud::ArgumentError)
196
+ expect(a_request(:any, //)).not_to have_been_made
197
+ end
198
+ end
199
+
200
+ context "without files:" do
201
+ before { request[:files] = [] }
202
+
203
+ it "raises ArgumentError without sending a request" do
204
+ expect { subject }.to raise_error(ABBYY::Cloud::ArgumentError)
205
+ expect(a_request(:any, //)).not_to have_been_made
206
+ end
207
+ end
208
+
209
+ context "with wrong file:" do
210
+ before { request[:files] = [{ foo: "bar" }] }
211
+
212
+ it "raises ArgumentError without sending a request" do
213
+ expect { subject }.to raise_error(ABBYY::Cloud::ArgumentError)
214
+ expect(a_request(:any, //)).not_to have_been_made
215
+ end
216
+ end
217
+
218
+ context "when API returned invalid order:" do
219
+ before do
220
+ stub_request(:post, path)
221
+ .with(basic_auth: %w(foo bar))
222
+ .to_return status: 200,
223
+ headers: { "Content-Type" => "application/json" },
224
+ body: JSON(response.update(currency: nil))
225
+ end
226
+
227
+ it "raises TypeError" do
228
+ expect { subject }.to raise_error(ABBYY::Cloud::TypeError)
229
+ end
230
+ end
231
+
232
+ context "when API responded with error:" do
233
+ before do
234
+ stub_request(:post, path)
235
+ .with(basic_auth: %w(foo bar))
236
+ .to_return status: 500,
237
+ headers: { "Content-Type" => "application/json" },
238
+ body: "Server error"
239
+ end
240
+
241
+ it "raises ResponseError" do
242
+ expect { subject }.to raise_error(ABBYY::Cloud::ResponseError)
243
+ end
244
+ end
245
+ end
@@ -0,0 +1,116 @@
1
+ RSpec.describe "orders.find" do
2
+ let(:client) { ABBYY::Cloud.new id: "foo", token: "bar" }
3
+ let(:path) { "https://api.abbyy.cloud/v0/order/45" }
4
+ let(:response) do
5
+ {
6
+ translations: [
7
+ {
8
+ source_file: {
9
+ id: "foo",
10
+ token: "bar",
11
+ name: "ru.xml",
12
+ language: "ru",
13
+ chars_count: 107,
14
+ words_count: 32,
15
+ pages_count: 1,
16
+ is_deleted: false
17
+ },
18
+ target_file: {
19
+ id: "rab",
20
+ token: "oof",
21
+ name: "de.xml",
22
+ language: "de",
23
+ chars_count: 87,
24
+ words_count: 22,
25
+ pages_count: 1,
26
+ is_deleted: false
27
+ },
28
+ started: "2016-03-13T10:00:00Z",
29
+ delivered: "2019-03-14T11:00:00Z",
30
+ progress: 10,
31
+ status: "InProgress"
32
+ }
33
+ ],
34
+ id: "qux",
35
+ number: 1924,
36
+ email: "user@example.com",
37
+ type: "ht_professional",
38
+ from: "ru",
39
+ to: ["de"],
40
+ is_layout_required: true,
41
+ label: "baz",
42
+ payment_type: "External",
43
+ unit_type: "Words",
44
+ unit_count: 32,
45
+ units_count: 32,
46
+ currency: "RUB",
47
+ amount: 100.0,
48
+ deadline: "2019-01-23T10:00:00Z",
49
+ payment_provider: "CloudPayments",
50
+ is_manual_estimation: true,
51
+ created: "2019-02-10T12:00:00Z",
52
+ started: "2016-03-13T10:00:00Z",
53
+ delivered: "2019-03-14T11:00:00Z",
54
+ progress: 10,
55
+ status: "InProgress",
56
+ approval_required: true,
57
+ deleted: nil,
58
+ is_deleted: false,
59
+ statistics: {
60
+ documents_count: 1,
61
+ pages_count: 1,
62
+ words_count: 32,
63
+ chars_count: 103
64
+ }
65
+ }
66
+ end
67
+
68
+ subject { client.orders.find(45) }
69
+
70
+ context "when API returned valid data:" do
71
+ before do
72
+ stub_request(:get, path)
73
+ .with(basic_auth: %w(foo bar))
74
+ .to_return status: 200,
75
+ headers: { "Content-Type" => "application/json" },
76
+ body: JSON(response)
77
+ end
78
+
79
+ it "sends a request to ABBYY Cloud API" do
80
+ subject
81
+ expect(a_request(:get, path)).to have_been_made
82
+ end
83
+
84
+ it "returns full order data" do
85
+ expect(subject).to be_kind_of ABBYY::Cloud::Models::FullOrder
86
+ end
87
+ end
88
+
89
+ context "when API returned invalid order:" do
90
+ before do
91
+ stub_request(:get, path)
92
+ .with(basic_auth: %w(foo bar))
93
+ .to_return status: 200,
94
+ headers: { "Content-Type" => "application/json" },
95
+ body: JSON(response.update(currency: nil))
96
+ end
97
+
98
+ it "raises TypeError" do
99
+ expect { subject }.to raise_error(ABBYY::Cloud::TypeError)
100
+ end
101
+ end
102
+
103
+ context "when API responded with error:" do
104
+ before do
105
+ stub_request(:get, path)
106
+ .with(basic_auth: %w(foo bar))
107
+ .to_return status: 500,
108
+ headers: { "Content-Type" => "application/json" },
109
+ body: "Server error"
110
+ end
111
+
112
+ it "raises ResponseError" do
113
+ expect { subject }.to raise_error(ABBYY::Cloud::ResponseError)
114
+ end
115
+ end
116
+ end
@@ -36,7 +36,7 @@ RSpec.describe ABBYY::Cloud::Connection do
36
36
  end
37
37
 
38
38
  it "returns the response body" do
39
- expect(subject).to eq("answer" => 42)
39
+ expect(subject).to eq(JSON(answer: 42))
40
40
  end
41
41
  end
42
42
 
@@ -0,0 +1,51 @@
1
+ RSpec.describe ABBYY::Cloud::Models::FileLink do
2
+ let(:data) do
3
+ {
4
+ id: "foo",
5
+ token: "bar",
6
+ name: "baz.txt",
7
+ language: "fr",
8
+ is_deleted: true,
9
+ chars_count: 3204,
10
+ words_count: 132,
11
+ pages_count: 3
12
+ }
13
+ end
14
+
15
+ subject { described_class.new(data) }
16
+
17
+ it { is_expected.to be_kind_of ABBYY::Cloud::Struct }
18
+ its(:to_h) { is_expected.to eq data }
19
+
20
+ context "without id:" do
21
+ before { data.delete :id }
22
+
23
+ it "fails" do
24
+ expect { subject }.to raise_error(StandardError)
25
+ end
26
+ end
27
+
28
+ context "without token:" do
29
+ before { data.delete :token }
30
+
31
+ it "fails" do
32
+ expect { subject }.to raise_error(StandardError)
33
+ end
34
+ end
35
+
36
+ context "without name:" do
37
+ before { data.delete :name }
38
+
39
+ it "fails" do
40
+ expect { subject }.to raise_error(StandardError)
41
+ end
42
+ end
43
+
44
+ context "without language:" do
45
+ before { data.delete :language }
46
+
47
+ it "fails" do
48
+ expect { subject }.to raise_error(StandardError)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,24 @@
1
+ RSpec.describe ABBYY::Cloud::Models::FileReference do
2
+ let(:data) { { id: "foo", token: "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 "without id:" do
10
+ before { data.delete :id }
11
+
12
+ it "fails" do
13
+ expect { subject }.to raise_error(StandardError)
14
+ end
15
+ end
16
+
17
+ context "without token:" do
18
+ before { data.delete :token }
19
+
20
+ it "fails" do
21
+ expect { subject }.to raise_error(StandardError)
22
+ end
23
+ end
24
+ end