active_campaign_wrapper 0.6.0 → 0.7.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: 550a77cc8d3977f538a43b652e7b718abea6aa83759b30551eac82a0ec914e1c
4
- data.tar.gz: f96a647161149950034b3912ad91e044081925b4b07f7791c23569e86c2a9f28
3
+ metadata.gz: a01f4281b5de081432bbaf0da09354d81f7ddbe869e84412ff814626328b9416
4
+ data.tar.gz: 8a77c02c292757bb1be2f53fe8fcaa07465400cb959cfc85e1025b7041797e97
5
5
  SHA512:
6
- metadata.gz: 11f14ca8ced5c3466fa3e10ff920bb6aec46e7b2301feb2a83b8b059df096dadb274c83df4ba00cd91a6d6e600a63dc0126f003c47ab1a280ef5a89769f9d062
7
- data.tar.gz: 5a90300b674ef5ed4aab05a99e87c4aae054d774ab2c9f537eccb6396ce0e3658b668b60629ef212e079c7568dff7b3de875900a1748b47d59e4674acfb7b574
6
+ metadata.gz: 3365e49ae4c44429254d3e1efea35a68b3593818931bf438117827b59aa3aade3ac982ce90f2bca797e4f560abd5deda80105a4176cc2abce3ca3a9e626dec41
7
+ data.tar.gz: fc94fb2186455e6377c43c607dbf3514f895d463b3fffe51f769326580cbfdb508a2504aceae08565594b977c60f647d4c1a2ddd12cd9e6246d829de9f3fe659
@@ -15,13 +15,20 @@ module ActiveCampaignWrapper
15
15
  end
16
16
  end
17
17
 
18
- class Error < StandardError; end
18
+ class Error < StandardError
19
+ attr_accessor :response
19
20
 
20
- class Forbidden < StandardError; end
21
+ def initialize(response)
22
+ super
23
+ @response = response
24
+ end
25
+ end
26
+
27
+ class Forbidden < Error; end
21
28
 
22
- class UnprocessableEntity < StandardError; end
29
+ class UnprocessableEntity < Error; end
23
30
 
24
- class NotFound < StandardError; end
31
+ class NotFound < Error; end
25
32
 
26
- class TooManyRequests < StandardError; end
33
+ class TooManyRequests < Error; end
27
34
  end
@@ -7,11 +7,7 @@ module ActiveCampaignWrapper
7
7
  module_function
8
8
 
9
9
  def normalize_response(response)
10
- raise ActiveCampaignWrapper::Forbidden, response['message'] if response.forbidden?
11
- raise ActiveCampaignWrapper::NotFound, response['message'] if response.not_found?
12
- raise ActiveCampaignWrapper::UnprocessableEntity, response['errors']&.join(', ') || response['error'] if response.unprocessable_entity?
13
- raise ActiveCampaignWrapper::TooManyRequests, response['message'] if response.too_many_requests?
14
- raise ActiveCampaignWrapper::Error, response['message'] unless response.success?
10
+ handle_errors(response)
15
11
 
16
12
  if response&.body.present?
17
13
  transform_keys(response, [:underscore])
@@ -87,5 +83,24 @@ module ActiveCampaignWrapper
87
83
  end
88
84
  end
89
85
  end
86
+
87
+ def handle_errors(response)
88
+ return if response.success?
89
+
90
+ class_name = if response.forbidden?
91
+ ActiveCampaignWrapper::Forbidden
92
+ elsif response.not_found?
93
+ ActiveCampaignWrapper::NotFound
94
+ elsif response.unprocessable_entity?
95
+ ActiveCampaignWrapper::UnprocessableEntity
96
+ elsif response.too_many_requests?
97
+ ActiveCampaignWrapper::TooManyRequests
98
+ else
99
+ ActiveCampaignWrapper::Error
100
+ end
101
+ raise class_name.new(response),
102
+ response['message'] || response['errors'].join(', ') || response['error'],
103
+ caller
104
+ end
90
105
  end
91
106
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveCampaignWrapper
4
- VERSION = '0.6.0'
4
+ VERSION = '0.7.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_campaign_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anmol Yousaf
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-25 00:00:00.000000000 Z
11
+ date: 2021-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport