lib/bumeran.rb in bumeran-0.3.2 vs lib/bumeran.rb in bumeran-0.3.3
- old
+ new
@@ -57,10 +57,11 @@
@@estados_estudio = {}
@@tipos_estudio = {}
@@direcciones = {}
@@denominaciones = {}
+ @@try_counter = 0
# Default way to setup Bumeran.
def self.setup
yield self
@@ -81,14 +82,22 @@
login
@@options = { query: {access_token: @@access_token} }
end
end
+ def self.invalidate_access_token!
+ @@access_token = nil
+ end
+ def self.revalidate_access_token
+ Bumeran.invalidate_access_token!
+ Bumeran.initialize
+ end
+
def self.has_valid_access_token?
- if @@access_token_updated_at && @@expires_in
- (Time.now < @@access_token_updated_at + @@expires_in)
+ if @@access_token && @@access_token_updated_at && @@expires_in
+ (Time.now < @@access_token_updated_at + @@expires_in.seconds + 10.seconds)
else
false
end
end
@@ -607,10 +616,11 @@
case response.code
when 200..201
# "All good!"
return response.body
when 401
+ self.invalidate_access_token!
raise "Error 401: Unauthorized. Check login info.\n #{response.body}"
when 403
raise "Error 403: Forbidden"
when 404
raise "Error 404 not found"
@@ -626,9 +636,10 @@
case response.code
when 200..201
# "All good!"
return JSON.parse(response.body)
when 401
+ self.invalidate_access_token!
raise "Error 401: Unauthorized. Check login info.\n #{response.body}"
when 403
raise "Error 403: Forbidden"
when 404
raise "Error 404 not found"