Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added spec query parameter #530

Merged
merged 5 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/splitclient-rb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
require 'splitclient-rb/engine/synchronizer'
require 'splitclient-rb/utilitites'

require 'splitclient-rb/spec.rb'

# SSE
require 'splitclient-rb/sse/event_source/client'
require 'splitclient-rb/sse/event_source/event_parser'
Expand Down
4 changes: 3 additions & 1 deletion lib/splitclient-rb/engine/api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def initialize(config)
end

def get_api(url, api_key, params = {}, cache_control_headers = false)
api_client.options.params_encoder.sort_params = false
api_client.get(url, params) do |req|
req.headers = common_headers(api_key).merge('Accept-Encoding' => 'gzip')
req.headers = req.headers.merge('Cache-Control' => 'no-cache') if cache_control_headers
Expand All @@ -29,7 +30,7 @@ def post_api(url, api_key, data, headers = {}, params = {})
req.headers = common_headers(api_key)
.merge('Content-Type' => 'application/json')
.merge(headers)

machine_ip = @config.machine_ip
machine_name = @config.machine_name

Expand All @@ -55,6 +56,7 @@ def api_client
@api_client ||= Faraday.new do |builder|
builder.use SplitIoClient::FaradayMiddleware::Gzip
builder.adapter :net_http_persistent
builder.options.params_encoder = Faraday::FlatParamsEncoder
end
end

Expand Down
5 changes: 3 additions & 2 deletions lib/splitclient-rb/engine/api/splits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ module SplitIoClient
module Api
# Retrieves split definitions from the Split Backend
class Splits < Client

def initialize(api_key, config, telemetry_runtime_producer)
super(config)
@api_key = api_key
@telemetry_runtime_producer = telemetry_runtime_producer
@flag_sets_filter = @config.flag_sets_filter
end

def since(since, fetch_options = { cache_control_headers: false, till: nil, sets: nil })
def since(since, fetch_options = { cache_control_headers: false, till: nil, sets: nil})
start = Time.now

params = { since: since }
params = { s: SplitIoClient::Spec::FeatureFlags::SPEC_VERSION, since: since }
params[:till] = fetch_options[:till] unless fetch_options[:till].nil?
params[:sets] = @flag_sets_filter.join(",") unless @flag_sets_filter.empty?
@config.logger.debug("Fetching from splitChanges with #{params}: ")
Expand Down
2 changes: 1 addition & 1 deletion lib/splitclient-rb/engine/auth_api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(config, telemetry_runtime_producer)

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

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

Expand Down
9 changes: 9 additions & 0 deletions lib/splitclient-rb/spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module SplitIoClient
module Spec
class FeatureFlags
SPEC_VERSION = "1.1"
end
end
end
2 changes: 1 addition & 1 deletion spec/cache/fetchers/segment_fetch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
stub_request(:get, 'https://sdk.split.io/api/segmentChanges/employees?since=1473863075059')
.to_return(status: 200, body: segments_json2)

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

Expand Down
12 changes: 6 additions & 6 deletions spec/cache/fetchers/split_fetch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
end

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

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

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

store.send(:fetch_splits)
Expand Down Expand Up @@ -81,7 +81,7 @@
let(:store) { described_class.new(splits_repository, '', config, telemetry_runtime_producer) }

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

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

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

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

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

store.send(:fetch_splits)
Expand Down Expand Up @@ -149,7 +149,7 @@
active_split = store.splits_repository.splits['test_1_ruby']
expect(active_split[:status]).to eq('ACTIVE')

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

store.send(:fetch_splits)
Expand Down
18 changes: 9 additions & 9 deletions spec/engine/api/splits_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
let(:splits_api) { described_class.new('', config, telemetry_runtime_producer) }

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

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

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

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

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

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

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

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

