abbyy-cloud 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/CHANGELOG.md +24 -0
  4. data/README.md +60 -33
  5. data/abbyy-cloud.gemspec +1 -1
  6. data/lib/abbyy/cloud.rb +10 -16
  7. data/lib/abbyy/cloud/connection.rb +31 -17
  8. data/lib/abbyy/cloud/models/direction.rb +4 -2
  9. data/lib/abbyy/cloud/models/discount.rb +12 -0
  10. data/lib/abbyy/cloud/models/engine.rb +4 -1
  11. data/lib/abbyy/cloud/models/locale.rb +23 -0
  12. data/lib/abbyy/cloud/models/price.rb +22 -0
  13. data/lib/abbyy/cloud/models/source_segment.rb +14 -0
  14. data/lib/abbyy/cloud/models/source_tag.rb +15 -0
  15. data/lib/abbyy/cloud/models/transfer_data.rb +14 -0
  16. data/lib/abbyy/cloud/models/translation.rb +1 -1
  17. data/lib/abbyy/cloud/models/translation_segment.rb +16 -0
  18. data/lib/abbyy/cloud/models/unit_price.rb +13 -0
  19. data/lib/abbyy/cloud/namespaces/machine_translations.rb +47 -1
  20. data/lib/abbyy/cloud/namespaces/prices.rb +29 -0
  21. data/lib/abbyy/cloud/operations/base.rb +20 -6
  22. data/lib/abbyy/cloud/operations/engines.rb +3 -1
  23. data/lib/abbyy/cloud/operations/prices.rb +23 -0
  24. data/lib/abbyy/cloud/operations/translate.rb +5 -3
  25. data/lib/abbyy/cloud/operations/translate_segments.rb +22 -0
  26. data/lib/abbyy/cloud/settings.rb +4 -5
  27. data/lib/abbyy/cloud/types.rb +14 -10
  28. data/spec/abbyy/cloud/connection_spec.rb +1 -1
  29. data/spec/abbyy/cloud/models/discount_spec.rb +32 -0
  30. data/spec/abbyy/cloud/models/locale_spec.rb +55 -0
  31. data/spec/abbyy/cloud/models/price_spec.rb +107 -0
  32. data/spec/abbyy/cloud/models/source_segment_spec.rb +37 -0
  33. data/spec/abbyy/cloud/models/source_tag_spec.rb +56 -0
  34. data/spec/abbyy/cloud/models/transfer_data_spec.rb +40 -0
  35. data/spec/abbyy/cloud/models/translation_segment_spec.rb +38 -0
  36. data/spec/abbyy/cloud/models/unit_price_spec.rb +48 -0
  37. data/spec/abbyy/cloud/settings_spec.rb +2 -24
  38. data/spec/abbyy/cloud_spec.rb +3 -4
  39. data/spec/feature/abbyy/mt_default_engine_spec.rb +12 -0
  40. data/spec/feature/abbyy/mt_engine_spec.rb +15 -0
  41. data/spec/feature/abbyy/mt_translate_segments_spec.rb +136 -0
  42. data/spec/feature/abbyy/{order_translate_spec.rb → mt_translate_spec.rb} +2 -2
  43. data/spec/feature/abbyy/prices_details_spec.rb +70 -0
  44. metadata +39 -5
  45. data/lib/abbyy/cloud/namespaces/orders.rb +0 -25
@@ -1,4 +1,4 @@
1
- RSpec.describe "orders.translate" do
1
+ RSpec.describe "mt.translate" do
2
2
  let(:client) { ABBYY::Cloud.new settings }
3
3
  let(:settings) { { id: "foo", token: "bar", engine: default_engine } }
4
4
  let(:default_engine) { "Google" }
@@ -21,7 +21,7 @@ RSpec.describe "orders.translate" do
21
21
  body: JSON(response_model)
22
22
  end
23
23
 
24
- subject { client.orders.translate source_text, params }
24
+ subject { client.mt.translate source_text, params }
25
25
 
26
26
  it "sends a request to ABBYY Cloud API" do
27
27
  subject
