easy_meli 0.5.0 → 0.6.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: d5a3424202e135a649e069fb9381c26e7e6760d9e387821c3e7f2f0358ec4f58
4
- data.tar.gz: f947be600fd5c1654b7c920c630f1e916edf58a0c8244c5d5a83def1a2fec288
3
+ metadata.gz: 9e8de8ae979d9da175327ba9238ceabac72a6276f0e51a9d6a99fb35040f50f8
4
+ data.tar.gz: 613fa5048c19460f7b209552ea9d314e222f43092b9780a6f09eff6a10b07314
5
5
  SHA512:
6
- metadata.gz: 0fb2a5a757c53a87aa5fa77a24a203ae65ab58ca7c979bba04a358df8dd78459e01395f36314c399b33beb15fc03d37b4945ff937c5b19b4281190e098d7910e
7
- data.tar.gz: 76a41f9314e945a4ce0846f922d7fb3e9f2d0937a0f74094fc03b52927b105dfa48fb4cc7898f9baff6d850988f8a1d156ef105ebfd54607b498dbc688fd8372
6
+ metadata.gz: b19390ec2c0d7f62de4d2a7b57647d565c82047a3ac094c27b1ae136128d8efaceb442bd23fa22d281003969c7ace0753c844c2d78b0cc042024d36669c1abda
7
+ data.tar.gz: 57325bba54d582992def8dd90ddaff390588b8cd400bdbaa3299803be7639f4e1520c08e5a1d226f0266decb54812650b096b39ebfa4a43908263521ac68ec92
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## V 0.6.0
4
+ - Classify an `invalid_token` response as an `InvalidTokenError`.
5
+ - `Malformed access_token` error changed from `AuthenticationError` to `InvalidTokenError`.
6
+
3
7
  ## V 0.5.0
4
8
  - `self.api_client` Prevent access_token override when initialize together with a refresh_token.
5
9
  - Raises a EasyMeli::TooManyRequestsError if a 429 response status is returned.
data/README.md CHANGED
@@ -42,16 +42,16 @@ response = EasyMeli.create_token('the_code_in_the_redirect', 'the_same_redirect_
42
42
  ```
43
43
  This will return a response object with a json body that you can easily access via `response.to_h`.
44
44
 
45
- If you want to refresh the token call
45
+ If you want to refresh the token call
46
46
 
47
47
  ```ruby
48
- access_token = EasyMeli.refresh_token('a_refresh_token')
48
+ access_token = EasyMeli.access_token('a_refresh_token')
49
49
  ```
50
50
 
51
51
  Once you can have an access token you can create a client and call the supported http verb methods.
52
52
 
53
53
  ```ruby
54
- client = EasyMeli.api_client(refresh_token: refresh_token)
54
+ client = EasyMeli.api_client(access_token: access_token)
55
55
 
56
56
  client.get(path, query: { a: 1 })
57
57
  client.post(path, query: { a: 1 }, body: { b: 1 })
@@ -5,17 +5,18 @@ class EasyMeli::ApiClient
5
5
 
6
6
  API_ROOT_URL = 'https://api.mercadolibre.com'
7
7
 
8
- TOKEN_ERRORS = {
9
- 'invalid_grant' => 'Invalid Grant',
10
- 'forbidden' => 'Forbidden',
11
- 'Malformed access_token' => 'Malformed access token'
8
+ ERROR_LIST = {
9
+ 'invalid_grant' => EasyMeli::InvalidGrantError,
10
+ 'forbidden' => EasyMeli::ForbiddenError,
11
+ 'invalid_token' => EasyMeli::InvalidTokenError,
12
+ 'Malformed access_token' => EasyMeli::MalformedTokenError
12
13
  }
13
14
 
14
15
  STATUS_ERRORS = {
15
16
  429 => EasyMeli::TooManyRequestsError
16
17
  }
17
18
 
18
- base_uri API_ROOT_URL
19
+ base_uri API_ROOT_URL
19
20
  headers EasyMeli::DEFAULT_HEADERS
20
21
  format :json
21
22
 
@@ -59,9 +60,10 @@ class EasyMeli::ApiClient
59
60
  response_message = error_message_from_body(response.to_h) if response.parsed_response.is_a? Hash
60
61
  return if response_message.to_s.empty?
61
62
 
62
- TOKEN_ERRORS.keys.each do |key|
63
+ ERROR_LIST.keys.each do |key|
63
64
  if response_message.include?(key)
64
- raise EasyMeli::AuthenticationError.new(TOKEN_ERRORS[key], response)
65
+ exception = ERROR_LIST[key]
66
+ raise exception.new(response)
65
67
  end
66
68
  end
67
69
  end
@@ -2,17 +2,59 @@ module EasyMeli
2
2
  class Error < StandardError
3
3
  attr_reader :response
4
4
 
5
- def initialize(message, response)
5
+ def initialize(response)
6
6
  @response = response
7
- super(message)
7
+ super(local_message)
8
+ end
9
+
10
+ private
11
+
12
+ def local_message
13
+ raise NotImplementedError
8
14
  end
9
15
  end
10
16
 
11
17
  class AuthenticationError < Error; end
12
-
18
+
19
+ class InvalidGrantError < AuthenticationError
20
+ private
21
+
22
+ def local_message
23
+ 'Invalid Grant'
24
+ end
25
+ end
26
+
27
+ class ForbiddenError < AuthenticationError
28
+ private
29
+
30
+ def local_message
31
+ 'Forbidden'
32
+ end
33
+ end
34
+
35
+ class AccessTokenError < Error; end
36
+
37
+ class InvalidTokenError < AccessTokenError
38
+ private
39
+
40
+ def local_message
41
+ 'Invalid Token'
42
+ end
43
+ end
44
+
45
+ class MalformedTokenError < AccessTokenError
46
+ private
47
+
48
+ def local_message
49
+ 'Malformed access token'
50
+ end
51
+ end
52
+
13
53
  class TooManyRequestsError < Error
14
- def initialize(response)
15
- super('Too many requests', response)
54
+ private
55
+
56
+ def local_message
57
+ 'Too many requests'
16
58
  end
17
59
  end
18
- end
60
+ end
@@ -1,3 +1,3 @@
1
1
  module EasyMeli
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
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.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Northam
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-18 00:00:00.000000000 Z
11
+ date: 2021-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -108,7 +108,7 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- description:
111
+ description:
112
112
  email:
113
113
  - eric@northam.us
114
114
  executables: []
@@ -136,7 +136,7 @@ licenses:
136
136
  - MIT
137
137
  metadata:
138
138
  homepage_uri: https://github.com/easybroker/easy_meli
139
- post_install_message:
139
+ post_install_message:
140
140
  rdoc_options: []
141
141
  require_paths:
142
142
  - lib
@@ -151,8 +151,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  requirements: []
154
- rubygems_version: 3.0.3
155
- signing_key:
154
+ rubygems_version: 3.1.4
155
+ signing_key:
156
156
  specification_version: 4
157
157
  summary: A simple gem to work with MercadoLibre's API
158
158
  test_files: []