scnnr 1.3.0 → 2.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
  SHA256:
3
- metadata.gz: 235c38c591c2c703be24918f4036a1a5164682190757d79c5be8288bf293728f
4
- data.tar.gz: 18f5a090fe68f2dc4d7e70529a3045085891ea12e3e8ad4dbf92e13c8db0eae0
3
+ metadata.gz: 5cb9874e1854429b787e165fbff198da0e2992ae506a6a84f0c85f42199701d0
4
+ data.tar.gz: 8c59dba0786ab878aef02294606f10fde6eb06fb154ea39ad8473eb8b498e02a
5
5
  SHA512:
6
- metadata.gz: 3533faddd548618a744923f3790cd8cc6f46fa3fd73e0bb1b28bc45bd4df94940b187b025ba51e43332080976b3172c06fc44c8140a5e14c7352b15783c4c835
7
- data.tar.gz: 345aaeb08008708d78cf2ab8b473f04d6261d227c1f2ec54e6e6a5e27b909179f906feec1644139b14d319f96649e5c63866b216934d3f0dc5f11fa1571ebb9d
6
+ metadata.gz: 77805ba9b1a35a675e918222e2925a56195cfbf10366ca6fe07d551d1f7ac95f8170acf7facd9d02e4e7c9b66aa3c1f3959f7d9b37c502b087b7d9c7a815d767
7
+ data.tar.gz: 0de1c9361be51d20fe0f95e57c9277efdac54450dceca1e065700bd07fa263db2635279438f65acb734a615b33b9cf083bfac18ef9dfb57c12891d06657db401
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
4
  #
5
- version: 2
5
+ version: 2.1
6
6
  jobs:
7
7
  build: &build
8
8
  docker:
@@ -13,13 +13,15 @@ jobs:
13
13
  - run:
14
14
  name: install dependencies
15
15
  command: |
16
- bundle install --jobs=4 --retry=3 --path vendor/bundle
16
+ gem install bundler -v 2.1.2
17
+ bundle config set path vendor/bundle
18
+ bundle install --jobs=4 --retry=3
17
19
  # run tests!
18
20
  - run:
19
21
  name: run tests
20
22
  command: |
21
23
  mkdir /tmp/test-results
22
- bundle exec rubocop --format progress -r $(bundle show rubocop-junit-formatter)/lib/rubocop/formatter/junit_formatter.rb --format RuboCop::Formatter::JUnitFormatter --out /tmp/test-results/rubocop.xml
24
+ bundle exec rubocop --format progress --format junit --out /tmp/test-results/rubocop.xml
23
25
  bundle exec rspec --format progress \
24
26
  --format RspecJunitFormatter \
25
27
  --out /tmp/test-results/rspec.xml \
@@ -30,27 +32,27 @@ jobs:
30
32
  - store_artifacts:
31
33
  path: /tmp/test-results
32
34
  destination: test-results
33
- ruby-2.3:
34
- <<: *build
35
- docker:
36
- - image: circleci/ruby:2.3
37
- ruby-2.4:
35
+ ruby-24:
38
36
  <<: *build
39
37
  docker:
40
38
  - image: circleci/ruby:2.4
41
- ruby-2.5:
39
+ ruby-25:
42
40
  <<: *build
43
41
  docker:
44
42
  - image: circleci/ruby:2.5
45
- ruby-2.6:
43
+ ruby-26:
46
44
  <<: *build
47
45
  docker:
48
46
  - image: circleci/ruby:2.6
47
+ ruby-27:
48
+ <<: *build
49
+ docker:
50
+ - image: circleci/ruby:2.7
49
51
  workflows:
50
52
  version: 2
51
53
  ruby-multi-build:
52
54
  jobs:
53
- - ruby-2.3
54
- - ruby-2.4
55
- - ruby-2.5
56
- - ruby-2.6
55
+ - ruby-24
56
+ - ruby-25
57
+ - ruby-26
58
+ - ruby-27
@@ -4,9 +4,6 @@ require:
4
4
  AllCops:
5
5
  TargetRubyVersion: 2.4
6
6
 
7
- Metrics/LineLength:
8
- Max: 120
9
-
10
7
  Metrics/ClassLength:
11
8
  Max: 300
12
9
 
@@ -29,7 +26,10 @@ Style/CollectionMethods:
29
26
  Style/TrailingCommaInArguments:
30
27
  EnforcedStyleForMultiline: no_comma
31
28
 
32
- Style/TrailingCommaInLiteral:
29
+ Style/TrailingCommaInArrayLiteral:
30
+ EnforcedStyleForMultiline: comma
31
+
32
+ Style/TrailingCommaInHashLiteral:
33
33
  EnforcedStyleForMultiline: comma
34
34
 
35
35
  Style/Documentation:
@@ -38,15 +38,15 @@ Style/Documentation:
38
38
  Style/RedundantSelf:
39
39
  Enabled: false
40
40
 
41
+ Layout/LineLength:
42
+ Max: 120
43
+
41
44
  Layout/MultilineMethodCallIndentation:
42
45
  EnforcedStyle: indented
43
46
 
44
- Layout/IndentHash:
47
+ Layout/FirstHashElementIndentation:
45
48
  EnforcedStyle: consistent
46
49
 
47
- Style/BracesAroundHashParameters:
48
- Enabled: false
49
-
50
50
  RSpec/NestedGroups:
51
51
  Max: 5
52
52
 
@@ -65,3 +65,148 @@ RSpec/MessageSpies:
65
65
  RSpec/AnyInstance:
66
66
  Exclude:
67
67
  - 'spec/scnnr/connection_spec.rb'
68
+
69
+ RSpec/ContextWording:
70
+ Prefixes:
71
+ - when
72
+ - with
73
+ - without
74
+ - and
75
+
76
+ RSpec/MultipleMemoizedHelpers:
77
+ Max: 7
78
+
79
+ Layout/EmptyLinesAroundAttributeAccessor: # (new in 0.83)
80
+ Enabled: true
81
+
82
+ Layout/SpaceAroundMethodCallOperator: # (new in 0.82)
83
+ Enabled: true
84
+
85
+ Lint/BinaryOperatorWithIdenticalOperands: # (new in 0.89)
86
+ Enabled: true
87
+
88
+ Lint/DeprecatedOpenSSLConstant: # (new in 0.84)
89
+ Enabled: true
90
+
91
+ Lint/DuplicateElsifCondition: # (new in 0.88)
92
+ Enabled: true
93
+
94
+ Lint/DuplicateRequire: # (new in 0.90)
95
+ Enabled: true
96
+
97
+ Lint/DuplicateRescueException: # (new in 0.89)
98
+ Enabled: true
99
+
100
+ Lint/EmptyConditionalBody: # (new in 0.89)
101
+ Enabled: true
102
+
103
+ Lint/EmptyFile: # (new in 0.90)
104
+ Enabled: true
105
+
106
+ Lint/FloatComparison: # (new in 0.89)
107
+ Enabled: true
108
+
109
+ Lint/MissingSuper: # (new in 0.89)
110
+ Enabled: true
111
+
112
+ Lint/MixedRegexpCaptureTypes: # (new in 0.85)
113
+ Enabled: true
114
+
115
+ Lint/OutOfRangeRegexpRef: # (new in 0.89)
116
+ Enabled: true
117
+
118
+ Lint/RaiseException: # (new in 0.81)
119
+ Enabled: true
120
+
121
+ Lint/SelfAssignment: # (new in 0.89)
122
+ Enabled: true
123
+
124
+ Lint/StructNewOverride: # (new in 0.81)
125
+ Enabled: true
126
+
127
+ Lint/TopLevelReturnWithArgument: # (new in 0.89)
128
+ Enabled: true
129
+
130
+ Lint/TrailingCommaInAttributeDeclaration: # (new in 0.90)
131
+ Enabled: true
132
+
133
+ Lint/UnreachableLoop: # (new in 0.89)
134
+ Enabled: true
135
+
136
+ Lint/UselessMethodDefinition: # (new in 0.90)
137
+ Enabled: true
138
+
139
+ Style/AccessorGrouping: # (new in 0.87)
140
+ Enabled: true
141
+
142
+ Style/ArrayCoercion: # (new in 0.88)
143
+ Enabled: true
144
+
145
+ Style/BisectedAttrAccessor: # (new in 0.87)
146
+ Enabled: true
147
+
148
+ Style/CaseLikeIf: # (new in 0.88)
149
+ Enabled: true
150
+
151
+ Style/CombinableLoops: # (new in 0.90)
152
+ Enabled: true
153
+
154
+ Style/ExplicitBlockArgument: # (new in 0.89)
155
+ Enabled: true
156
+
157
+ Style/ExponentialNotation: # (new in 0.82)
158
+ Enabled: true
159
+
160
+ Style/GlobalStdStream: # (new in 0.89)
161
+ Enabled: true
162
+
163
+ Style/HashAsLastArrayItem: # (new in 0.88)
164
+ Enabled: true
165
+
166
+ Style/HashEachMethods: # (new in 0.80)
167
+ Enabled: true
168
+
169
+ Style/HashLikeCase: # (new in 0.88)
170
+ Enabled: true
171
+
172
+ Style/HashTransformKeys: # (new in 0.80)
173
+ Enabled: true
174
+
175
+ Style/HashTransformValues: # (new in 0.80)
176
+ Enabled: true
177
+
178
+ Style/KeywordParametersOrder: # (new in 0.90)
179
+ Enabled: true
180
+
181
+ Style/OptionalBooleanParameter: # (new in 0.89)
182
+ Enabled: true
183
+
184
+ Style/RedundantAssignment: # (new in 0.87)
185
+ Enabled: true
186
+
187
+ Style/RedundantFetchBlock: # (new in 0.86)
188
+ Enabled: true
189
+
190
+ Style/RedundantFileExtensionInRequire: # (new in 0.88)
191
+ Enabled: true
192
+
193
+ Style/RedundantRegexpCharacterClass: # (new in 0.85)
194
+ Enabled: true
195
+
196
+ Style/RedundantRegexpEscape: # (new in 0.85)
197
+ Enabled: true
198
+
199
+ Style/RedundantSelfAssignment: # (new in 0.90)
200
+ Enabled: true
201
+
202
+ Style/SingleArgumentDig: # (new in 0.89)
203
+ Enabled: true
204
+
205
+ Style/SlicingWithRange: # (new in 0.83)
206
+ Enabled: true
207
+
208
+ Style/SoleNestedConditional: # (new in 0.89)
209
+ Enabled: true
210
+
211
+ Style/StringConcatenation: # (new in 0.89)
212
+ Enabled: true
@@ -4,6 +4,15 @@ 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
+ ## [2.0.0] - 2020-09-14
8
+ ### Added
9
+ - Start supporting Ruby 2.7.
10
+ - Provide image error details.
11
+ - Raise `UnexpectedError` for unknown recognition error types.
12
+
13
+ ### Removed
14
+ - Support for Ruby 2.3.
15
+
7
16
  ## [1.3.0] - 2019-08-30
