Skip to content

Commit 6eafede

Browse files
authored
Merge pull request #530 from splitio/semver-spec-query
added spec query parameter
2 parents 71320e2 + 7cb1c31 commit 6eafede

29 files changed

+215
-200
lines changed

lib/splitclient-rb.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@
105105
require 'splitclient-rb/engine/synchronizer'
106106
require 'splitclient-rb/utilitites'
107107

108+
require 'splitclient-rb/spec.rb'
109+
108110
# SSE
109111
require 'splitclient-rb/sse/event_source/client'
110112
require 'splitclient-rb/sse/event_source/event_parser'

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def initialize(config)
1010
end
1111

1212
def get_api(url, api_key, params = {}, cache_control_headers = false)
13+
api_client.options.params_encoder.sort_params = false
1314
api_client.get(url, params) do |req|
1415
req.headers = common_headers(api_key).merge('Accept-Encoding' => 'gzip')
1516
req.headers = req.headers.merge('Cache-Control' => 'no-cache') if cache_control_headers
@@ -29,7 +30,7 @@ def post_api(url, api_key, data, headers = {}, params = {})
2930
req.headers = common_headers(api_key)
3031
.merge('Content-Type' => 'application/json')
3132
.merge(headers)
32-
33+
3334
machine_ip = @config.machine_ip
3435
machine_name = @config.machine_name
3536

@@ -55,6 +56,7 @@ def api_client
5556
@api_client ||= Faraday.new do |builder|
5657
builder.use SplitIoClient::FaradayMiddleware::Gzip
5758
builder.adapter :net_http_persistent
59+
builder.options.params_encoder = Faraday::FlatParamsEncoder
5860
end
5961
end
6062

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ module SplitIoClient
44
module Api
55
# Retrieves split definitions from the Split Backend
66
class Splits < Client
7+
78
def initialize(api_key, config, telemetry_runtime_producer)
89
super(config)
910
@api_key = api_key
1011
@telemetry_runtime_producer = telemetry_runtime_producer
1112
@flag_sets_filter = @config.flag_sets_filter
1213
end
1314

14-
def since(since, fetch_options = { cache_control_headers: false, till: nil, sets: nil })
15+
def since(since, fetch_options = { cache_control_headers: false, till: nil, sets: nil})
1516
start = Time.now
1617

17-
params = { since: since }
18+
params = { s: SplitIoClient::Spec::FeatureFlags::SPEC_VERSION, since: since }
1819
params[:till] = fetch_options[:till] unless fetch_options[:till].nil?
1920
params[:sets] = @flag_sets_filter.join(",") unless @flag_sets_filter.empty?
2021
@config.logger.debug("Fetching from splitChanges with #{params}: ")

lib/splitclient-rb/engine/auth_api_client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def initialize(config, telemetry_runtime_producer)
1414

1515
def authenticate(api_key)
1616
start = Time.now
17-
response = @api_client.get_api(@config.auth_service_url, api_key)
17+
response = @api_client.get_api("#{@config.auth_service_url}?s=#{SplitIoClient::Spec::FeatureFlags::SPEC_VERSION}", api_key)
1818

1919
return process_success(response, start) if response.success?
2020

lib/splitclient-rb/spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
module SplitIoClient
4+
module Spec
5+
class FeatureFlags
6+
SPEC_VERSION = "1.1"
7+
end
8+
end
9+
end

spec/cache/fetchers/segment_fetch_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
stub_request(:get, 'https://sdk.split.io/api/segmentChanges/employees?since=1473863075059')
2727
.to_return(status: 200, body: segments_json2)
2828

29-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
29+
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1')
3030
.to_return(status: 200, body: splits_with_segments_json)
3131
end
3232

spec/cache/fetchers/split_fetch_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
end
1212

1313
before do
14-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
14+
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1')
1515
.to_return(status: 200, body: active_splits_json)
1616
end
1717

@@ -48,7 +48,7 @@
4848
active_split = store.splits_repository.splits['test_1_ruby']
4949
expect(active_split[:status]).to eq('ACTIVE')
5050

51-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=1473413807667')
51+
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=1473413807667')
5252
.to_return(status: 200, body: archived_splits_json)
5353

5454
store.send(:fetch_splits)
@@ -81,7 +81,7 @@
8181
let(:store) { described_class.new(splits_repository, '', config, telemetry_runtime_producer) }
8282

8383
before do
84-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?sets=set_2&since=-1')
84+
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1&sets=set_2')
8585
.to_return(status: 200, body: active_splits_json)
8686
end
8787

@@ -103,14 +103,14 @@
103103
expect(store.splits_repository.get_split('sample_feature')[:name]).to eq('sample_feature')
104104
expect(store.splits_repository.get_split('test_1_ruby')).to eq(nil)
105105

106-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?sets=set_2&since=1473413807667')
106+
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=1473413807667&sets=set_2')
107107
.to_return(status: 200, body: archived_splits_json)
108108

109109
store.send(:fetch_splits)
110110
expect(store.splits_repository.get_split('sample_feature')).to eq(nil)
111111

112112
store.splits_repository.set_change_number(-1)
113-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?sets=set_2&since=-1')
113+
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1&sets=set_2')
114114
.to_return(status: 200, body: active_splits_json)
115115

116116
store.send(:fetch_splits)
@@ -149,7 +149,7 @@
149149
active_split = store.splits_repository.splits['test_1_ruby']
150150
expect(active_split[:status]).to eq('ACTIVE')
151151

