easy_meli 0.6.4 → 0.6.5
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/easy_meli.rb +1 -0
- data/lib/easy_meli/api_client.rb +10 -18
- data/lib/easy_meli/authorization_client.rb +3 -1
- data/lib/easy_meli/error_parser.rb +38 -0
- data/lib/easy_meli/errors.rb +48 -0
- data/lib/easy_meli/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 269c22ea4f450792d02935692db9eec8adc207fc8f44c946f1d3f439cce435b1
|
4
|
+
data.tar.gz: 00565d53e5a9e3b40235bce3723ab962d7e3f0a8fb912713330255de90b7980c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f3e5971e80a8a9b73b435186fad527d93e71f0d454208ecf78a412c5716726f28ab0fbc25cca60dc6701422adf089d05ae504a86d3b34efb918ef4ba1685223
|
7
|
+
data.tar.gz: 6f1e0cb4af4919bb9c15fbd15526787c1f13727b870d5b2345a36d67f5e790bd9602eb39fde70dcb137d62856eda5e789c2c3629962fb0c081d5ddc09d4fb738
|
data/CHANGELOG.md
CHANGED
data/lib/easy_meli.rb
CHANGED
data/lib/easy_meli/api_client.rb
CHANGED
@@ -5,15 +5,6 @@ class EasyMeli::ApiClient
|
|
5
5
|
|
6
6
|
API_ROOT_URL = 'https://api.mercadolibre.com'
|
7
7
|
|
8
|
-
ERROR_LIST = {
|
9
|
-
'Error validating grant' => EasyMeli::InvalidGrantError,
|
10
|
-
'The User ID must match the consultant\'s' => EasyMeli::ForbiddenError,
|
11
|
-
'invalid_token' => EasyMeli::InvalidTokenError,
|
12
|
-
'Malformed access_token' => EasyMeli::MalformedTokenError,
|
13
|
-
'too_many_requests' => EasyMeli::TooManyRequestsError,
|
14
|
-
'unknown_error' => EasyMeli::UnknownError
|
15
|
-
}
|
16
|
-
|
17
8
|
base_uri API_ROOT_URL
|
18
9
|
headers EasyMeli::DEFAULT_HEADERS
|
19
10
|
format :json
|
@@ -49,25 +40,26 @@ class EasyMeli::ApiClient
|
|
49
40
|
|
50
41
|
self.class.send(verb, path, params.merge(query)).tap do |response|
|
51
42
|
logger&.log response
|
43
|
+
check_status(response)
|
52
44
|
check_for_errors(response)
|
53
45
|
end
|
54
46
|
end
|
55
47
|
|
56
|
-
def
|
57
|
-
|
58
|
-
|
59
|
-
exception = error_class(response)
|
48
|
+
def check_status(response)
|
49
|
+
exception = EasyMeli::ErrorParser.status_error_class(response)
|
60
50
|
|
61
51
|
if exception
|
62
52
|
raise exception.new(response)
|
63
53
|
end
|
64
54
|
end
|
65
55
|
|
66
|
-
def
|
67
|
-
|
68
|
-
|
56
|
+
def check_for_errors(response)
|
57
|
+
return unless response.parsed_response.is_a?(Hash) && !response.body.nil?
|
58
|
+
|
59
|
+
exception = EasyMeli::ErrorParser.error_class(response)
|
69
60
|
|
70
|
-
|
71
|
-
|
61
|
+
if exception
|
62
|
+
raise exception.new(response)
|
63
|
+
end
|
72
64
|
end
|
73
65
|
end
|
@@ -54,7 +54,9 @@ class EasyMeli::AuthorizationClient
|
|
54
54
|
if response.success?
|
55
55
|
response.to_h[EasyMeli::AuthorizationClient::ACCESS_TOKEN_KEY]
|
56
56
|
else
|
57
|
-
|
57
|
+
exception = EasyMeli::ErrorParser.error_class(response) || EasyMeli::InvalidTokenError
|
58
|
+
|
59
|
+
raise exception.new(response)
|
58
60
|
end
|
59
61
|
end
|
60
62
|
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class EasyMeli::ErrorParser
|
2
|
+
ERROR_LIST = {
|
3
|
+
'Error validating grant' => EasyMeli::InvalidGrantError,
|
4
|
+
'The User ID must match the consultant\'s' => EasyMeli::ForbiddenError,
|
5
|
+
'invalid_token' => EasyMeli::InvalidTokenError,
|
6
|
+
'Malformed access_token' => EasyMeli::MalformedTokenError,
|
7
|
+
'too_many_requests' => EasyMeli::TooManyRequestsError,
|
8
|
+
'unknown_error' => EasyMeli::UnknownError
|
9
|
+
}
|
10
|
+
|
11
|
+
STATUS_ERRORS = {
|
12
|
+
500 => EasyMeli::InternalServerError,
|
13
|
+
501 => EasyMeli::NotImplementedError,
|
14
|
+
502 => EasyMeli::BadGatewayError,
|
15
|
+
503 => EasyMeli::ServiceUnavailableError,
|
16
|
+
504 => EasyMeli::GatewayTimeoutError
|
17
|
+
}
|
18
|
+
|
19
|
+
def self.error_class(response)
|
20
|
+
ERROR_LIST.find { |key, _| self.error_message_from_body(response)&.include?(key) }&.last
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.status_error_class(response)
|
24
|
+
return unless self.server_side_error?(response)
|
25
|
+
|
26
|
+
STATUS_ERRORS[response.code] || EasyMeli::ServerError
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def self.error_message_from_body(response)
|
32
|
+
response['message'].to_s.empty? ? response['error'] : response['message']
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.server_side_error?(response)
|
36
|
+
response.code >= 500
|
37
|
+
end
|
38
|
+
end
|
data/lib/easy_meli/errors.rb
CHANGED
@@ -73,4 +73,52 @@ module EasyMeli
|
|
73
73
|
'Unknown Error'
|
74
74
|
end
|
75
75
|
end
|
76
|
+
|
77
|
+
class ServerError < Error
|
78
|
+
private
|
79
|
+
|
80
|
+
def local_message
|
81
|
+
'Server Error'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class InternalServerError < ServerError
|
86
|
+
private
|
87
|
+
|
88
|
+
def local_message
|
89
|
+
'Internal Server Error'
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class NotImplementedError < ServerError
|
94
|
+
private
|
95
|
+
|
96
|
+
def local_message
|
97
|
+
'Not Implemented'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
class BadGatewayError < ServerError
|
102
|
+
private
|
103
|
+
|
104
|
+
def local_message
|
105
|
+
'Bad Gateway'
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
class ServiceUnavailableError < ServerError
|
110
|
+
private
|
111
|
+
|
112
|
+
def local_message
|
113
|
+
'Service Unavailable'
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
class GatewayTimeoutError < ServerError
|
118
|
+
private
|
119
|
+
|
120
|
+
def local_message
|
121
|
+
'Gateway Timeout'
|
122
|
+
end
|
123
|
+
end
|
76
124
|
end
|
data/lib/easy_meli/version.rb
CHANGED
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.
|
4
|
+
version: 0.6.5
|
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-
|
11
|
+
date: 2021-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -130,6 +130,7 @@ files:
|
|
130
130
|
- lib/easy_meli/authorization_client.rb
|
131
131
|
- lib/easy_meli/configuration.rb
|
132
132
|
- lib/easy_meli/constants.rb
|
133
|
+
- lib/easy_meli/error_parser.rb
|
133
134
|
- lib/easy_meli/errors.rb
|
134
135
|
- lib/easy_meli/version.rb
|
135
136
|
homepage: https://github.com/easybroker/easy_meli
|