scnnr 0.1.0 → 0.2.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: 7d5ce96021afa8ae437e4a7b23cdb7018bfc0202
4
- data.tar.gz: e06b41c303d7f2949b8ac542454e6e40ffa77ed3
3
+ metadata.gz: 63bcc0cea5fbfb536f2ebd9b87623f7ec943b68e
4
+ data.tar.gz: 295d5b100e0cd86ffcaaad0e815f28276c063597
5
5
  SHA512:
6
- metadata.gz: ea14db49ec5b7f1e671444ef7715015030133c4b4e2eaa533bb8bb6c66539db2beb20280725e47f3948178c6ff24094e430558edece68868a432de258fdac124
7
- data.tar.gz: 005662bd30ebb39ad6065b2208b24c7c8301cd04123cf17b3175e7cd4bc1dee0501dd88250244e788073c4e561bc8af5e5cea71863176fbfbe91a54c27852242
6
+ metadata.gz: 5659d4858fdce6480279c9d988f61813ccfd852c7eba5e366913ec4d7583d5eccd14f19182d54032f0eb91bb1eb0f1bdb1e1a524f8b7b36713c3121aab3db46b
7
+ data.tar.gz: 9880c8a857b3bd38ec11bd19c4b80d73a9f242cea72585ddc9f6108897f6be63890ccbda5e6306c45b2136a43bbc3196571feec63b90dce900ea5ca3e21e37e1
data/CHANGELOG.md ADDED
@@ -0,0 +1,20 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [0.2.0] - 2017-10-20
8
+ ### Added
9
+ - Add reference links to README.
10
+
11
+ ### Fixed
12
+ - Fix the client specs to make them easier to understand.
13
+ - Fix to handle `unexpected-content` and `bad-request` API errors.
14
+
15
+ ### Changed
16
+ - Rename `UnsupportedError` -> `UnexpectedError`.
17
+
18
+ ## [0.1.0] - 2017-09-21
19
+ ### Added
20
+ - Initial release of scnnr-ruby.
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Official #CBK scnnr client library for Ruby.
2
2
 
3
+ - [#CBK scnnr](https://scnnr.cubki.jp/)
4
+ - [API Documentation](https://api.scnnr.cubki.jp/v1/docs)
5
+
3
6
  ## Installation
4
7
  ### Bundler
5
8
  ```
@@ -113,15 +116,15 @@ rescue Scnnr::RecognitionFailed => e
113
116
  # Failed to recognize the image you requested.
114
117
  recognition = e.recognition
115
118
  recognition.error? # => true
116
- STDERR.puts "[ERROR] #{e.title}: #{e.detail} (e.type)"
119
+ STDERR.puts "[ERROR] #{e.title}: #{e.detail} #{e.type}"
117
120
  rescue Scnnr::RequestFailed => e
118
121
  # Failed to reserve the recognition.
119
122
  # This kind of errors have no `#recognition` field.
120
- STDERR.puts "[ERROR] #{e.title}: #{e.detail} (e.type)"
123
+ STDERR.puts "[ERROR] #{e.title}: #{e.detail} #{e.type}"
121
124
  rescue Scnnr::RecognitionNotFound => e
122
125
  # Failed to find the recognition with the specified ID.
123
126
  # This kind of errors have no `#recognition` field.
124
- STDERR.puts "[ERROR] #{e.title}: #{e.detail} (e.type)"
127
+ STDERR.puts "[ERROR] #{e.title}: #{e.detail} #{e.type}"
125
128
  rescue => e
126
129
  # Unexpected error.
127
130
  raise
data/lib/scnnr/errors.rb CHANGED
@@ -4,8 +4,8 @@ module Scnnr
4
4
  class Error < StandardError
5
5
  attr_accessor :detail, :title, :type
6
6
 
7
- def initialize(message, attrs)
8
- super(message)
7
+ def initialize(attrs)
8
+ super(attrs['detail'])
9
9
  @detail = attrs['detail']
10
10
  @title = attrs['title']
11
11
  @type = attrs['type']
@@ -19,8 +19,8 @@ module Scnnr
19
19
  class RecognitionFailed < Error
20
20
  attr_accessor :recognition
21
21
 
22
- def initialize(message, recognition)
23
- super(message, recognition.error)
22
+ def initialize(recognition)
23
+ super(recognition.error)
24
24
  @recognition = recognition
25
25
  end
26
26
  end
@@ -34,7 +34,7 @@ module Scnnr
34
34
  end
35
35
  end
36
36
 
37
- class UnsupportedError < StandardError
37
+ class UnexpectedError < StandardError
38
38
  attr_accessor :response
39
39
 
40
40
  def initialize(response)
@@ -5,7 +5,7 @@ module Scnnr
5
5
  SUPPORTED_CONTENT_TYPE = 'application/jp.cubki.scnnr.v1+json'
6
6
 
7
7
  def initialize(response, async)
8
- raise UnsupportedError, response if response.content_type != SUPPORTED_CONTENT_TYPE
8
+ raise UnexpectedError, response if response.content_type != SUPPORTED_CONTENT_TYPE
9
9
  @response = response
10
10
  @async = async
11
11
  end
@@ -36,17 +36,22 @@ module Scnnr
36
36
 
37
37
  def handle_recognition(recognition)
38
38
  raise TimeoutError.new('recognition timed out', recognition) if recognition.queued? && async?
39
- raise RecognitionFailed.new('recognition failed', recognition) if recognition.error?
40
- recognition
39
+ return recognition unless recognition.error?
40
+
41
+ case recognition.error['type']
42
+ when 'unexpected-content', 'bad-request'
43
+ raise RequestFailed, recognition.error
44
+ else raise RecognitionFailed, recognition
45
+ end
41
46
  end
42
47
 
43
48
  def handle_error
44
49
  case @response
45
50
  when Net::HTTPNotFound
46
- raise RecognitionNotFound.new('recognition not found', self.parsed_body)
51
+ raise RecognitionNotFound, self.parsed_body
47
52
  when Net::HTTPUnprocessableEntity
48
- raise RequestFailed.new('failed to reserve the recognition', self.parsed_body)
49
- else raise UnsupportedError, @response
53
+ raise RequestFailed, self.parsed_body
54
+ else raise UnexpectedError, @response
50
55
  end
51
56
  end
52
57
  end
data/lib/scnnr/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Scnnr
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.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.1.0
4
+ version: 0.2.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-09-21 00:00:00.000000000 Z
11
+ date: 2017-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -36,6 +36,7 @@ files:
36
36
  - ".circleci/config.yml"
37
37
  - ".gitignore"
38
38
  - ".rubocop.yml"
39
+ - CHANGELOG.md
39
40
  - CODE_OF_CONDUCT.md
40
41
  - Gemfile
41
42
  - LICENSE