tinplate 2.1.0 → 2.1.3

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
- SHA1:
3
- metadata.gz: cd4d09eedc78227f59705e1178ce27d024270fe2
4
- data.tar.gz: ac0c1b55d669aad4ca94b24cfec7802aae73ed33
2
+ SHA256:
3
+ metadata.gz: c1ace4f94bd8263a1891dfb2f30e01a43562e3f1e9bf62cc9ea5bb470d6c05c9
4
+ data.tar.gz: 245d673949dee9932b2b41f35251c781576398cccf8b89b067278b8e6530346b
5
5
  SHA512:
6
- metadata.gz: 87de49e77f7b78d21a613390a47443e1b6b44602b64f0faf2fb6dd8dacb184e91b0dc5319f9e47eb4c2dd0f4ce1c76ddf13f08a3927a82652a2684830abf5184
7
- data.tar.gz: e1496130dcde0c1484a2adba0f989fe6a6cf087be4c915aaa59ca81d474d7ca3c07bb67c938a9a3773f86b87ee32d5b55056735b5c6a17e927288359ebf82d37
6
+ metadata.gz: eb5c81720a9d1809323ccb83a4a93c245a2bfb9bccca3b905e1c73748d1292a9afaa1fcd31dd0453aa2bc92fc11dc50ed7e61ae19ac86563337134660fb8f261
7
+ data.tar.gz: 2b4ab575b33057c1b4342ea633bd6931494d25ff3e662eba751036bab315d6b277dd1df6aff126875e44bc50e750dbabaf590f9b953c27991b532139da6a2946
@@ -1,20 +1,36 @@
1
1
  module Tinplate
2
2
  class Error < StandardError
3
- def self.from_response(code, type, message)
4
- klass = case message
5
- when /503 Service Unavailable/ then Tinplate::ServiceUnavailableError
6
- when /service is busy due to high load/ then Tinplate::ServiceUnavailableError
7
- when /Image too simple/ then Tinplate::NoSignatureError
8
- when /purchase another bundle/ then Tinplate::NoCreditsRemainingError
9
- else
10
- Tinplate::Error
11
- end
3
+ def self.from_response(code, messages)
4
+ return UnauthorizedError.new(messages.first) if code == 403
12
5
 
13
- klass.new(message)
6
+ messages.each do |message|
7
+ klass = class_from_message(message)
8
+ return klass.new(messages.join("\n")) if klass
9
+ end
10
+
11
+ Tinplate::Error.new(messages.join("\n"))
12
+ end
13
+
14
+ def self.class_from_message(message)
15
+ case message
16
+ when /503 Service Unavailable/ then Tinplate::ServiceUnavailableError
17
+ when /service is busy due to high load/ then Tinplate::ServiceUnavailableError
18
+ when /Image too simple/ then Tinplate::NoSignatureError
19
+ when /purchase another bundle/ then Tinplate::NoCreditsRemainingError
20
+ when /Could not download/ then Tinplate::InaccessibleURLError
21
+ when /Please supply an image/ then Tinplate::InvalidSearchError
22
+ when /Error reading image data/ then Tinplate::InvalidImageDataError
23
+ when /Too many concurrent requests/ then Tinplate::TooManyRequestsError
24
+ end
14
25
  end
15
26
  end
16
27
 
17
28
  class ServiceUnavailableError < Error; end
18
29
  class NoSignatureError < Error; end
19
30
  class NoCreditsRemainingError < Error; end
20
- end
31
+ class UnauthorizedError < Error; end
32
+ class InaccessibleURLError < Error; end
33
+ class InvalidSearchError < Error; end
34
+ class InvalidImageDataError < Error; end
35
+ class TooManyRequestsError < Error; end
36
+ end
@@ -55,7 +55,7 @@ module Tinplate
55
55
  response = ::JSON.parse(response.body)
56
56
 
57
57
  if response["code"] != 200
58
- raise Tinplate::Error.from_response(response["code"], response["messages"][0], response["messages"][1])
58
+ raise Tinplate::Error.from_response(response["code"], response["messages"])
59
59
  end
60
60
 
61
61
  response
@@ -1,3 +1,3 @@
1
1
  module Tinplate
2
- VERSION = "2.1.0"
2
+ VERSION = "2.1.3"
3
3
  end
data/lib/tinplate.rb CHANGED
@@ -4,7 +4,6 @@ require "json"
4
4
  require "tinplate/version"
5
5
  require "tinplate/configuration"
6
6
  require "tinplate/tineye"
7
- require "tinplate/request_authenticator"
8
7
  require "tinplate/search_results"
9
8
  require "tinplate/errors"
10
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tinplate
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Klaassen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-12 00:00:00.000000000 Z
11
+ date: 2022-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -128,8 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  - !ruby/object:Gem::Version
129
129
  version: '0'
130
130
  requirements: []
131
- rubyforge_project:
132
- rubygems_version: 2.4.8
131
+ rubygems_version: 3.1.4
133
132
  signing_key:
134
133
  specification_version: 4
135
134
  summary: A wrapper around the TinEye API.