zaikio-client-helpers 0.1.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3409eab2392246cb7990f31dff3d24b47fa8616b150ad217ed0bb5a7f89607a9
4
- data.tar.gz: cefdc3ec682204a0552484e0d37ad06dda3449ff05c0ec00637aa4b85c695415
3
+ metadata.gz: b04e37308c3d4d671262df75c9e71a56feccfa2ecbddd561a5c495d9bb08116c
4
+ data.tar.gz: f9cd398097d4e20637398ce37bf75cd035d52385f6beafb58d32c8d787ac50b5
5
5
  SHA512:
6
- metadata.gz: a0b859d93659e155556e14c36b66b7ab2fbadcea7922f226b431e34d13668104144441239de59656055f321b92d84fc246ce1fe60f295f82d57a5f5879d7360a
7
- data.tar.gz: e420427ff71df44f79ef37fa59ccb54a22c2becf3863021ce80b2a3164806c8336c0701ce0809f7571e9e7efd5c66dac07829adf861e15e4410900ac0632ac0f
6
+ metadata.gz: 41d8e99d08d8dc5bc2f6cfcb247285857222a830ac74a73da9339cd293aedf43fdcd0ac74a9fb4d08479028c7a34956c1afb00406a7655e33769fbca39132a47
7
+ data.tar.gz: '08baf07f1cee0553900681da973abd696ab9f12b40c4dd03d8df46fb27402d20716721dd537908b77c14993e9b0ca5f59fe798ca0ae8f8cf00562cee2f8ac41a'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.2] - 2021-08-12
4
+
5
+ - Attempt to fix `NoMethodError` when looking for pagination headers
6
+
7
+ ## [0.2.1] - 2021-08-05
8
+
9
+ - Fixed `with_fallback` from spyke by aliasing the correct error classes
10
+
11
+ ## [0.2.0] - 2021-07-22
12
+
13
+ - Add `Zaikio:Error` and allow setting arbitrary attributes on the exceptions
14
+ - Add `Zaikio::RateLimitedError` when HTTP 429 occurs (note that this subclasses
15
+ `Zaikio::ConnectionError` so all existing error handling should continue to work).
16
+
17
+ ## [0.1.1] - 2021-06-18
18
+
19
+ - Require `zaikio/client/model` as part of gem loading to avoid need to load it elsewhere
20
+ - Fix message about total number of pages - count pages, not objects!
21
+
3
22
  ## [0.1.0] - 2021-06-17
4
23
 
5
24
  - Initial release
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "zaikio/client/helpers/version"
4
+
5
+ require_relative "zaikio/error"
6
+ require_relative "zaikio/client/model"
4
7
  require_relative "zaikio/client/helpers/json_parser"
5
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)
@@ -63,7 +63,7 @@ module Zaikio::Client::Helpers
63
63
  class Relation < Spyke::Relation
64
64
  HEADERS.each_key do |symbol|
65
65
  define_method(symbol) do
66
- find_some.metadata[METADATA_KEY][symbol]
66
+ find_some.metadata.dig(METADATA_KEY, symbol)
67
67
  end
68
68
  end
69
69
 
@@ -97,7 +97,7 @@ module Zaikio::Client::Helpers
97
97
  find_some.each(&block)
98
98
  return if !supports_pagination? || last_page?
99
99
 
100
- puts "There are #{total_count} pages, I will load more pages automatically" if first_page?
100
+ puts "There are #{total_pages} pages, I will load more pages automatically" if first_page?
101
101
  clone.page(next_page).each(&block)
102
102
  end
103
103
 
@@ -3,7 +3,7 @@
3
3
  module Zaikio
4
4
  module Client
5
5
  module Helpers
6
- VERSION = "0.1.0"
6
+ VERSION = "0.2.2"
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 = Zaikio::ConnectionError
30
+ ResourceNotFound = 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.0
4
+ version: 0.2.2
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-18 00:00:00.000000000 Z
11
+ date: 2021-08-13 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
@@ -111,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
112
  requirements:
112
113
  - - ">="
113
114
  - !ruby/object:Gem::Version
114
- version: '0'
115
+ version: '2.3'
115
116
  required_rubygems_version: !ruby/object:Gem::Requirement
116
117
  requirements:
117
118
  - - ">="