vexilla_client 0.0.1

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/vexilla_client.rb +48 -0
  3. metadata +79 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b1a3e61f95a933e0ae76e10ef041ac915276a63b
4
+ data.tar.gz: f31b14db8f4ff88abbb33e876eadf019fdf65732
5
+ SHA512:
6
+ metadata.gz: 8ff62352941dcad4fe44651791f159633206258a960fd390c2a526319f11cedbc515b7cbbfcdbed0848aac4b9627499a46f64e5b43b6ee001650b39595eabf41
7
+ data.tar.gz: 4ae93c870e327127c260cff6a387e55c050bcfb978da724a686cf214352a07c8e3ec51dbd69ecc0fd88463d15b8f7bcdc3dd70862fc03d12f14455f9f4e2608d
@@ -0,0 +1,48 @@
1
+ require "httparty"
2
+ require "json"
3
+
4
+ class VexillaClient
5
+
6
+ @@VEXILLA_FEATURE_TYPE_TOGGLE = "toggle"
7
+ @@VEXILLA_FEATURE_TYPE_GRADUAL = "gradual"
8
+
9
+ def initialize(environment, base_url, custom_instance_hash)
10
+ @environment = environment
11
+ @base_url = base_url
12
+ @custom_instance_hash = custom_instance_hash
13
+ end
14
+
15
+ def fetch_flags(file_name)
16
+ response = HTTParty.get("#{@base_url}/#{file_name}")
17
+ parsed_response = JSON.parse(response.body)
18
+ parsed_response["environments"]
19
+ end
20
+
21
+ def set_flags(flags)
22
+ @flags = flags
23
+ end
24
+
25
+ def should(feature_name)
26
+ feature = @flags[@environment]["untagged"][feature_name]
27
+
28
+ if feature["type"] == @@VEXILLA_FEATURE_TYPE_TOGGLE then
29
+ feature["value"]
30
+ elsif feature["type"] == @@VEXILLA_FEATURE_TYPE_GRADUAL
31
+ hash_value = hash_instance_id(feature["seed"])
32
+ hash_value <= feature["value"]
33
+ else
34
+ false
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def hash_instance_id(seed)
41
+ chars = @custom_instance_hash.chars
42
+
43
+ total = chars.map { |char| char.ord }.reduce(0) { |sum, char_code| sum + char_code }
44
+
45
+ (total * seed * 42.0) % 100
46
+ end
47
+
48
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vexilla_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Griffing
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-02-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json_pure
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.5'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.5.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.5'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.5.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: httparty
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 0.18.1
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 0.18.1
47
+ description: Vexilla is a statically hosted feature flag system. Free to use for personal
48
+ and commercial projects.
49
+ email: cmgriffing@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - lib/vexilla_client.rb
55
+ homepage: https://rubygems.org/gems/vexilla_client
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.5.2.3
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: A Ruby client for the Vexilla Feature Flag system.
79
+ test_files: []