easy_meli 0.6.1 → 0.6.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: 8c8dc1140d9368b076baf0a49a9742aea8de95565a90512152c9c58ec2b98723
4
- data.tar.gz: 543cbed2c4789b0259b62f11d332a02c3b5b281feb2c5b60c5f87fd8640c0754
3
+ metadata.gz: bc240e7ae7a827cff6460162be1a9460f5e860676f3800a50d18ae3558f2976e
4
+ data.tar.gz: 714503d3e3886b1d491d1ea579d72f1d74e2408d476b9ada5ee6446f0efbb467
5
5
  SHA512:
6
- metadata.gz: c2a7ecfa32beed3a9329b01312b1cfd4ed70fceb26469dc90e8d0d2c3b42186a9c1ec06f115f1dc5fa15236aa48d99b7e074a089fad7f710bddaf2bcb324680a
7
- data.tar.gz: dfc01a8544c0f2d23711888fdfa3fb6a6f6f68196782d41cb501c1f50d53900882fb5c1b8d7a9f88e610eb1fafc8112447943ff87b8793af7fccd29e800a6d17
6
+ metadata.gz: 7004c03b3ec4be44170bb4ea92c5ac2595ddd5d244a7e680a88e67d5bdc9eec0197ae7a7bd0970ac78d0912e42f04b9b44a65ee907e5333db479f569753853b2
7
+ data.tar.gz: 139f426a07c7782b73ea52959283b70e068f8565d9c5e646790cd7f3373b51eed3f3e179d418a72ddf746012c13f4ea735a133c023b59da4c6d8d24aed38ab91
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## V 0.6.2
4
+ - Update Error classification mechanism to use error message as first option
5
+
3
6
  ## V 0.6.1
4
7
  - Fix a bug in the error raising in the authorization client introduced in V 0.6.0
5
8
 
@@ -6,14 +6,11 @@ class EasyMeli::ApiClient
6
6
  API_ROOT_URL = 'https://api.mercadolibre.com'
7
7
 
8
8
  ERROR_LIST = {
9
- 'invalid_grant' => EasyMeli::InvalidGrantError,
9
+ 'Error validating grant' => EasyMeli::InvalidGrantError,
10
10
  'forbidden' => EasyMeli::ForbiddenError,
11
11
  'invalid_token' => EasyMeli::InvalidTokenError,
12
- 'Malformed access_token' => EasyMeli::MalformedTokenError
13
- }
14
-
15
- STATUS_ERRORS = {
16
- 429 => EasyMeli::TooManyRequestsError
12
+ 'Malformed access_token' => EasyMeli::MalformedTokenError,
13
+ 'too_many_requests' => EasyMeli::TooManyRequestsError
17
14
  }
18
15
 
19
16
  base_uri API_ROOT_URL
@@ -51,30 +48,27 @@ class EasyMeli::ApiClient
51
48
 
52
49
  self.class.send(verb, path, params.merge(query)).tap do |response|
53
50
  logger&.log response
54
- check_authentication(response)
55
- check_status(response)
51
+ check_for_errors(response)
56
52
  end
57
53
  end
58
54
 
59
- def check_authentication(response)
60
- response_message = error_message_from_body(response.to_h) if response.parsed_response.is_a? Hash
61
- return if response_message.to_s.empty?
55
+ def check_for_errors(response)
56
+ return unless response.parsed_response.is_a? Hash
62
57
 
63
- ERROR_LIST.keys.each do |key|
64
- if response_message.include?(key)
65
- exception = ERROR_LIST[key]
66
- raise exception.new(response)
67
- end
58
+ exception = error_class(response)
59
+
60
+ if exception
61
+ raise exception.new(response)
68
62
  end
69
63
  end
70
64
 
71
- def error_message_from_body(body)
72
- return if body.nil?
73
- body['error'].to_s.empty? ? body['message'] : body['error']
65
+ def error_class(body)
66
+ ERROR_LIST.find { |key, _| error_message_from_body(body).include?(key) }&.last
74
67
  end
75
68
 
76
- def check_status(response)
77
- status_error = STATUS_ERRORS[response.code]
78
- raise status_error.new(response) if status_error
69
+ def error_message_from_body(response)
70
+ return if response.body.nil?
71
+
72
+ response['message'].to_s.empty? ? response['error'] : response['message']
79
73
  end
80
74
  end
@@ -1,3 +1,3 @@
1
1
  module EasyMeli
2
- VERSION = "0.6.1"
2
+ VERSION = "0.6.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_meli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Northam
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-27 00:00:00.000000000 Z
11
+ date: 2021-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty