flags_sdk_ort 0.0.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/flags_sdk_ort.rb +85 -0
  3. metadata +101 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2f868ec1ad28bdd46665522bec28130e25f499e5
4
+ data.tar.gz: 6aa147d97286c33c5a99818c7f2d23917c1e37b2
5
+ SHA512:
6
+ metadata.gz: aaab6c38ea6a5685985dd1a0171823762c7e3e33aa91f49615c777faaad267f20188c1cece691db11c5f61ddd3085571fdf95c56b9e68620a183cee064a711dc
7
+ data.tar.gz: b0c7c72e38b8c7d473a45d3a5a3cbadff1bffe232ae925bc7aff1aa76c75cd52c67f7a48e84263ad07b491bee0b2765040efedda59f0eb14b38bd26cb308f967
@@ -0,0 +1,85 @@
1
+ require 'httparty'
2
+ require 'date'
3
+
4
+ class FlagsEvaluation
5
+ @@cache = Hash.new
6
+ @@route = 'https://featureflags.mybluemix.net'
7
+ @@verbose = false
8
+
9
+ def FlagsEvaluation.set_route(route)
10
+ @@route = route
11
+ @@cache = Hash.new
12
+ end
13
+
14
+ def FlagsEvaluation.set_verbose(verbose)
15
+ @@verbose = verbose
16
+ end
17
+
18
+ def FlagsEvaluation.print_if_verbose(message)
19
+ if @@verbose
20
+ puts message
21
+ end
22
+ end
23
+
24
+ def FlagsEvaluation.cached(token, user_id)
25
+ print_if_verbose("Check if value was previously cached")
26
+
27
+ if @@cache[token] != nil && @@cache[token][user_id] != nil
28
+ print_if_verbose("The result was cached, checking if value has not expired (<= 120 seconds)")
29
+
30
+ current_date = DateTime.now
31
+ _, old_date = @@cache[token][user_id]
32
+
33
+ elapsed_seconds = ((current_date - old_date) * 24 * 60 * 60).to_i
34
+
35
+ print_if_verbose("The elapsed seconds are " + elapsed_seconds.to_s)
36
+ return elapsed_seconds <= 120
37
+ end
38
+
39
+ return false
40
+ end
41
+
42
+ def FlagsEvaluation.save_to_cache(token, user_id, result)
43
+ print_if_verbose("Information for this request is going to be saved in the cache")
44
+
45
+ @@cache[token] = {user_id => [result, DateTime.now]}
46
+
47
+ print_if_verbose("The following values were added to the cache: token: " + token + ", user_id: " + user_id + ", result: " + @@cache[token][user_id].to_s)
48
+ end
49
+
50
+ def FlagsEvaluation.retrieve_from_cache(token, user_id)
51
+ print_if_verbose("Retriving the value from cache")
52
+
53
+ value, _ = @@cache[token][user_id]
54
+
55
+ return value
56
+ end
57
+
58
+ def FlagsEvaluation.evaluate(token, user_id)
59
+ if !cached(token, user_id)
60
+ print_if_verbose("A request is going to be made because there is no valid result cached for this flag and token")
61
+
62
+ complete_route = @@route + '/flags/' + token.to_s + '/user/' + user_id.to_s + "/evaluate"
63
+
64
+ response = HTTParty.get(complete_route, timeout: 1)
65
+
66
+ if response.code == 200
67
+ body = JSON.parse(response.body)
68
+
69
+ if body["eval"] != nil
70
+ self.save_to_cache(token, user_id, body["eval"])
71
+
72
+ return body["eval"]
73
+ else
74
+ return false
75
+ end
76
+ else
77
+ return false
78
+ end
79
+ else
80
+ print_if_verbose("The evaluation result is going to be obtained from cache")
81
+
82
+ return retrieve_from_cache(token, user_id)
83
+ end
84
+ end
85
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flags_sdk_ort
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Chacon
8
+ - Mathias Rodriguez
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2018-11-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: date
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: httparty
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: date
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ description: A simple hello world gem
71
+ email: kevinchacon@hotmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - lib/flags_sdk_ort.rb
77
+ homepage: http://rubygems.org/gems/hola
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.6.11
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: This gem provides convinient methods for evaluating flags for the app https://featureflags.mybluemix.org
101
+ test_files: []