class FlagsEvaluation
Public Class Methods
cached(token, user_id)
click to toggle source
# File lib/flags_sdk_ort.rb, line 24 def FlagsEvaluation.cached(token, user_id) print_if_verbose("Check if value was previously cached") if @@cache[token] != nil && @@cache[token][user_id] != nil print_if_verbose("The result was cached, checking if value has not expired (<= 120 seconds)") current_date = DateTime.now _, old_date = @@cache[token][user_id] elapsed_seconds = ((current_date - old_date) * 24 * 60 * 60).to_i print_if_verbose("The elapsed seconds are " + elapsed_seconds.to_s) return elapsed_seconds <= 120 end return false end
evaluate(token, user_id)
click to toggle source
# File lib/flags_sdk_ort.rb, line 58 def FlagsEvaluation.evaluate(token, user_id) if !cached(token, user_id) print_if_verbose("A request is going to be made because there is no valid result cached for this flag and token") complete_route = @@route + '/flags/' + token.to_s + '/user/' + user_id.to_s + "/evaluate" response = HTTParty.get(complete_route, timeout: 1) if response.code == 200 body = JSON.parse(response.body) if body["eval"] != nil self.save_to_cache(token, user_id, body["eval"]) return body["eval"] else return false end else return false end else print_if_verbose("The evaluation result is going to be obtained from cache") return retrieve_from_cache(token, user_id) end end
print_if_verbose(message)
click to toggle source
# File lib/flags_sdk_ort.rb, line 18 def FlagsEvaluation.print_if_verbose(message) if @@verbose puts message end end
retrieve_from_cache(token, user_id)
click to toggle source
# File lib/flags_sdk_ort.rb, line 50 def FlagsEvaluation.retrieve_from_cache(token, user_id) print_if_verbose("Retriving the value from cache") value, _ = @@cache[token][user_id] return value end
save_to_cache(token, user_id, result)
click to toggle source
# File lib/flags_sdk_ort.rb, line 42 def FlagsEvaluation.save_to_cache(token, user_id, result) print_if_verbose("Information for this request is going to be saved in the cache") @@cache[token] = {user_id => [result, DateTime.now]} print_if_verbose("The following values were added to the cache: token: " + token + ", user_id: " + user_id + ", result: " + @@cache[token][user_id].to_s) end
set_route(route)
click to toggle source
# File lib/flags_sdk_ort.rb, line 9 def FlagsEvaluation.set_route(route) @@route = route @@cache = Hash.new end
set_verbose(verbose)
click to toggle source
# File lib/flags_sdk_ort.rb, line 14 def FlagsEvaluation.set_verbose(verbose) @@verbose = verbose end