iron_bank 1.0.1 → 1.0.2

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: b28f1d5aa15b643c9c32ef1cb7d71cbf198b6d3fd64bc6a0d06f278c0d9b2c7f
4
- data.tar.gz: fc18d9c747034c470fc767bfea6cd673a81217f31377146818922dd143c3f201
3
+ metadata.gz: db077e1c6186fc1a24bd7d1ae7cf06e6c9c02a85acb8a651e6c5c84e7a3972c7
4
+ data.tar.gz: 84903d8e3515bd8b48b192e32d1cfc6293a7d0c99ea709c4c7106d609db646cd
5
5
  SHA512:
6
- metadata.gz: f6cafda4559dd307315b75c67ee4069487539e97d1321933b4f9a4bb2684ae2f7ecf71144c3aa07cfa2d001d2cb73123c2bcd7f7c17a4d8bd3660f586c886a5b
7
- data.tar.gz: f2ace39fb97f22776b0a2ba80b4dd682cc4229e316ec821c0b0fd8cd41fac8501ce23189bf2c9bb727d07270aa1de1cd170c7ad05ef68f39191e93efdbfff118
6
+ metadata.gz: 8afcf559e8a4a0b7c0a70bb4d8faabf179a394a939c6993ae0cdea76c06a1a5f3bf889201af394169e71b1ee119f394460a7c0e5636084198993e847f7d3f82b
7
+ data.tar.gz: f9aa741b2ea5b469512e5285db6ecf19fc8c63762b4581bdb29e7803b8b53a3a7dbf3d8dc059bd609d219619c5f7d21dd6a35c5e7ec14eaee08effc3b9ed9de4
@@ -11,12 +11,15 @@ module IronBank
11
11
  end
12
12
 
13
13
  def call
14
- IronBank.client.connection.post(endpoint, params).body
14
+ @body = IronBank.client.connection.post(endpoint, params).body
15
+ return body if success?
16
+
17
+ raise ::IronBank::UnprocessableEntity, errors
15
18
  end
16
19
 
17
20
  private
18
21
 
19
- attr_reader :args
22
+ attr_reader :args, :body
20
23
 
21
24
  def initialize(args)
22
25
  @args = args
@@ -30,6 +33,22 @@ module IronBank
30
33
  self.class.name.split('::').last
31
34
  end
32
35
 
36
+ def success?
37
+ response_object.fetch(:success, true)
38
+ end
39
+
40
+ def response_object
41
+ @response_object ||= begin
42
+ return {} unless body.is_a?(Array)
43
+
44
+ ::IronBank::Object.new(body.first).deep_underscore
45
+ end
46
+ end
47
+
48
+ def errors
49
+ { errors: response_object.fetch(:errors, []) }
50
+ end
51
+
33
52
  def requests(type: :upper)
34
53
  args.fetch(:objects).map do |object|
35
54
  IronBank::Object.new(object).deep_camelize(type: type)
@@ -12,6 +12,7 @@ module IronBank
12
12
  case status
13
13
  when 400 then IronBank::BadRequest
14
14
  when 404 then IronBank::NotFound
15
+ when 422 then IronBank::UnprocessableEntity
15
16
  when 429 then IronBank::TooManyRequests
16
17
  when 500 then IronBank::InternalServerError
17
18
  when 400..499 then IronBank::ClientError
@@ -34,6 +35,9 @@ module IronBank
34
35
  # Raised when Zuora returns a 404 HTTP status code
35
36
  class NotFound < ClientError; end
36
37
 
38
+ # Raised when Zuora return 422 and unsuccessful action responses
39
+ class UnprocessableEntity < Error; end
40
+
37
41
  # Raised when Zuora returns a 429 HTTP status code
38
42
  class TooManyRequests < ClientError; end
39
43
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IronBank
4
- VERSION = '1.0.1'
4
+ VERSION = '1.0.2'
5
5
  API_VERSION = 'v1'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iron_bank
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mickael Pham
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2018-10-04 00:00:00.000000000 Z
14
+ date: 2018-10-05 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bump