Skip to content

Add methods to help with user self-service opt in (labs) #18

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

Closed
wants to merge 7 commits into from
Closed
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
33 changes: 33 additions & 0 deletions lib/ldclient-rb/ldclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,39 @@ def get_features
end
end

def get_user_toggles(user)
res = make_request "/api/users/#{user[:key]}/features"

if res.status / 100 == 2
return JSON.parse(res.body, symbolize_names: true)
else
@config.logger.error("[LDClient] Unexpected status code #{res.status}. Response body #{res.body}")
return { :items => [] }
end
end

def add_user_override(key, user, value)
res = @client.put("#{@config.base_uri}/api/users/#{user[:key]}/features/#{key}") do |req|
req.headers['Authorization'] = "api_key #{@api_key}"
req.headers['User-Agent'] = "RubyClient/#{LaunchDarkly::VERSION}"
req.headers['Content-Type'] = 'application/json'
req.body = {setting: value}.to_json
req.options.timeout = @config.read_timeout
req.options.open_timeout = @config.connect_timeout
end

if res.status == 401
@config.logger.error("[LDClient] Invalid API key")
end

if res.status / 100 != 2
@config.logger.error("[LDClient] Unexpected status code #{res.status}")
return false
end

return true
end

def get_streamed_flag(key)
feature = get_flag_stream(key)
if @config.debug_stream?
Expand Down