Class: VexillaClient
- Inherits:
-
Object
- Object
- VexillaClient
- Defined in:
- lib/vexilla_client.rb
Constant Summary collapse
- @@VEXILLA_FEATURE_TYPE_TOGGLE =
"toggle"
- @@VEXILLA_FEATURE_TYPE_GRADUAL =
"gradual"
Instance Method Summary collapse
- #fetch_flags(file_name) ⇒ Object
-
#initialize(environment, base_url, custom_instance_hash) ⇒ VexillaClient
constructor
A new instance of VexillaClient.
- #set_flags(flags) ⇒ Object
- #should(feature_name) ⇒ Object
Constructor Details
#initialize(environment, base_url, custom_instance_hash) ⇒ VexillaClient
Returns a new instance of VexillaClient.
9 10 11 12 13 |
# File 'lib/vexilla_client.rb', line 9 def initialize(environment, base_url, custom_instance_hash) @environment = environment @base_url = base_url @custom_instance_hash = custom_instance_hash end |
Instance Method Details
#fetch_flags(file_name) ⇒ Object
15 16 17 18 19 |
# File 'lib/vexilla_client.rb', line 15 def fetch_flags(file_name) response = HTTParty.get("#{@base_url}/#{file_name}") parsed_response = JSON.parse(response.body) parsed_response["environments"] end |
#set_flags(flags) ⇒ Object
21 22 23 |
# File 'lib/vexilla_client.rb', line 21 def set_flags(flags) @flags = flags end |
#should(feature_name) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/vexilla_client.rb', line 25 def should(feature_name) feature = @flags[@environment]["untagged"][feature_name] if feature["type"] == @@VEXILLA_FEATURE_TYPE_TOGGLE then feature["value"] elsif feature["type"] == @@VEXILLA_FEATURE_TYPE_GRADUAL hash_value = hash_instance_id(feature["seed"]) hash_value <= feature["value"] else false end end |