Class: WorkOS::FeatureFlags

Inherits:
Object
  • Object
show all
Defined in:
lib/workos/feature_flags.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ FeatureFlags

Returns a new instance of FeatureFlags.



9
10
11
# File 'lib/workos/feature_flags.rb', line 9

def initialize(client)
  @client = client
end

Instance Method Details

#add_flag_target(resource_id:, slug:, request_options: {}) ⇒ void

This method returns an undefined value.

Add a feature flag target

Parameters:

  • resource_id (String)

    The resource ID in format “user_<id>” or “org_<id>”.

  • slug (String)

    The unique slug identifier of the feature flag.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)



119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/workos/feature_flags.rb', line 119

def add_flag_target(
  resource_id:,
  slug:,
  request_options: {}
)
  @client.request(
    method: :post,
    path: "/feature-flags/#{WorkOS::Util.encode_path(slug)}/targets/#{WorkOS::Util.encode_path(resource_id)}",
    auth: true,
    request_options: request_options
  )
  nil
end

#disable_feature_flag(slug:, request_options: {}) ⇒ WorkOS::FeatureFlag

Disable a feature flag

Parameters:

  • slug (String)

    A unique key to reference the Feature Flag.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/workos/feature_flags.rb', line 80

def disable_feature_flag(
  slug:,
  request_options: {}
)
  response = @client.request(
    method: :put,
    path: "/feature-flags/#{WorkOS::Util.encode_path(slug)}/disable",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::FeatureFlag.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#enable_feature_flag(slug:, request_options: {}) ⇒ WorkOS::FeatureFlag

Enable a feature flag

Parameters:

  • slug (String)

    A unique key to reference the Feature Flag.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/workos/feature_flags.rb', line 99

def enable_feature_flag(
  slug:,
  request_options: {}
)
  response = @client.request(
    method: :put,
    path: "/feature-flags/#{WorkOS::Util.encode_path(slug)}/enable",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::FeatureFlag.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#get_feature_flag(slug:, request_options: {}) ⇒ WorkOS::Flag

Get a feature flag

Parameters:

  • slug (String)

    A unique key to reference the Feature Flag.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/workos/feature_flags.rb', line 61

def get_feature_flag(
  slug:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/feature-flags/#{WorkOS::Util.encode_path(slug)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::Flag.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#list_feature_flags(before: nil, after: nil, limit: nil, order: "desc", request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::Flag>

List feature flags

Parameters:

  • before (String, nil) (defaults to: nil)

    An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.

  • after (String, nil) (defaults to: nil)

    An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.

  • limit (Integer, nil) (defaults to: nil)

    Upper limit on the number of objects to return, between ‘1` and `100`.

  • order (WorkOS::Types::FeatureFlagsOrder, nil) (defaults to: "desc")

    Order the results by the creation time.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/workos/feature_flags.rb', line 20

def list_feature_flags(
  before: nil,
  after: nil,
  limit: nil,
  order: "desc",
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order
  }.compact
  response = @client.request(
    method: :get,
    path: "/feature-flags",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_feature_flags(
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::Flag,
    filters: {before: before, limit: limit, order: order},
    fetch_next: fetch_next
  )
end

#list_organization_feature_flags(organization_id:, before: nil, after: nil, limit: nil, order: "desc", request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::Flag>

List enabled feature flags for an organization

Parameters:

  • organization_id (String)

    Unique identifier of the Organization.

  • before (String, nil) (defaults to: nil)

    An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.

  • after (String, nil) (defaults to: nil)

    An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.

  • limit (Integer, nil) (defaults to: nil)

    Upper limit on the number of objects to return, between ‘1` and `100`.

  • order (WorkOS::Types::OrganizationsFeatureFlagsOrder, nil) (defaults to: "desc")

    Order the results by the creation time.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/workos/feature_flags.rb', line 160

def list_organization_feature_flags(
  organization_id:,
  before: nil,
  after: nil,
  limit: nil,
  order: "desc",
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order
  }.compact
  response = @client.request(
    method: :get,
    path: "/organizations/#{WorkOS::Util.encode_path(organization_id)}/feature-flags",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_organization_feature_flags(
      organization_id: organization_id,
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::Flag,
    filters: {organization_id: organization_id, before: before, limit: limit, order: order},
    fetch_next: fetch_next
  )
end

#list_user_feature_flags(user_id:, before: nil, after: nil, limit: nil, order: "desc", request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::Flag>

List enabled feature flags for a user

Parameters:

  • user_id (String)

    The ID of the user.

  • before (String, nil) (defaults to: nil)

    An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.

  • after (String, nil) (defaults to: nil)

    An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.

  • limit (Integer, nil) (defaults to: nil)

    Upper limit on the number of objects to return, between ‘1` and `100`.

  • order (WorkOS::Types::UserManagementUsersFeatureFlagsOrder, nil) (defaults to: "desc")

    Order the results by the creation time.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/workos/feature_flags.rb', line 207

def list_user_feature_flags(
  user_id:,
  before: nil,
  after: nil,
  limit: nil,
  order: "desc",
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order
  }.compact
  response = @client.request(
    method: :get,
    path: "/user_management/users/#{WorkOS::Util.encode_path(user_id)}/feature-flags",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_user_feature_flags(
      user_id: user_id,
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::Flag,
    filters: {user_id: user_id, before: before, limit: limit, order: order},
    fetch_next: fetch_next
  )
end

#remove_flag_target(resource_id:, slug:, request_options: {}) ⇒ void

This method returns an undefined value.

Remove a feature flag target

Parameters:

  • resource_id (String)

    The resource ID in format “user_<id>” or “org_<id>”.

  • slug (String)

    The unique slug identifier of the feature flag.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)



138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/workos/feature_flags.rb', line 138

def remove_flag_target(
  resource_id:,
  slug:,
  request_options: {}
)
  @client.request(
    method: :delete,
    path: "/feature-flags/#{WorkOS::Util.encode_path(slug)}/targets/#{WorkOS::Util.encode_path(resource_id)}",
    auth: true,
    request_options: request_options
  )
  nil
end