expect { splits_api.since(-1) }.to raise_error(
Expand All @@ -166,7 +166,7 @@
end

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

expect { splits_api.since(-1) }.to raise_error(
Expand All @@ -175,7 +175,7 @@
end

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

expect { splits_api.since(-1) }.to raise_error(
Expand Down
6 changes: 3 additions & 3 deletions spec/engine/auth_api_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
let(:telemetry_runtime_producer) { SplitIoClient::Telemetry::RuntimeProducer.new(config) }

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

auth_api_client = subject.new(config, telemetry_runtime_producer)
response = auth_api_client.authenticate(api_key)
Expand All @@ -26,7 +26,7 @@
end

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

auth_api_client = subject.new(config, telemetry_runtime_producer)
response = auth_api_client.authenticate(api_key)
Expand All @@ -36,7 +36,7 @@
end

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

auth_api_client = subject.new(config, telemetry_runtime_producer)
response = auth_api_client.authenticate(api_key)
Expand Down
6 changes: 3 additions & 3 deletions spec/engine/matchers/between_matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
# .to_return(status: 200, body: number_matcher_splits)
stub_request(:get, 'https://sdk.split.io/api/splitChanges')
.to_return(status: 200, body: number_matcher_splits)
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1')
.to_return(status: 200, body: number_matcher_splits)
subject.block_until_ready
sleep 1
Expand All @@ -69,7 +69,7 @@
let(:non_matching_low_value_negative_attributes) { { income: -999 } }

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

before do
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/)
.to_return(status: 200, body: datetime_matcher_splits)
subject.block_until_ready
sleep 1
Expand Down
2 changes: 1 addition & 1 deletion spec/engine/matchers/combining_matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
before do
stub_request(:get, 'https://sdk.split.io/api/segmentChanges/employees?since=-1')
.to_return(status: 200, body: segments_json)
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/)
.to_return(status: 200, body: splits_json)
stub_request(:any, /https:\/\/telemetry.*/)
.to_return(status: 200, body: 'ok')
Expand Down
8 changes: 4 additions & 4 deletions spec/engine/matchers/equal_to_matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
before do
stub_request(:any, /https:\/\/telemetry.*/)
.to_return(status: 200, body: 'ok')
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/)
.to_return(status: 200, body: splits_json)
stub_request(:any, /https:\/\/events.*/)
.to_return(status: 200, body: 'ok')
Expand All @@ -64,7 +64,7 @@
before do
stub_request(:any, /https:\/\/telemetry.*/)
.to_return(status: 200, body: 'ok')
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/)
.to_return(status: 200, body: zero_splits_json)
stub_request(:any, /https:\/\/events.*/)
.to_return(status: 200, body: 'ok')
Expand All @@ -90,7 +90,7 @@
before do
stub_request(:any, /https:\/\/telemetry.*/)
.to_return(status: 200, body: 'ok')
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/)
.to_return(status: 200, body: negative_splits_json)
stub_request(:any, /https:\/\/events.*/)
.to_return(status: 200, body: 'ok')
Expand All @@ -117,7 +117,7 @@
before do
stub_request(:any, /https:\/\/telemetry.*/)
.to_return(status: 200, body: 'ok')
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/)
.to_return(status: 200, body: date_splits_json)
stub_request(:any, /https:\/\/events.*/)
.to_return(status: 200, body: 'ok')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
before do
stub_request(:any, /https:\/\/telemetry.*/)
.to_return(status: 200, body: 'ok')
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/)
.to_return(status: 200, body: splits_json)
stub_request(:any, /https:\/\/events.*/)
.to_return(status: 200, body: "", headers: {})
Expand All @@ -61,7 +61,7 @@
before do
stub_request(:any, /https:\/\/telemetry.*/)
.to_return(status: 200, body: 'ok')
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/)
.to_return(status: 200, body: negative_splits_json)
stub_request(:any, /https:\/\/events.*/)
.to_return(status: 200, body: "", headers: {})
Expand Down Expand Up @@ -92,7 +92,7 @@
before do
stub_request(:any, /https:\/\/telemetry.*/)
.to_return(status: 200, body: 'ok')
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/)
.to_return(status: 200, body: date_splits_json)
stub_request(:any, /https:\/\/events.*/)
.to_return(status: 200, body: "", headers: {})
Expand Down
8 changes: 4 additions & 4 deletions spec/engine/matchers/less_than_or_equal_to_matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
before do
stub_request(:any, /https:\/\/telemetry.*/)
.to_return(status: 200, body: 'ok')
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/)
.to_return(status: 200, body: splits_json)
stub_request(:any, /https:\/\/events.*/)
.to_return(status: 200, body: "", headers: {})
Expand All @@ -64,7 +64,7 @@
before do
stub_request(:any, /https:\/\/telemetry.*/)
.to_return(status: 200, body: 'ok')
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/)
.to_return(status: 200, body: negative_splits_json)
stub_request(:any, /https:\/\/events.*/)
.to_return(status: 200, body: "", headers: {})
Expand Down Expand Up @@ -93,7 +93,7 @@
before do
stub_request(:any, /https:\/\/telemetry.*/)
.to_return(status: 200, body: 'ok')
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/)
.to_return(status: 200, body: date_splits_json)
stub_request(:any, /https:\/\/events.*/)
.to_return(status: 200, body: "", headers: {})
Expand All @@ -119,7 +119,7 @@
before do
stub_request(:any, /https:\/\/telemetry.*/)
.to_return(status: 200, body: 'ok')
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/)
.to_return(status: 200, body: date_splits2_json)
stub_request(:any, /https:\/\/events.*/)
.to_return(status: 200, body: "", headers: {})
Expand Down
2 changes: 1 addition & 1 deletion spec/engine/matchers/whitelist_matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
before do
stub_request(:any, /https:\/\/telemetry.*/)
.to_return(status: 200, body: 'ok')
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/)
.to_return(status: 200, body: splits_json)
stub_request(:any, /https:\/\/events.*/)
.to_return(status: 200, body: "", headers: {})
Expand Down
Loading
Loading