Skip to content

Commit 52f53cd

Browse files
feat(flags): switch local evaluation endpoint to /flags/definitions (#121)
1 parent 971eac0 commit 52f53cd

6 files changed

Lines changed: 68 additions & 68 deletions

File tree

lib/posthog/feature_flags.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ def _apply_flag_definitions(data)
11281128
end
11291129

11301130
def _request_feature_flag_definitions(etag: nil)
1131-
uri = URI("#{@host}/api/feature_flag/local_evaluation")
1131+
uri = URI("#{@host}/flags/definitions")
11321132
uri.query = URI.encode_www_form([['token', @project_api_key], %w[send_cohorts true]])
11331133
req = Net::HTTP::Get.new(uri)
11341134
req['Authorization'] = "Bearer #{@personal_api_key}"

spec/posthog/client_spec.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ module PostHog
278278

279279
stub_request(
280280
:get,
281-
'https://us.i.posthog.com/api/feature_flag/local_evaluation?token=testsecret&send_cohorts=true'
281+
'https://us.i.posthog.com/flags/definitions?token=testsecret&send_cohorts=true'
282282
).to_return(status: 200, body: api_feature_flag_res.to_json)
283283
stub_request(:post, flags_endpoint)
284284
.to_return(status: 200, body: flags_response.to_json)
@@ -323,7 +323,7 @@ module PostHog
323323

324324
stub_request(
325325
:get,
326-
'https://us.i.posthog.com/api/feature_flag/local_evaluation?token=testsecret&send_cohorts=true'
326+
'https://us.i.posthog.com/flags/definitions?token=testsecret&send_cohorts=true'
327327
).to_return(status: 200, body: api_feature_flag_res.to_json)
328328
stub_request(:post, flags_endpoint)
329329
.to_return(status: 200, body: flags_response.to_json)
@@ -348,7 +348,7 @@ module PostHog
348348
'off-feature' => false } }
349349
stub_request(
350350
:get,
351-
'https://us.i.posthog.com/api/feature_flag/local_evaluation?token=testsecret&send_cohorts=true'
351+
'https://us.i.posthog.com/flags/definitions?token=testsecret&send_cohorts=true'
352352
).to_return(status: 200, body: {}.to_json)
353353
stub_request(:post, flags_endpoint)
354354
.to_return(status: 200, body: flags_response.to_json)
@@ -373,7 +373,7 @@ module PostHog
373373

374374
stub_request(
375375
:get,
376-
'https://us.i.posthog.com/api/feature_flag/local_evaluation?token=testsecret&send_cohorts=true'
376+
'https://us.i.posthog.com/flags/definitions?token=testsecret&send_cohorts=true'
377377
).to_return(status: 401, body: { 'error' => 'not authorized' }.to_json)
378378
stub_request(:post, flags_endpoint)
379379
.to_return(status: 200, body: flags_response.to_json)
@@ -390,7 +390,7 @@ module PostHog
390390
expect(properties['$feature/beta-feature']).to eq('random-variant')
391391
expect(properties['$active_feature_flags']).to eq(['beta-feature'])
392392

393-
assert_not_requested :get, 'https://us.i.posthog.com/api/feature_flag/local_evaluation?token=testsecret&send_cohorts=true'
393+
assert_not_requested :get, 'https://us.i.posthog.com/flags/definitions?token=testsecret&send_cohorts=true'
394394
end
395395

396396
it 'manages memory well when sending feature flags' do
@@ -414,7 +414,7 @@ module PostHog
414414
}
415415
stub_request(
416416
:get,
417-
'https://us.i.posthog.com/api/feature_flag/local_evaluation?token=testsecret&send_cohorts=true'
417+
'https://us.i.posthog.com/flags/definitions?token=testsecret&send_cohorts=true'
418418
).to_return(status: 200, body: api_feature_flag_res.to_json)
419419

420420
stub_const('PostHog::Defaults::MAX_HASH_SIZE', 10)
@@ -482,7 +482,7 @@ module PostHog
482482

483483
stub_request(
484484
:get,
485-
'https://us.i.posthog.com/api/feature_flag/local_evaluation?token=testsecret&send_cohorts=true'
485+
'https://us.i.posthog.com/flags/definitions?token=testsecret&send_cohorts=true'
486486
).to_return(status: 200, body: api_feature_flag_res.to_json)
487487

