lib/cheetahmails.rb in cheetahmails-0.0.2 vs lib/cheetahmails.rb in cheetahmails-0.0.3

- old
+ new

@@ -10,16 +10,19 @@ end def self.get_token(clear_cache = false) tries ||= 2 - redis = Redis.new(Cheetahmails.configuration.redis) + begin + redis = Redis.new(Cheetahmails.configuration.redis) + redis.del "cheetahmails_access_token" if clear_cache + token = redis.get("cheetahmails_access_token") + rescue => error + end - redis.del "cheetahmails_access_token" if clear_cache + if not token - if not token = redis.get("cheetahmails_access_token") - faraday = Faraday.new(:url => @base_uri) do |faraday| faraday.request :url_encoded # form-encode POST params #faraday.response :logger # log requests to STDOUT faraday.adapter Faraday.default_adapter # make requests with Net::HTTP end @@ -39,11 +42,14 @@ rescue JSON::ParserError => error raise response.status.to_s + " " + response.body end if token = jsonresponse["access_token"] - redis.set("cheetahmails_access_token", token) - redis.expire("cheetahmails_access_token", jsonresponse["expires_in"]) + begin + redis.set("cheetahmails_access_token", token) + redis.expire("cheetahmails_access_token", jsonresponse["expires_in"]) + rescue => error + end end end token