8
17
  ### Added
9
18
  - Support a retrying feature on `Scnnr::Connection`.
data/Gemfile CHANGED
@@ -4,7 +4,7 @@ source 'https://rubygems.org'
4
4
 
5
5
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
6
 
7
- gem 'rake', '~> 10.0'
7
+ gem 'rake', '~> 13.0'
8
8
 
9
9
  group :development do
10
10
  gem 'pry', '~> 0.10'
@@ -18,9 +18,8 @@ group :test do
18
18
  gem 'rspec', '~> 3.5'
19
19
  gem 'rspec_junit_formatter', '~> 0.3'
20
20
 
21
- gem 'rubocop', '~> 0.49.0'
22
- gem 'rubocop-junit-formatter', '~> 0.1'
23
- gem 'rubocop-rspec', '~> 1.15.0'
21
+ gem 'rubocop', '~> 0.90.0'
22
+ gem 'rubocop-rspec', '~> 1.43.2'
24
23
 
25
24
  gem 'webmock', '~> 3.0'
26
25
  end
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  - [API Documentation](https://api.scnnr.cubki.jp/v1/docs)
6
6
 
7
7
  ## Supported Ruby versions
8
- - Ruby 2.3+
8
+ - Ruby 2.4+
9
9
 
10
10
  ## Installation
11
11
 
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'scnnr/configuration'
4
4
  require 'scnnr/errors'
5
+ require 'scnnr/errors/image'
6
+ require 'scnnr/errors/image/response'
5
7
  require 'scnnr/label'
6
8
  require 'scnnr/recognition'
7
9
  require 'scnnr/recognition/image'
@@ -40,6 +40,7 @@ module Scnnr
40
40
  def fetch(recognition_id, options = {})
41
41
  options = merge_options options
42
42
  return request(recognition_id, options) if options.delete(:polling) == false
43
+
43
44
  PollingManager.new(options.delete(:timeout)).polling(self, recognition_id, options)
44
45
  end
45
46
 
@@ -4,7 +4,7 @@ module Scnnr
4
4
  Configuration = Struct.new(:api_key, :api_version, :timeout, :logger) do
5
5
  require 'logger'
6
6
 
7
- DEFAULT_LOGGER = Logger.new(STDOUT, level: :info)
7
+ DEFAULT_LOGGER = Logger.new($stdout, level: :info)
8
8
 
9
9
  def initialize
10
10
  super(nil, 'v1', 0, DEFAULT_LOGGER)
@@ -37,9 +37,8 @@ module Scnnr
37
37
  end
38
38
  end
39
39
 
40
- def send_request
41
- block = block_given? ? Proc.new : nil
42
- request = build_request(&block)
40
+ def send_request(&block)
41
+ request = block_given? ? build_request(&block) : build_request
43
42
  with_retries do
44
43
  Net::HTTP.start(@uri.host, @uri.port, use_ssl: use_ssl?) do |http|
45
44
  @logger&.info("Started #{@method.upcase} #{@uri}")
@@ -17,11 +17,12 @@ module Scnnr
17
17
  class RecognitionNotFound < Error; end
18
18
 
19
19
  class RecognitionFailed < Error
20
- attr_accessor :recognition
20
+ attr_accessor :recognition, :image
21
21
 
22
22
  def initialize(recognition)
23
23
  super(recognition.error)
24
24
  @recognition = recognition
25
+ @image = Scnnr::Errors::Image.new(recognition.error['image']) if recognition.error['image']
25
26
  end
26
27
  end
27
28
 
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Scnnr
4
+ module Errors
5
+ class Image
6
+ attr_accessor :url, :response
7
+
8
+ def initialize(attrs)
9
+ @response = Response.new(attrs['response'])
10
+ @url = attrs['url']
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Scnnr
4
+ module Errors
5
+ class Image
6
+ class Response
7
+ attr_accessor :status
8
+
9
+ def initialize(attrs)
10
+ @status = attrs['status']
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -6,6 +6,7 @@ module Scnnr
6
6
 
7
7
  def initialize(response)
8
8
  raise UnexpectedError, response if response.content_type != SUPPORTED_CONTENT_TYPE
9
+
9
10
  @response = response
10
11
  end
11
12
 
@@ -36,7 +37,9 @@ module Scnnr
36
37
  case recognition.error['type']
37
38
  when 'unexpected-content', 'bad-request'
38
39
  raise RequestFailed, recognition.error
39
- else raise RecognitionFailed, recognition
40
+ when 'download-timeout', 'invalid-image', 'download-failed'
41
+ raise RecognitionFailed, recognition
42
+ else raise UnexpectedError, @response
40
43
  end
41
44
  end
42
45
 
@@ -26,9 +26,9 @@ module Scnnr
26
26
  end
27
27
 
28
28
  def path
29
- '/' + [self.path_prefix, @path]
29
+ "/#{[self.path_prefix, @path]
30
30
  .map { |value| value.sub(%r{\A/}, '').sub(%r{/\z}, '') }
31
- .join('/')
31
+ .join('/')}"
32
32
  end
