scnnr 0.2.0 → 1.0.0

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: 63bcc0cea5fbfb536f2ebd9b87623f7ec943b68e
4
- data.tar.gz: 295d5b100e0cd86ffcaaad0e815f28276c063597
3
+ metadata.gz: 701520f0f2410d7300d04bac498aec68db34597f
4
+ data.tar.gz: 15d6e7b77a2ad5c91d96fa302d4eb1fc800792f3
5
5
  SHA512:
6
- metadata.gz: 5659d4858fdce6480279c9d988f61813ccfd852c7eba5e366913ec4d7583d5eccd14f19182d54032f0eb91bb1eb0f1bdb1e1a524f8b7b36713c3121aab3db46b
7
- data.tar.gz: 9880c8a857b3bd38ec11bd19c4b80d73a9f242cea72585ddc9f6108897f6be63890ccbda5e6306c45b2136a43bbc3196571feec63b90dce900ea5ca3e21e37e1
6
+ metadata.gz: 99379cccbdb705692acd048f32355638b4084c19071c7c2833604fb1356164a36982aab1e7aa505d66495650524faf1d88d492e2eb854308b38b052ed821d0c0
7
+ data.tar.gz: ab1d3a36414710519e793259a1a9f655da7c6333971ac145e834bbb62fe02257985092cfd54568c78dd6aa86b4947e5961c9270adf44618adae7a121dba6c62b
@@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
+
8
+ ## [1.0.0] - 2017-11-01
9
+ ### Added
10
+ - Allow timeouts greater than 25s when recognising images.
11
+
12
+ ### Fixed
13
+ - Fix that `Scnnr::Client#fetch` with a long timeout does not make multiple request.
14
+
15
+ ### Removed
16
+ - Remove `async` from `Scnnr::Response`.
17
+
7
18
  ## [0.2.0] - 2017-10-20
8
19
  ### Added
9
20
  - Add reference links to README.
@@ -16,19 +16,19 @@ module Scnnr
16
16
  end
17
17
 
18
18
  def recognize_image(image, options = {})
19
- options = merge_options(options)
20
- uri = construct_uri('recognitions', options)
21
- # TODO: Use PollingManager to be accepted timeout > 25
22
- response = post_connection(uri, options).send_stream(image)
23
- handle_response(response, options)
19
+ PollingManager.start(self, merge_options(options)) do |opts|
20
+ uri = construct_uri('recognitions', opts)
21
+ response = post_connection(uri, opts).send_stream(image)
22
+ handle_response(response)
23
+ end
24
24
  end
25
25
 
26
26
  def recognize_url(url, options = {})
27
- options = merge_options(options)
28
- uri = construct_uri('remote/recognitions', options)
29
- # TODO: Use PollingManager to be accepted timeout > 25
30
- response = post_connection(uri, options).send_json({ url: url })
31
- handle_response(response, options)
27
+ PollingManager.start(self, merge_options(options)) do |opts|
28
+ uri = construct_uri('remote/recognitions', opts)
29
+ response = post_connection(uri, opts).send_json({ url: url })
30
+ handle_response(response)
31
+ end
32
32
  end
33
33
 
34
34
  def fetch(recognition_id, options = {})
@@ -60,11 +60,11 @@ module Scnnr
60
60
  options = merge_options(options)
61
61
  uri = construct_uri("recognitions/#{recognition_id}", options)
62
62
  response = get_connection(uri, options).send_request
63
- handle_response(response, options)
63
+ handle_response(response)
64
64
  end
65
65
 
66
- def handle_response(response, options = {})
67
- response = Response.new(response, options[:timeout].positive?)
66
+ def handle_response(response)
67
+ response = Response.new(response)
68
68
  response.build_recognition
69
69
  end
70
70
  end
@@ -6,6 +6,19 @@ module Scnnr
6
6
 
7
7
  attr_accessor :timeout
8
8
 
9
+ def self.start(client, options, &block)
10
+ timeout = options.delete(:timeout)
11
+ used_timeout = [timeout, MAX_TIMEOUT].min
12
+ extra_timeout = timeout - used_timeout
13
+
14
+ recognition = block.call(options.merge(timeout: used_timeout))
15
+ if recognition.queued? && extra_timeout.positive?
16
+ new(extra_timeout).polling(client, recognition.id, options)
17
+ else
18
+ recognition
19
+ end
20
+ end
21
+
9
22
  def initialize(timeout)
10
23
  case timeout
11
24
  when Integer, Float::INFINITY then @timeout = timeout
@@ -14,16 +27,14 @@ module Scnnr
14
27
  end
15
28
  end
16
29
 
17
- def remain_timeout?
18
- self.timeout.positive?
19
- end
20
-
21
30
  def polling(client, recognition_id, options = {})
22
31
  loop do
23
32
  timeout = [self.timeout, MAX_TIMEOUT].min
24
33
  self.timeout -= timeout
25
34
  recognition = client.fetch(recognition_id, options.merge(timeout: timeout, polling: false))
26
- break recognition if recognition.finished? || !self.remain_timeout?
35
+
36
+ break recognition unless recognition.queued?
37
+ raise TimeoutError.new('recognition timed out', recognition) unless self.timeout.positive?
27
38
  end
28
39
  end
29
40
  end
@@ -4,10 +4,9 @@ module Scnnr
4
4
  class Response
5
5
  SUPPORTED_CONTENT_TYPE = 'application/jp.cubki.scnnr.v1+json'
6
6
 
7
- def initialize(response, async)
7
+ def initialize(response)
8
8
  raise UnexpectedError, response if response.content_type != SUPPORTED_CONTENT_TYPE
9
9
  @response = response
10
- @async = async
11
10
  end
12
11
 
13
12
  def body
@@ -18,10 +17,6 @@ module Scnnr
18
17
  @parsed_body ||= JSON.parse(self.body)
19
18
  end
20
19
 
21
- def async?
22
- @async == true
23
- end
24
-
25
20
  def build_recognition
26
21
  case @response
27
22
  when Net::HTTPSuccess
@@ -35,7 +30,6 @@ module Scnnr
35
30
  private
36
31
 
37
32
  def handle_recognition(recognition)
38
- raise TimeoutError.new('recognition timed out', recognition) if recognition.queued? && async?
39
33
  return recognition unless recognition.error?
40
34
 
41
35
  case recognition.error['type']
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Scnnr
4
- VERSION = '0.2.0'
4
+ VERSION = '1.0.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scnnr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - NEWROPE Co. Ltd.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-20 00:00:00.000000000 Z
11
+ date: 2017-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler