lib/flipper/adapters/http.rb in flipper-0.20.1 vs lib/flipper/adapters/http.rb in flipper-0.20.2
- old
+ new
@@ -33,16 +33,10 @@
else
raise Error, response
end
end
- def add(feature)
- body = JSON.generate(name: feature.key)
- response = @client.post('/features', body)
- response.is_a?(Net::HTTPOK)
- end
-
def get_multi(features)
csv_keys = features.map(&:key).join(',')
response = @client.get("/features?keys=#{csv_keys}")
raise Error, response unless response.is_a?(Net::HTTPOK)
@@ -85,54 +79,64 @@
parsed_response = JSON.parse(response.body)
parsed_response['features'].map { |feature| feature['key'] }.to_set
end
+ def add(feature)
+ body = JSON.generate(name: feature.key)
+ response = @client.post('/features', body)
+ raise Error, response unless response.is_a?(Net::HTTPOK)
+ true
+ end
+
def remove(feature)
response = @client.delete("/features/#{feature.key}")
- response.is_a?(Net::HTTPNoContent)
+ raise Error, response unless response.is_a?(Net::HTTPNoContent)
+ true
end
def enable(feature, gate, thing)
body = request_body_for_gate(gate, thing.value.to_s)
query_string = gate.key == :groups ? "?allow_unregistered_groups=true" : ""
response = @client.post("/features/#{feature.key}/#{gate.key}#{query_string}", body)
- response.is_a?(Net::HTTPOK)
+ raise Error, response unless response.is_a?(Net::HTTPOK)
+ true
end
def disable(feature, gate, thing)
body = request_body_for_gate(gate, thing.value.to_s)
query_string = gate.key == :groups ? "?allow_unregistered_groups=true" : ""
- response =
- case gate.key
- when :percentage_of_actors, :percentage_of_time
- @client.post("/features/#{feature.key}/#{gate.key}#{query_string}", body)
- else
- @client.delete("/features/#{feature.key}/#{gate.key}#{query_string}", body)
- end
- response.is_a?(Net::HTTPOK)
+ response = case gate.key
+ when :percentage_of_actors, :percentage_of_time
+ @client.post("/features/#{feature.key}/#{gate.key}#{query_string}", body)
+ else
+ @client.delete("/features/#{feature.key}/#{gate.key}#{query_string}", body)
+ end
+ raise Error, response unless response.is_a?(Net::HTTPOK)
+ true
end
def clear(feature)
response = @client.delete("/features/#{feature.key}/clear")
- response.is_a?(Net::HTTPNoContent)
+ raise Error, response unless response.is_a?(Net::HTTPNoContent)
+ true
end
private
def request_body_for_gate(gate, value)
data = case gate.key
- when :boolean
- {}
- when :groups
- { name: value }
- when :actors
- { flipper_id: value }
- when :percentage_of_actors, :percentage_of_time
- { percentage: value }
- else
- raise "#{gate.key} is not a valid flipper gate key"
- end
+ when :boolean
+ {}
+ when :groups
+ { name: value }
+ when :actors
+ { flipper_id: value }
+ when :percentage_of_actors, :percentage_of_time
+ { percentage: value }
+ else
+ raise "#{gate.key} is not a valid flipper gate key"
+ end
JSON.generate(data)
end
def result_for_feature(feature, api_gates)
api_gates ||= []