Skip to content

Commit 19026f4

Browse files
committed
Add GET /organizations/:orgId/feature-flags support
1 parent 4d8a2ba commit 19026f4

File tree

5 files changed

+161
-0
lines changed

5 files changed

+161
-0
lines changed

lib/workos.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def self.key
5959
autoload :Event, 'workos/event'
6060
autoload :Events, 'workos/events'
6161
autoload :Factor, 'workos/factor'
62+
autoload :FeatureFlag, 'workos/feature_flag'
6263
autoload :Impersonator, 'workos/impersonator'
6364
autoload :Invitation, 'workos/invitation'
6465
autoload :MagicAuth, 'workos/magic_auth'

lib/workos/feature_flag.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# frozen_string_literal: true
2+
3+
module WorkOS
4+
# The FeatureFlag class provides a lightweight wrapper around
5+
# a WorkOS Feature Flag resource. This class is not meant to be instantiated
6+
# in user space, and is instantiated internally but exposed.
7+
class FeatureFlag
8+
include HashProvider
9+
10+
attr_accessor :id, :name, :slug, :description, :created_at, :updated_at
11+
12+
def initialize(json)
13+
hash = JSON.parse(json, symbolize_names: true)
14+
15+
@id = hash[:id]
16+
@name = hash[:name]
17+
@slug = hash[:slug]
18+
@description = hash[:description]
19+
@created_at = hash[:created_at]
20+
@updated_at = hash[:updated_at]
21+
end
22+
23+
def to_json(*)
24+
{
25+
id: id,
26+
name: name,
27+
slug: slug,
28+
description: description,
29+
created_at: created_at,
30+
updated_at: updated_at,
31+
}
32+
end
33+
end
34+
end

lib/workos/organizations.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,39 @@ def list_organization_roles(organization_id:)
224224
)
225225
end
226226

227+
# Retrieve a list of feature flags for the given organization.
228+
#
229+
# @param [String] organization_id The ID of the organization to fetch feature flags for.
230+
#
231+
# @example
232+
# WorkOS::Organizations.list_organization_feature_flags(organization_id: 'org_01EHZNVPK3SFK441A1RGBFSHRT')
233+
# => #<WorkOS::Types::ListStruct data=[#<WorkOS::FeatureFlag id="flag_123" key="new_feature"
234+
# enabled=true ...>] ...>
235+
#
236+
# @return [WorkOS::Types::ListStruct] - Collection of FeatureFlag objects
237+
def list_organization_feature_flags(organization_id:)
238+
response = execute_request(
239+
request: get_request(
240+
path: "/organizations/#{organization_id}/feature_flags",
241+
auth: true,
242+
),
243+
)
244+
245+
parsed_response = JSON.parse(response.body)
246+
247+
feature_flags = parsed_response['data'].map do |feature_flag|
248+
WorkOS::FeatureFlag.new(feature_flag.to_json)
249+
end
250+
251+
WorkOS::Types::ListStruct.new(
252+
data: feature_flags,
253+
list_metadata: {
254+
after: nil,
255+
before: nil,
256+
},
257+
)
258+
end
259+
227260
private
228261

229262
def check_and_raise_organization_error(response:)

spec/lib/workos/organizations_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,4 +450,22 @@
450450
end
451451
end
452452
end
453+
454+
describe '.list_organization_feature_flags' do
455+
context 'with no options' do
456+
it 'returns feature flags for organization' do
457+
expected_metadata = {
458+
after: nil,
459+
before: nil,
460+
}
461+
462+
VCR.use_cassette 'organization/list_organization_feature_flags' do
463+
feature_flags = described_class.list_organization_feature_flags(organization_id: 'org_01JEXP6Z3X7HE4CB6WQSH9ZAFE')
464+
465+
expect(feature_flags.data.size).to eq(3)
466+
expect(feature_flags.list_metadata).to eq(expected_metadata)
467+
end
468+
end
469+
end
470+
end
453471
end

spec/support/fixtures/vcr_cassettes/organization/list_organization_feature_flags.yml

Lines changed: 75 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)