From 08c973ed1f480b5a9170748fd699f1b0df2d791d Mon Sep 17 00:00:00 2001 From: budipang Date: Tue, 28 Aug 2018 13:01:09 +0700 Subject: [PATCH] add notify to toggle base --- lib/toggleable/base.rb | 8 ++++++++ spec/toggleable/toggleable_spec.rb | 2 ++ 2 files changed, 10 insertions(+) diff --git a/lib/toggleable/base.rb b/lib/toggleable/base.rb index b1567c0..2cf1e80 100644 --- a/lib/toggleable/base.rb +++ b/lib/toggleable/base.rb @@ -54,6 +54,7 @@ def toggle_key(value, actor) Toggleable.configuration.storage.set(key, value, namespace: Toggleable.configuration.namespace) Toggleable::FeatureToggler.instance.toggle_key(key, value, actor: actor) Toggleable.configuration.logger&.log(key: key, value: value, actor: actor) + notify_changes(key, value) if Toggleable.configuration.notify_endpoint end def toggle_active @@ -65,6 +66,13 @@ def toggle_active def read_expired? @_last_read_at < Time.now.localtime - Toggleable.configuration.expiration_time end + + def notify_changes(toggles, values) + url = "#{Toggleable.configuration.notify_endpoint}/notify_toggle?keys=#{toggles}&values=#{values}" + RestClient::Resource.new(url).get timeout: 2, open_timeout: 1 + rescue StandardError + nil + end end end end diff --git a/spec/toggleable/toggleable_spec.rb b/spec/toggleable/toggleable_spec.rb index d8af8c6..496f62e 100644 --- a/spec/toggleable/toggleable_spec.rb +++ b/spec/toggleable/toggleable_spec.rb @@ -23,6 +23,8 @@ class SampleFeature before(:each) do allow(Toggleable::FeatureToggler.instance).to receive(:toggle_key).and_return(true) + stub_request(:get, "http://localhost:5858/notify_toggle?keys=sample_feature&values=true").to_return(status: 200, body: 'success') + stub_request(:get, "http://localhost:5858/notify_toggle?keys=sample_feature&values=false").to_return(status: 200, body: 'success') end describe 'active? before key exist should create the key also' do