33
33
 
34
34
  private
@@ -36,6 +36,7 @@ module Scnnr
36
36
  def query_string
37
37
  params = self.queries
38
38
  return if params.empty?
39
+
39
40
  params
40
41
  .map { |pair| pair.map { |val| URI.encode_www_form_component val }.join('=') }
41
42
  .join('&')
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Scnnr
4
- VERSION = '1.3.0'
4
+ VERSION = '2.0.0'
5
5
  end
@@ -1,7 +1,6 @@
1
- # coding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
5
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
5
  require 'scnnr/version'
7
6
 
@@ -23,5 +22,7 @@ Gem::Specification.new do |spec|
23
22
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
24
23
  spec.require_paths = ['lib']
25
24
 
26
- spec.add_development_dependency 'bundler', '~> 1.15'
25
+ spec.add_development_dependency 'bundler', '~> 2.1'
26
+
27
+ spec.required_ruby_version = '>= 2.4'
27
28
  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: 1.3.0
4
+ version: 2.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: 2019-08-30 00:00:00.000000000 Z
11
+ date: 2020-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.15'
19
+ version: '2.1'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.15'
26
+ version: '2.1'
27
27
  description: 'Official #CBK scnnr client library for Ruby.'
28
28
  email:
29
29
  - support@newrope.biz
@@ -52,6 +52,8 @@ files:
52
52
  - lib/scnnr/coordinate.rb
53
53
  - lib/scnnr/coordinate/item.rb
54
54
  - lib/scnnr/errors.rb
55
+ - lib/scnnr/errors/image.rb
56
+ - lib/scnnr/errors/image/response.rb
55
57
  - lib/scnnr/label.rb
56
58
  - lib/scnnr/polling_manager.rb
57
59
  - lib/scnnr/recognition.rb
@@ -75,14 +77,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
77
  requirements:
76
78
  - - ">="
77
79
  - !ruby/object:Gem::Version
78
- version: '0'
80
+ version: '2.4'
79
81
  required_rubygems_version: !ruby/object:Gem::Requirement
80
82
  requirements:
81
83
  - - ">="
82
84
  - !ruby/object:Gem::Version
83
85
  version: '0'
84
86
  requirements: []
85
- rubygems_version: 3.0.3
87
+ rubygems_version: 3.0.1
86
88
  signing_key:
87
89
  specification_version: 4
88
90
  summary: ''