abbyy-cloud 0.0.6 → 0.0.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e315b9643988d2d779dbbe0e22deca6552111e47
4
- data.tar.gz: 1255379a0e408cdba1c524395d8c2a3a653bf7f9
3
+ metadata.gz: 22ccdf6c83c1c16d2d88e4e2c1db6e92350f855b
4
+ data.tar.gz: 5487edca014bb2b01839ad1c018c417b9ba90d6e
5
5
  SHA512:
6
- metadata.gz: 71b4414e1f7f9aba1058e7bac40dc5fa38c0f14079c593ba5426b89f1b015b492a626472debad76e2282c4cf3f1ad543ab7b9f5005f7446034b8a0e831ce0153
7
- data.tar.gz: 8fe5ec65636e196b1a9e2e1da3cd539a279b89891929414256bdc91c79d0620dee8906a0329c0756af60186b724b315fe16afb1fa82ecb87ca3a4e04a62b2877
6
+ metadata.gz: 73afb10ed62e83e82275e2ed91b4dea2c4a84e3624b5b6352ed163f63bc34db49c0acdb3e824a8394232c8a9773e26628b1c8f43bd14e54a2def0edda5415822
7
+ data.tar.gz: c3238c14723df68f93233c9f99d03b7203a82a1b09f84f25e190dab8597a126799baa4dbd66dc03b4a82fe1aa4fdd9d3230f3534684ed68bbc6739bc3a7c93e8
@@ -1,5 +1,17 @@
1
1
  # Master (to be released)
2
2
 
