Skip to content

Commit db9311a

Browse files
author
Bilal Al
committed
updated query api order, fixed spec and added error to split logger
1 parent 0f5ac2f commit db9311a

8 files changed

Lines changed: 31 additions & 23 deletions

lib/splitclient-rb/engine/api/splits.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def since(since, fetch_options = { cache_control_headers: false, till: nil, sets
1616
start = Time.now
1717

1818
params = { s: SplitIoClient::Spec::FeatureFlags::SPEC_VERSION, since: since }
19-
params[:till] = fetch_options[:till] unless fetch_options[:till].nil?
2019
params[:sets] = @flag_sets_filter.join(",") unless @flag_sets_filter.empty?
20+
params[:till] = fetch_options[:till] unless fetch_options[:till].nil?
2121
@config.logger.debug("Fetching from splitChanges with #{params}: ")
2222
response = get_api("#{@config.base_uri}/splitChanges", @api_key, params, fetch_options[:cache_control_headers])
2323
if response.status == 414

lib/splitclient-rb/engine/matchers/between_semver_matcher.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def initialize(attribute, start_value, end_value, logger, validator)
1616
end
1717

1818
def match?(args)
19-
@logger.debug('[BetweenSemverMatcher] evaluating value and attributes.')
19+
@logger.log_if_debug('[BetweenSemverMatcher] evaluating value and attributes.')
2020
return false unless @validator.valid_matcher_arguments(args)
2121

2222
value_to_match = SplitIoClient::Semver.build(args[:attributes][@attribute.to_sym], @logger)
@@ -26,7 +26,7 @@ def match?(args)
2626
end
2727
matches = ([0, -1].include?(@semver_start.compare(value_to_match)) &&
2828
[0, 1].include?(@semver_end.compare(value_to_match)))
29-
@logger.debug("[BetweenMatcher] #{value_to_match} matches -> #{matches}")
29+
@logger.log_if_debug("[BetweenMatcher] #{value_to_match} matches -> #{matches}")
3030
matches
3131
end
3232
end

lib/splitclient-rb/engine/matchers/equal_to_semver_matcher.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def initialize(attribute, string_value, logger, validator)
1515
end
1616

1717
def match?(args)
18-
@logger.debug('[EqualsToSemverMatcher] evaluating value and attributes.')
18+
@logger.log_if_debug('[EqualsToSemverMatcher] evaluating value and attributes.')
1919
return false unless @validator.valid_matcher_arguments(args)
2020

2121
value_to_match = SplitIoClient::Semver.build(args[:attributes][@attribute.to_sym], @logger)
@@ -24,7 +24,7 @@ def match?(args)
2424
return false
2525
end
2626
matches = (@semver.version == value_to_match.version)
27-
@logger.debug("[EqualsToSemverMatcher] #{value_to_match} matches -> #{matches}")
27+
@logger.log_if_debug("[EqualsToSemverMatcher] #{value_to_match} matches -> #{matches}")
2828
matches
2929
end
3030
end

lib/splitclient-rb/engine/matchers/greater_than_or_equal_to_semver_matcher.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def initialize(attribute, string_value, logger, validator)
1515
end
1616

1717
def match?(args)
18-
@logger.debug('[GreaterThanOrEqualsToSemverMatcher] evaluating value and attributes.')
18+
@logger.log_if_debug('[GreaterThanOrEqualsToSemverMatcher] evaluating value and attributes.')
1919
return false unless @validator.valid_matcher_arguments(args)
2020

2121
value_to_match = SplitIoClient::Semver.build(args[:attributes][@attribute.to_sym], @logger)
@@ -24,7 +24,7 @@ def match?(args)
2424
return false
2525
end
2626
matches = [0, 1].include?(value_to_match.compare(@semver))
27-
@logger.debug("[GreaterThanOrEqualsToSemverMatcher] #{value_to_match} matches -> #{matches}")
27+
@logger.log_if_debug("[GreaterThanOrEqualsToSemverMatcher] #{value_to_match} matches -> #{matches}")
2828
matches
2929
end
3030
end

lib/splitclient-rb/engine/matchers/in_list_semver_matcher.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def initialize(attribute, list_value, logger, validator)
1515
end
1616

1717
def match?(args)
18-
@logger.debug('[InListSemverMatcher] evaluating value and attributes.')
18+
@logger.log_if_debug('[InListSemverMatcher] evaluating value and attributes.')
1919
return false unless @validator.valid_matcher_arguments(args) && args[:attributes][@attribute.to_sym].is_a?(String)
2020

2121
value_to_match = SplitIoClient::Semver.build(args[:attributes][@attribute.to_sym], @logger)
@@ -24,7 +24,7 @@ def match?(args)
2424
return false
2525
end
2626
matches = (@semver_list.map { |item| item.version == value_to_match.version }).any? { |item| item == true }
27-
@logger.debug("[InListSemverMatcher] #{value_to_match} matches -> #{matches}")
27+
@logger.log_if_debug("[InListSemverMatcher] #{value_to_match} matches -> #{matches}")
2828
matches
2929
end
3030
end

lib/splitclient-rb/engine/matchers/less_than_or_equal_to_semver_matcher.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def initialize(attribute, string_value, logger, validator)
1515
end
1616

1717
def match?(args)
18-
@logger.debug('[LessThanOrEqualsToSemverMatcher] evaluating value and attributes.')
18+
@logger.log_if_debug('[LessThanOrEqualsToSemverMatcher] evaluating value and attributes.')
1919
return false unless @validator.valid_matcher_arguments(args)
2020

2121
value_to_match = SplitIoClient::Semver.build(args[:attributes][@attribute.to_sym], @logger)
@@ -24,7 +24,7 @@ def match?(args)
2424
return false
2525
end
2626
matches = [0, -1].include?(value_to_match.compare(@semver))
27-
@logger.debug("[LessThanOrEqualsToSemverMatcher] #{value_to_match} matches -> #{matches}")
27+
@logger.log_if_debug("[LessThanOrEqualsToSemverMatcher] #{value_to_match} matches -> #{matches}")
2828
matches
2929
end
3030
end

lib/splitclient-rb/split_logger.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,9 @@ def log_if_debug(message)
1111
def log_if_transport(message)
1212
@config.logger.debug(message) if @config.transport_debug_enabled
1313
end
14+
15+
def error(message)
16+
@config.logger.error(message)
17+
end
1418
end
1519
end

spec/engine/matchers/semver_matchers_integration_spec.rb

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,19 @@
4343
let(:user) { 'fake_user_id_1' }
4444

4545
before do
46-
stub_request(:any, /https:\/\/telemetry.*/).to_return(status: 200, body: 'ok')
47-
stub_request(:any, /https:\/\/events.*/).to_return(status: 200, body: "", headers: {})
46+
stub_request(:any, /https:\/\/telemetry\.*/).to_return(status: 200, body: 'ok')
47+
stub_request(:any, /https:\/\/events\.*/).to_return(status: 200, body: "", headers: {})
48+
stub_request(:any, /https:\/\/metrics\.*/).to_return(status: 200, body: "", headers: {})
49+
stub_request(:post, "https://telemetry.split.io/api/v1/metrics/config").to_return(status: 200, body: "", headers: {})
4850
end
4951

5052
context 'equal to matcher' do
5153
before do
52-
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
54+
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since\.*/)
5355
.to_return(status: 200, body: semver_equalto_matcher_splits)
54-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
56+
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1')
57+
.to_return(status: 200, body: semver_equalto_matcher_splits)
58+
stub_request(:get, "https://sdk.split.io/api/splitChanges?s=1.1&since=1675259356568")
5559
.to_return(status: 200, body: semver_equalto_matcher_splits)
5660
sleep 1
5761
subject.block_until_ready
@@ -70,9 +74,9 @@
7074

7175
context 'greater than or equal to matcher' do
7276
before do
73-
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
77+
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/)
7478
.to_return(status: 200, body: semver_greater_or_equalto_matcher_splits)
75-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
79+
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1')
7680
.to_return(status: 200, body: semver_greater_or_equalto_matcher_splits)
7781
sleep 1
7882
subject.block_until_ready
@@ -92,9 +96,9 @@
9296

9397
context 'less than or equal to matcher' do
9498
before do
95-
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
99+
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/)
96100
.to_return(status: 200, body: semver_less_or_equalto_matcher_splits)
97-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
101+
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1')
98102
.to_return(status: 200, body: semver_less_or_equalto_matcher_splits)
99103
sleep 1
100104
subject.block_until_ready
@@ -114,9 +118,9 @@
114118

115119
context 'in list matcher' do
116120
before do
117-
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
121+
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/)
118122
.to_return(status: 200, body: semver_inlist_matcher_splits)
119-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
123+
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1')
120124
.to_return(status: 200, body: semver_inlist_matcher_splits)
121125
sleep 1
122126
subject.block_until_ready
@@ -136,9 +140,9 @@
136140

137141
context 'between matcher' do
138142
before do
139-
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
143+
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/)
140144
.to_return(status: 200, body: semver_between_matcher_splits)
141-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
145+
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1')
142146
.to_return(status: 200, body: semver_between_matcher_splits)
143147
sleep 1
144148
subject.block_until_ready

0 commit comments

Comments
 (0)