488488
stub_const('PostHog::Defaults::MAX_HASH_SIZE', 10)
@@ -639,7 +639,7 @@ module PostHog
639639

640640
stub_request(
641641
:get,
642-
'https://us.i.posthog.com/api/feature_flag/local_evaluation?token=testsecret&send_cohorts=true'
642+
'https://us.i.posthog.com/flags/definitions?token=testsecret&send_cohorts=true'
643643
).to_return(status: 200, body: api_feature_flag_res.to_json)
644644
stub_request(:post, flags_endpoint)
645645
.to_return(status: 200, body: flags_response.to_json)
@@ -677,7 +677,7 @@ module PostHog
677677

678678
stub_request(
679679
:get,
680-
'https://us.i.posthog.com/api/feature_flag/local_evaluation?token=testsecret&send_cohorts=true'
680+
'https://us.i.posthog.com/flags/definitions?token=testsecret&send_cohorts=true'
681681
).to_return(status: 200, body: api_feature_flag_res.to_json)
682682
stub_request(:post, flags_endpoint)
683683
.to_return(status: 200, body: flags_response.to_json)
@@ -703,7 +703,7 @@ module PostHog
703703
it 'ignores feature flags with invalid send_feature_flags parameter' do
704704
stub_request(
705705
:get,
706-
'https://us.i.posthog.com/api/feature_flag/local_evaluation?token=testsecret&send_cohorts=true'
706+
'https://us.i.posthog.com/flags/definitions?token=testsecret&send_cohorts=true'
707707
).to_return(status: 200, body: { flags: [] }.to_json)
708708
c = Client.new(api_key: API_KEY, personal_api_key: API_KEY, test_mode: true)
709709

@@ -741,7 +741,7 @@ module PostHog
741741
}
742742
stub_request(
743743
:get,
744-
'https://us.i.posthog.com/api/feature_flag/local_evaluation?token=testsecret&send_cohorts=true'
744+
'https://us.i.posthog.com/flags/definitions?token=testsecret&send_cohorts=true'
745745
).to_return(status: 200, body: api_feature_flag_res.to_json)
746746

747747
# This should NOT be called because only_evaluate_locally is true
@@ -793,7 +793,7 @@ module PostHog
793793
}
794794
stub_request(
795795
:get,
796-
'https://us.i.posthog.com/api/feature_flag/local_evaluation?token=testsecret&send_cohorts=true'
796+
'https://us.i.posthog.com/flags/definitions?token=testsecret&send_cohorts=true'
797797
).to_return(status: 200, body: api_feature_flag_res.to_json)
798798

799799
# This should NOT be called because only_evaluate_locally is true
@@ -844,7 +844,7 @@ module PostHog
844844
}
845845
stub_request(
846846
:get,
847-
'https://us.i.posthog.com/api/feature_flag/local_evaluation?token=testsecret&send_cohorts=true'
847+
'https://us.i.posthog.com/flags/definitions?token=testsecret&send_cohorts=true'
848848
).to_return(status: 200, body: api_feature_flag_res.to_json)
849849

850850
# This SHOULD be called because only_evaluate_locally is explicitly false
@@ -1186,7 +1186,7 @@ def run
11861186
# Mock response for api/feature_flag
11871187
stub_request(
11881188
:get,
1189-
'https://us.i.posthog.com/api/feature_flag/local_evaluation?token=testsecret&send_cohorts=true'
1189+
'https://us.i.posthog.com/flags/definitions?token=testsecret&send_cohorts=true'
11901190
).to_return(status: 200, body: api_feature_flag_res.to_json)
11911191

11921192
# Mock response for `/flags`

spec/posthog/feature_flag_error_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
module PostHog
66
describe 'Feature Flag Error Tracking' do
77
let(:flags_endpoint) { 'https://us.i.posthog.com/flags/?v=2' }
8-
let(:feature_flag_endpoint) { 'https://us.i.posthog.com/api/feature_flag/local_evaluation?token=testsecret&send_cohorts=true' }
8+
let(:feature_flag_endpoint) { 'https://us.i.posthog.com/flags/definitions?token=testsecret&send_cohorts=true' }
99
let(:client) { Client.new(api_key: API_KEY, personal_api_key: API_KEY, test_mode: true) }
1010

1111
before do

0 commit comments

Comments
 (0)