@@ -0,0 +1,70 @@
1
+ RSpec.describe "prices.details" do
2
+ let(:client) { ABBYY::Cloud.new id: "foo", token: "bar" }
3
+ let(:price) do
4
+ {
5
+ id: "foo",
6
+ account_id: "bar",
7
+ type: "qux",
8
+ from: "ru",
9
+ to: "en",
10
+ unit_prices: [{ unit_type: "Words", currency: "USD", amount: 0.03 }],
11
+ discounts: [{ discount_type: "TMTextMatch", discount: 0.01 }],
12
+ created: Time.parse("2017-03-09 18:19")
13
+ }
14
+ end
15
+
16
+ before do
17
+ stub_request(:get, //)
18
+ .with(basic_auth: %w(foo bar))
19
+ .to_return status: 200,
20
+ headers: { "Content-Type" => "application/json" },
21
+ body: JSON.generate(Array.new(taken) { price })
22
+ end
23
+
24
+ subject { client.prices.details skip: 0, take: take }
25
+
26
+ context "when take not exceeds 1_000:" do
27
+ let(:take) { 1_000 }
28
+ let(:taken) { 1_000 }
29
+
30
+ it "sends a request to ABBYY Cloud API" do
31
+ subject
32
+ expect(a_request(:get, "https://api.abbyy.cloud/v0/prices/details?skip=0&take=1000")).to have_been_made.once
33
+ end
34
+
35
+ it "returns list of prices" do
36
+ expect(subject.count).to eq 1_000
37
+ expect(subject.first.to_h).to eq price
38
+ end
39
+ end
40
+
41
+ context "when take exceeds 1_000:" do
42
+ let(:take) { 2_000 }
43
+ let(:taken) { 1_000 }
44
+
45
+ it "sends several requests to ABBYY Cloud API" do
46
+ subject
47
+ expect(a_request(:get, "https://api.abbyy.cloud/v0/prices/details?skip=0&take=1000")).to have_been_made.once
48
+ expect(a_request(:get, "https://api.abbyy.cloud/v0/prices/details?skip=1000&take=1000")).to have_been_made.once
49
+ end
50
+
51
+ it "returns list of prices" do
52
+ expect(subject.count).to eq 2_000
53
+ end
54
+ end
55
+
56
+ context "when number of prices is less than take option:" do
57
+ let(:take) { 2_000 }
58
+ let(:taken) { 900 }
59
+
60
+ it "sends necessary requests only" do
61
+ subject
62
+ expect(a_request(:get, "https://api.abbyy.cloud/v0/prices/details?skip=0&take=1000")).to have_been_made.once
63
+ expect(a_request(:get, "https://api.abbyy.cloud/v0/prices/details?*")).not_to have_been_made
64
+ end
65
+
66
+ it "returns list of prices" do
67
+ expect(subject.count).to eq 900
68
+ end
69
+ end
70
+ end
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.3
4
+ version: 0.0.4
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-19 00:00:00.000000000 Z
11
+ date: 2016-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-initializer
@@ -147,28 +147,50 @@ files:
147
147
  - lib/abbyy/cloud/exceptions/response_error.rb
148
148
  - lib/abbyy/cloud/exceptions/type_error.rb
149
149
  - lib/abbyy/cloud/models/direction.rb
150
+ - lib/abbyy/cloud/models/discount.rb
150
151
  - lib/abbyy/cloud/models/engine.rb
151
152
  - lib/abbyy/cloud/models/error.rb
153
+ - lib/abbyy/cloud/models/locale.rb
154
+ - lib/abbyy/cloud/models/price.rb
155
+ - lib/abbyy/cloud/models/source_segment.rb
156
+ - lib/abbyy/cloud/models/source_tag.rb
157
+ - lib/abbyy/cloud/models/transfer_data.rb
152
158
  - lib/abbyy/cloud/models/translation.rb
159
+ - lib/abbyy/cloud/models/translation_segment.rb
160
+ - lib/abbyy/cloud/models/unit_price.rb
153
161
  - lib/abbyy/cloud/namespaces/base.rb
154
162
  - lib/abbyy/cloud/namespaces/machine_translations.rb
155
- - lib/abbyy/cloud/namespaces/orders.rb
163
+ - lib/abbyy/cloud/namespaces/prices.rb
156
164
  - lib/abbyy/cloud/operations/base.rb
157
165
  - lib/abbyy/cloud/operations/engines.rb
166
+ - lib/abbyy/cloud/operations/prices.rb
158
167
  - lib/abbyy/cloud/operations/translate.rb
168
+ - lib/abbyy/cloud/operations/translate_segments.rb
159
169
  - lib/abbyy/cloud/settings.rb
160
170
  - lib/abbyy/cloud/struct.rb
161
171
  - lib/abbyy/cloud/types.rb
162
172
  - spec/abbyy/cloud/connection_spec.rb
163
173
  - spec/abbyy/cloud/models/direction_spec.rb
174
+ - spec/abbyy/cloud/models/discount_spec.rb
164
175
  - spec/abbyy/cloud/models/engine_spec.rb
165
176
  - spec/abbyy/cloud/models/error_spec.rb
177
+ - spec/abbyy/cloud/models/locale_spec.rb
178
+ - spec/abbyy/cloud/models/price_spec.rb
179
+ - spec/abbyy/cloud/models/source_segment_spec.rb
180
+ - spec/abbyy/cloud/models/source_tag_spec.rb
181
+ - spec/abbyy/cloud/models/transfer_data_spec.rb
182
+ - spec/abbyy/cloud/models/translation_segment_spec.rb
166
183
  - spec/abbyy/cloud/models/translation_spec.rb
184
+ - spec/abbyy/cloud/models/unit_price_spec.rb
167
185
  - spec/abbyy/cloud/response_error_spec.rb
168
186
  - spec/abbyy/cloud/settings_spec.rb
169
187
  - spec/abbyy/cloud_spec.rb
188
+ - spec/feature/abbyy/mt_default_engine_spec.rb
189
+ - spec/feature/abbyy/mt_engine_spec.rb
170
190
  - spec/feature/abbyy/mt_engines_spec.rb
171
- - spec/feature/abbyy/order_translate_spec.rb
191
+ - spec/feature/abbyy/mt_translate_segments_spec.rb
192
+ - spec/feature/abbyy/mt_translate_spec.rb
193
+ - spec/feature/abbyy/prices_details_spec.rb
172
194
  - spec/spec_helper.rb
173
195
  homepage: https://github.com/nepalez/abbyy-cloud
174
196
  licenses:
@@ -197,12 +219,24 @@ summary: HTTP client to ABBYY Cloud API
197
219
  test_files:
198
220
  - spec/abbyy/cloud/connection_spec.rb
199
221
  - spec/abbyy/cloud/models/direction_spec.rb
222
+ - spec/abbyy/cloud/models/discount_spec.rb
200
223
  - spec/abbyy/cloud/models/engine_spec.rb
201
224
  - spec/abbyy/cloud/models/error_spec.rb
225
+ - spec/abbyy/cloud/models/locale_spec.rb
226
+ - spec/abbyy/cloud/models/price_spec.rb
227
+ - spec/abbyy/cloud/models/source_segment_spec.rb
228
+ - spec/abbyy/cloud/models/source_tag_spec.rb
229
+ - spec/abbyy/cloud/models/transfer_data_spec.rb
230
+ - spec/abbyy/cloud/models/translation_segment_spec.rb
202
231
  - spec/abbyy/cloud/models/translation_spec.rb
232
+ - spec/abbyy/cloud/models/unit_price_spec.rb
203
233
  - spec/abbyy/cloud/response_error_spec.rb
204
234
  - spec/abbyy/cloud/settings_spec.rb
205
235
  - spec/abbyy/cloud_spec.rb
236
+ - spec/feature/abbyy/mt_default_engine_spec.rb
237
+ - spec/feature/abbyy/mt_engine_spec.rb
206
238
  - spec/feature/abbyy/mt_engines_spec.rb
207
- - spec/feature/abbyy/order_translate_spec.rb
239
+ - spec/feature/abbyy/mt_translate_segments_spec.rb
240
+ - spec/feature/abbyy/mt_translate_spec.rb
241
+ - spec/feature/abbyy/prices_details_spec.rb
208
242
  - spec/spec_helper.rb
@@ -1,25 +0,0 @@
1
- class ABBYY::Cloud
2
- module Namespaces
3
- # Namespace for operations with orders
4
- # @see [https://api.abbyy.cloud/swagger/ui/index#!/Order] ABBYY Cloud API
5
- class Orders < Base
6
- # Instantly (synchronously) translates the text
7
- #
8
- # @example
9
- # translate "Hello world!", from: "en", to: "fr_FR"
10
- #
11
- # @param [String] text
12
- # @option [ABBYY::Cloud::Types::Language] :from Source language
13
- # @option [ABBYY::Cloud::Types::Language] :to Target language
14
- # @return [Hash<Symbol, Object>] translation
15
- #
16
- def translate(text, from:, to:, **opts)
17
- Operations::Translate.new(settings).call source_text: text,
18
- source_language: from,
19
- target_language: to,
20
- engine: settings.engine,
21
- **opts
22
- end
23
- end
24
- end
25
- end