3
+ [Compare v0.0.7...HEAD](https://github.com/nepalez/abbyy-cloud/compare/v0.0.7...HEAD)
4
+
5
+ # [v0.0.7 2016-09-09](https://github.com/nepalez/abbyy-cloud/tree/v0.0.7)
6
+
7
+ ### Bugs Fixed
8
+
9
+ * Order of loading files (nepalez)
10
+
11
+ [Compare v0.0.6...v0.0.7](https://github.com/nepalez/abbyy-cloud/compare/v0.0.6...v0.0.7)
12
+
13
+ # [v0.0.6 2016-09-09](https://github.com/nepalez/abbyy-cloud/tree/v0.0.6)
14
+
3
15
  ### Added
4
16
 
5
17
  * Operation `files.upload` (nepalez)
@@ -7,7 +19,7 @@
7
19
  * Operation `orders.create(options)` (nepalez)
8
20
  * Operation `orders.find(id)` (nepalez)
9
21
 
10
- [Compare v0.0.5...HEAD](https://github.com/nepalez/abbyy-cloud/compare/v0.0.5...HEAD)
22
+ [Compare v0.0.5...v0.0.6](https://github.com/nepalez/abbyy-cloud/compare/v0.0.5...v0.0.6)
11
23
 
12
24
  # [v0.0.5 2016-08-23](https://github.com/nepalez/abbyy-cloud/tree/v0.0.5)
13
25
 
@@ -1,6 +1,9 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
1
4
  Gem::Specification.new do |gem|
2
5
  gem.name = "abbyy-cloud"
3
- gem.version = "0.0.6"
6
+ gem.version = "0.0.7"
4
7
  gem.authors = ["Andrew Kozin"]
5
8
  gem.email = ["andrew.kozin@gmail.com"]
6
9
  gem.summary = "HTTP client to ABBYY Cloud API"
@@ -18,6 +21,7 @@ Gem::Specification.new do |gem|
18
21
  gem.add_runtime_dependency "dry-struct", "~> 0.0.1"
19
22
  gem.add_runtime_dependency "hashie", "~> 3.4"
20
23
  gem.add_runtime_dependency "multipart_body", "~> 0.2"
24
+ gem.add_runtime_dependency "mime-types", "~> 3.1"
21
25
 
22
26
  gem.add_development_dependency "bundler", "~> 1.12"
23
27
  gem.add_development_dependency "rake", "~> 10.0"
@@ -5,6 +5,7 @@ require "json"
5
5
  require "net/http"
6
6
  require "net/https"
7
7
  require "multipart_body"
8
+ require "mime-types"
8
9
 
9
10
  module ABBYY
10
11
  class Cloud
@@ -14,7 +15,7 @@ module ABBYY
14
15
  require_relative "cloud/settings"
15
16
 
16
17
  %w(exceptions models operations namespaces).each do |dir|
17
- path = File.expand_path("lib/abbyy/cloud/#{dir}/**")
18
+ path = File.expand_path("../cloud/#{dir}/**", __FILE__)
18
19
  Dir[path].each { |file| require file }
19
20
  end
20
21
 
@@ -11,7 +11,7 @@ require_relative "unit_type"
11
11
  class ABBYY::Cloud
12
12
  module Models
13
13
  class FullOrder < Struct
14
- attribute :amount, Types::Coercible::Float
14
+ attribute :amount, Types::Coercible::Float.optional
15
15
  attribute :approval_required, Types::Form::Bool
16
16
  attribute :created, Types::Form::Time
17
17
  attribute :currency, Types::Currency
@@ -26,18 +26,18 @@ class ABBYY::Cloud
26
26
  attribute :is_manual_estimation, Types::Form::Bool
27
27
  attribute :label, Types::Label.optional
28
28
  attribute :number, Types::Coercible::Int
29
- attribute :payment_provider, Types::Strict::String
29
+ attribute :payment_provider, Types::Strict::String.optional
30
30
  attribute :payment_type, Types::PaymentType
31
31
  attribute :progress, Types::Coercible::Int
32
32
  attribute :started, Types::Form::Time.optional
33
- attribute :statistics, Types::OrderStatistics
33
+ attribute :statistics, Types::OrderStatistics.optional
34
34
  attribute :status, Types::Status
35
35
  attribute :to, Types::FilledArray.member(Types::Locale)
36
36
  attribute :translations, Types::Array.member(Types::TranslationLink)
37
37
  attribute :type, Types::TranslationType
38
- attribute :unit_count, Types::Coercible::Int
39
- attribute :unit_type, Types::UnitType
40
- attribute :units_count, Types::Hash
38
+ attribute :unit_count, Types::Coercible::Int.optional
39
+ attribute :unit_type, Types::UnitType.optional
40
+ attribute :units_count, Types::Hash.optional
41
41
  end
42
42
 
43
43
  # Registers type Types::FullOrder
@@ -4,10 +4,10 @@ require_relative "file_link"
4
4
  class ABBYY::Cloud
5
5
  module Models
6
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
7
+ attribute :delivered, Types::Form::Time.optional
8
+ attribute :started, Types::Form::Time.optional
9
+ attribute :progress, Types::Hash
10
+ attribute :status, Types::Status
11
11
  attribute :source_file, Types::FileLink
12
12
  attribute :target_file, Types::FileLink
13
13
  end
@@ -1,3 +1,5 @@
1
+ require_relative "file"
2
+
1
3
  # Base class for specific operations
2
4
  # It validates request and response using corresponding structs
3
5
  #
@@ -79,11 +81,10 @@ class ABBYY::Cloud
79
81
 
80
82
  private
81
83
 
82
- def prepare_multipart(file, content_type: "plain/text", **)
84
+ def prepare_multipart(data, content_type: "text/plain", **)
83
85
  name = SecureRandom.hex(10)
84
- data = file.read if file.respond_to?(:read)
85
- path = Pathname.new(file.path).basename if file.respond_to?(:path)
86
- part = Part.new(name, data || file, path || "file")
86
+ file = File.new(data, content_type: content_type)
87
+ part = Part.new(name, file.read, file.path)
87
88
  part.content_type = content_type
88
89
  MultipartBody.new [part]
89
90
  end
@@ -91,7 +92,7 @@ class ABBYY::Cloud
91
92
  def prepare_request_body(multipart, data)
92
93
  case request_type
93
94
  when :json then JSON(request_body[data].to_h)
94
- when :file then multipart.to_s << "\r\n"
95
+ when :file then [nil, nil, multipart, nil].join("\r\n")
95
96
  else data
96
97
  end
97
98
  rescue => error
@@ -0,0 +1,29 @@
1
+ # Emulates a source to ensure it has methods [#read] and [#path]
2
+ class ABBYY::Cloud
3
+ module Operations
4
+ class File
5
+ extend Dry::Initializer::Mixin
6
+ param :source
7
+ option :content_type
8
+
9
+ def read
10
+ source.respond_to?(:read) ? source.read : source
11
+ end
12
+
13
+ def path
14
+ @path ||= \
15
+ if source.respond_to?(:path)
16
+ Pathname.new(source.path).basename
17
+ else
18
+ "#{SecureRandom.hex(4)}.#{ext}"
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def ext
25
+ MIME::Types[content_type].first.preferred_extension
26
+ end
27
+ end
28
+ end
29
+ end
@@ -24,6 +24,7 @@ class ABBYY::Cloud
24
24
  attribute :label, Types::Label.optional
25
25
  attribute :to, Types::FilledArray.member(Types::Locale)
26
26
  attribute :files, Types::FilledArray.member(Types::FileReference)
27
+ attribute :category, Types::Strict::String.optional
27
28
  end
28
29
 
29
30
  response_body Models::FullOrder
@@ -18,7 +18,8 @@ RSpec.describe "orders.create" do
18
18
  currency: "RUB",
19
19
  from: "ru",
20
20
  to: ["de"],
21
- files: [{ id: "foo", token: "bar" }]
21
+ files: [{ id: "foo", token: "bar" }],
22
+ category: "Games > Lego"
22
23
  }
23
24
  end
24
25
 
@@ -63,7 +64,6 @@ RSpec.describe "orders.create" do
63
64
  payment_type: "External",
64
65
  unit_type: "Words",
65
66
  unit_count: 32,
66
- units_count: 32,
67
67
  currency: "RUB",
68
68
  amount: 100.0,
69
69
  deadline: "2019-01-23T10:00:00Z",
@@ -42,7 +42,6 @@ RSpec.describe "orders.find" do
42
42
  payment_type: "External",
43
43
  unit_type: "Words",
44
44
  unit_count: 32,
45
- units_count: 32,
46
45
  currency: "RUB",
47
46
  amount: 100.0,
48
47
  deadline: "2019-01-23T10:00:00Z",
@@ -134,22 +134,6 @@ RSpec.describe ABBYY::Cloud::Models::FullOrder do
134
134
  end
135
135
  end
136
136
 
137
- context "without unit_type:" do
138
- before { data.delete :unit_type }
139
-
140
- it "fails" do
141
- expect { subject }.to raise_error(StandardError)
142
- end
143
- end
144
-
145
- context "without unit_count:" do
146
- before { data.delete :unit_count }
147
-
148
- it "fails" do
149
- expect { subject }.to raise_error(StandardError)
150
- end
151
- end
152
-
153
137
  context "without currency:" do
154
138
  before { data.delete :currency }
155
139
 
@@ -181,12 +165,4 @@ RSpec.describe ABBYY::Cloud::Models::FullOrder do
181
165
  expect { subject }.to raise_error(StandardError)
182
166
  end
183
167
  end
184
-
185
- context "without statistics:" do
186
- before { data.delete :statistics }
187
-
188
- it "fails" do
189
- expect { subject }.to raise_error(StandardError)
190
- end
191
- end
192
168
  end
@@ -23,7 +23,6 @@ RSpec.describe ABBYY::Cloud::Models::TranslationLink do
23
23
  },
24
24
  started: "2016-03-13T10:00:00Z",
25
25
  delivered: "2019-03-14T11:00:00Z",
26
- progress: 10,
27
26
  status: "InProgress"
28
27
  }
29
28
  end
@@ -55,12 +54,4 @@ RSpec.describe ABBYY::Cloud::Models::TranslationLink do
55
54
  expect { subject }.to raise_error(StandardError)
56
55
  end
57
56
  end
58
-
59
- context "without progress:" do
60
- before { data.delete :progress }
61
-
62
- it "fails" do
63
- expect { subject }.to raise_error(StandardError)
64
- end
65
- end
66
57
  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.6
4
+ version: 0.0.7
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-09-08 00:00:00.000000000 Z
11
+ date: 2016-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-initializer
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mime-types
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.1'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.1'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: bundler
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -219,6 +233,7 @@ files:
219
233
  - lib/abbyy/cloud/operations/base.rb
220
234
  - lib/abbyy/cloud/operations/download_file.rb
221
235
  - lib/abbyy/cloud/operations/engines.rb
236
+ - lib/abbyy/cloud/operations/file.rb
222
237
  - lib/abbyy/cloud/operations/find_order.rb
223
238
  - lib/abbyy/cloud/operations/prices.rb
224
239
  - lib/abbyy/cloud/operations/submit_order.rb