152-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=1473413807667')
152+
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=1473413807667')
153153
.to_return(status: 200, body: archived_splits_json)
154154

155155
store.send(:fetch_splits)

spec/engine/api/splits_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
let(:splits_api) { described_class.new('', config, telemetry_runtime_producer) }
1919

2020
it 'returns splits with segment names' do
21-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
21+
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1')
2222
.to_return(status: 200, body: splits)
2323

2424
parsed_splits = splits_api.send(:splits_with_segment_names, splits)
@@ -41,7 +41,7 @@
4141
let(:splits_api) { described_class.new('', config, telemetry_runtime_producer) }
4242

4343
it 'returns the splits - with 2 sets param' do
44-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?sets=set_1,set_2&since=-1')
44+
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1&sets=set_1,set_2')
4545
.with(headers: {
4646
'Accept' => '*/*',
4747
'Accept-Encoding' => 'gzip',
@@ -61,7 +61,7 @@
6161
end
6262

6363
it 'raise api exception when status 414' do
64-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?sets=set_1,set_2&since=-1')
64+
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1&sets=set_1,set_2')
6565
.with(headers: {
6666
'Accept' => '*/*',
6767
'Accept-Encoding' => 'gzip',
@@ -96,7 +96,7 @@
9696
let(:splits_api) { described_class.new('', config, telemetry_runtime_producer) }
9797

9898
it 'returns the splits - checking headers when cache_control_headers is false' do
99-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
99+
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1')
100100
.with(headers: {
101101
'Accept' => '*/*',
102102
'Accept-Encoding' => 'gzip',
@@ -115,7 +115,7 @@
115115
end
116116

117117
it 'returns the splits - with till param' do
118-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1&till=123123')
118+
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1&till=123123')
119119
.with(headers: {
120120
'Accept' => '*/*',
121121
'Accept-Encoding' => 'gzip',
@@ -135,7 +135,7 @@
135135
end
136136

137137
it 'returns the splits - checking headers when cache_control_headers is true' do
138-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
138+
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1')
139139
.with(headers: {
140140
'Accept' => '*/*',
141141
'Accept-Encoding' => 'gzip',
@@ -156,7 +156,7 @@
156156
end
157157

158158
it 'throws exception if request to get splits from API returns unexpected status code' do
159-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
159+
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1')
160160
.to_return(status: 404)
161161

162162
expect { splits_api.since(-1) }.to raise_error(
@@ -166,7 +166,7 @@
166166
end
167167

168168
it 'throws exception if request to get splits from API fails' do
169-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
169+
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1')
170170
.to_raise(StandardError)
171171

172172
expect { splits_api.since(-1) }.to raise_error(
@@ -175,7 +175,7 @@
175175
end
176176

177177
it 'throws exception if request to get splits from API times out' do
178-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
178+
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1')
179179
.to_timeout
180180

181181
expect { splits_api.since(-1) }.to raise_error(

spec/engine/auth_api_client_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
let(:telemetry_runtime_producer) { SplitIoClient::Telemetry::RuntimeProducer.new(config) }
1616

1717
it 'authenticate success' do
18-
stub_request(:get, config.auth_service_url).to_return(status: 200, body: body_response)
18+
stub_request(:get, config.auth_service_url + "?s=1.1").to_return(status: 200, body: body_response)
1919

2020
auth_api_client = subject.new(config, telemetry_runtime_producer)
2121
response = auth_api_client.authenticate(api_key)
@@ -26,7 +26,7 @@
2626
end
2727

2828
it 'auth server return 500' do
29-
stub_request(:get, config.auth_service_url).to_return(status: 500)
29+
stub_request(:get, config.auth_service_url + "?s=1.1").to_return(status: 500)
3030

3131
auth_api_client = subject.new(config, telemetry_runtime_producer)
3232
response = auth_api_client.authenticate(api_key)
@@ -36,7 +36,7 @@
3636
end
3737

3838
it 'auth server return 401' do
39-
stub_request(:get, config.auth_service_url).to_return(status: 401)
39+
stub_request(:get, config.auth_service_url + "?s=1.1").to_return(status: 401)
4040

4141
auth_api_client = subject.new(config, telemetry_runtime_producer)
4242
response = auth_api_client.authenticate(api_key)

spec/engine/matchers/between_matcher_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
# .to_return(status: 200, body: number_matcher_splits)
4444
stub_request(:get, 'https://sdk.split.io/api/splitChanges')
4545
.to_return(status: 200, body: number_matcher_splits)
46-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
46+
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1')
4747
.to_return(status: 200, body: number_matcher_splits)
4848
subject.block_until_ready
4949
sleep 1
@@ -69,7 +69,7 @@
6969
let(:non_matching_low_value_negative_attributes) { { income: -999 } }
7070

7171
before do
72-
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since.*/)
72+
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since.*/)
7373
.to_return(status: 200, body: negative_number_matcher_splits)
7474
subject.block_until_ready
7575
sleep 1
@@ -97,7 +97,7 @@
9797
let(:non_matching_high_value_attributes) { { created: 1_459_775_460 } } # "2016/04/04T13:11Z"
9898

9999
before do
100-
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
100+
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/)
101101
.to_return(status: 200, body: datetime_matcher_splits)
102102
subject.block_until_ready
103103
sleep 1

0 commit comments

Comments
 (0)