zaikio-client-helpers 0.1.1 → 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
  SHA256:
3
- metadata.gz: 5f9d6f6f113ac843f051aa75868b818e5d61320f593f134b40355dcf453f27dd
4
- data.tar.gz: 39fbcef434b1bdc0b6dd9a9116d0213a14ffb4cc92252c790ffb451656eade15
3
+ metadata.gz: 363d6b961f22895db699c5ee54243f515cc79845c95784958e66e72f58f568bd
4
+ data.tar.gz: 442e1e463e845d525829d908866d6f26fd48e9b4dfd3ba8a7927bd19d53b442c
5
5
  SHA512:
6
- metadata.gz: a84a8904648fc53c027e645cf687e503667075cadc244bc31f5c988b2ce1573ea6fdf8e1b586b5abbb013b9ae96259d8c3f837481981b91056d067933869576b
7
- data.tar.gz: 1136f7ce6cdd6da736c344c27beafb7ed5c275b95a4d993844c3e93f7e8f10b704b663e1b4446f7d7584eae7dc9896d2be79f2caebc66b8fa2933d1db94dd10b
6
+ metadata.gz: 4e9319b55e7e03a9ea0d13958ad0df34bfd1d92c832e5ef8669e0fc02933a60495069997f253e7cd1651f716d985fab00164b8305f71bc68998de481ec171c3d
7
+ data.tar.gz: 0e45c6d37c8ec0065b805c60e5f419a01a47673d988aaf36940d252b0df709609c3009f173ad0da5e97f947caadb6bb1be90ff0549e197d62e28a2f1981be108
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2021-07-22
4
+
5
+ - Add `Zaikio:Error` and allow setting arbitrary attributes on the exceptions
6
+ - Add `Zaikio::RateLimitedError` when HTTP 429 occurs (note that this subclasses
7
+ `Zaikio::ConnectionError` so all existing error handling should continue to work).
8
+
3
9
  ## [0.1.1] - 2021-06-18
4
10
 
5
11
  - Require `zaikio/client/model` as part of gem loading to avoid need to load it elsewhere
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "zaikio/client/helpers/version"
4
4
 
5
+ require_relative "zaikio/error"
5
6
  require_relative "zaikio/client/model"
6
7
  require_relative "zaikio/client/helpers/json_parser"
7
8
  require_relative "zaikio/client/helpers/pagination"
@@ -4,15 +4,21 @@ require "multi_json"
4
4
  module Zaikio::Client::Helpers
5
5
  class JSONParser < Faraday::Response::Middleware
6
6
  def on_complete(env)
7
- connection_error(env) unless /^(2\d\d)|422|404$/.match?(env.status.to_s)
8
-
9
- raise Spyke::ResourceNotFound if env.status.to_s == "404"
10
-
11
- env.body = parse_body(env.body)
7
+ case env.status
8
+ when 404 then raise Spyke::ResourceNotFound.new(nil, url: env.url)
9
+ when 429 then raise Zaikio::RateLimitedError.new(nil, url: env.url)
10
+ when (200..299), 422 then env.body = parse_body(env.body)
11
+ else connection_error(env)
12
+ end
12
13
  end
13
14
 
14
15
  def connection_error(env)
15
- raise Spyke::ConnectionError, "Status: #{env.status}, URL: #{env.url}, body: #{env.body}"
16
+ raise Spyke::ConnectionError.new(
17
+ "Status: #{env.status}, URL: #{env.url}, body: #{env.body}",
18
+ status: env.status,
19
+ url: env.url,
20
+ body: env.body
21
+ )
16
22
  end
17
23
 
18
24
  def parse_body(body)
@@ -3,7 +3,7 @@
3
3
  module Zaikio
4
4
  module Client
5
5
  module Helpers
6
- VERSION = "0.1.1"
6
+ VERSION = "0.2.0"
7
7
  end
8
8
  end
9
9
  end
@@ -0,0 +1,31 @@
1
+ module Zaikio
2
+ class Error < StandardError
3
+ def initialize(message = nil, **opts)
4
+ super(message)
5
+
6
+ opts.each do |key, value|
7
+ ivar = "@#{key}".to_sym
8
+ instance_variable_set(ivar, value)
9
+ define_singleton_method(key) { instance_variable_get(ivar) }
10
+ end
11
+ end
12
+ end
13
+
14
+ class ResourceNotFound < Zaikio::Error; end
15
+
16
+ class ConnectionError < Zaikio::Error; end
17
+ class RateLimitedError < ConnectionError; end
18
+ end
19
+
20
+ require "spyke"
21
+
22
+ module Spyke
23
+ instance_eval do
24
+ # avoid warning: already initialized constant
25
+ remove_const("ConnectionError")
26
+ remove_const("ResourceNotFound")
27
+ end
28
+
29
+ ConnectionError = Class.new Zaikio::ConnectionError
30
+ ResourceNotFound = Class.new Zaikio::ResourceNotFound
31
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zaikio-client-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zaikio GMBH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-29 00:00:00.000000000 Z
11
+ date: 2021-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -96,6 +96,7 @@ files:
96
96
  - lib/zaikio/client/helpers/pagination.rb
97
97
  - lib/zaikio/client/helpers/version.rb
98
98
  - lib/zaikio/client/model.rb
99
+ - lib/zaikio/error.rb
99
100
  homepage: https://github.com/zaikio/zaikio-client-helpers
100
101
  licenses:
101
102
  - MIT