me_api 1.1.1 → 1.1.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: a0053dda52f53e3ec1d0e6ed038fae07f180856578dcd23acb78855579967d00
4
- data.tar.gz: 3b100d5d63e339f1bf1793adeeb29434028699d5b6edd3c78d88c44233822bd7
3
+ metadata.gz: e746281011a0287a4789c9e84156710883e3d9a2c8959b4b66efd0b4d0b0c26c
4
+ data.tar.gz: b6601ef3f21c03db8b4b21856715a640fd3b0253024c6bb70738c55a0e2dbf09
5
5
  SHA512:
6
- metadata.gz: 5597d2363cbf9e679357b4ac525a48bb6129f38bfaab70372c38fed05f87782aa2bb4fceec05152f6727e756a265512a0484f7a4c5e9b666659a6f98627a1f75
7
- data.tar.gz: 2adaf13367f5971fa08a654abc7a2c1a8cc88375d9eef3f4557c3612f6cc2bd4eb0f4f7f217b09e8de1241834c29f8c76045f1778a45b78ba3d90d04334e34bd
6
+ metadata.gz: b632c7dc5e2b54c0a9b06fbeb6385d65989bc33c72bd0bbbe5037e82c9522cb3c9e957a17735e0c5d024606a8dff0558b3bd91cde8c4e416beb45a7ac2a2ed95
7
+ data.tar.gz: 3c0ad7affbf4bfdbd032607687df954b94f8059cc44cb97bc0488e86baf37fc19e1ac3a881821b9305c3cc88f239fb3610610510a6106a02e14c029ff74af504
data/lib/me_api/client.rb CHANGED
@@ -33,7 +33,7 @@ module MeApi
33
33
  },
34
34
  "services" => "1,2,3,4,17,33"
35
35
  }
36
- response = post "api/v2/me/shipment/calculate", body: JSON.dump(body)
36
+ response = post("api/v2/me/shipment/calculate", body: JSON.dump(body)) { |response| validate_response(response, [0, "id"]) }
37
37
  response.json.map do |rate|
38
38
  Rate.new(
39
39
  id: rate["id"],
@@ -56,7 +56,7 @@ module MeApi
56
56
  client_secret: client_secret,
57
57
  refresh_token: refresh_token
58
58
  }
59
- post "/oauth/token", body: JSON.dump(body), headers: {"Content-Type": "application/json"}
59
+ post("/oauth/token", body: JSON.dump(body), headers: {"Content-Type": "application/json"}) { |response| validate_response(response, "access_token") }
60
60
  end
61
61
 
62
62
  def authorize client_id:, client_secret:, code:, redirect_url:
@@ -67,7 +67,14 @@ module MeApi
67
67
  code: code,
68
68
  redirect_uri: redirect_url
69
69
  }
70
- post "/oauth/token", body: JSON.dump(body), headers: {"Content-Type": "application/json"}
70
+ post("/oauth/token", body: JSON.dump(body), headers: {"Content-Type": "application/json"}) { |response| validate_response(response, "access_token") }
71
+ end
72
+
73
+ private
74
+
75
+ def validate_response(response, required_response_key)
76
+ puts response.json unless response.success?
77
+ ![500, 429].include?(response.code) || response.json.dig(*required_response_key)
71
78
  end
72
79
  end
73
80
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MeApi
4
- VERSION = "1.1.1"
4
+ VERSION = "1.1.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: me_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todas Essas Coisas