Skip to content

Commit 5daa3ca

Browse files
authored
add locale to user (#400)
## Description adds locale to the User object, adds support for updating User locale ## Documentation Does this require changes to the WorkOS Docs? E.g. the [API Reference](https://workos.com/docs/reference) or code snippets need updates. ``` [X] Yes ``` If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.
1 parent 0bd554a commit 5daa3ca

File tree

4 files changed

+93
-1
lines changed

4 files changed

+93
-1
lines changed

lib/workos/user.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class User
88
include HashProvider
99

1010
attr_accessor :id, :email, :first_name, :last_name, :email_verified,
11-
:profile_picture_url, :external_id, :last_sign_in_at, :created_at, :updated_at
11+
:profile_picture_url, :external_id, :locale, :last_sign_in_at, :created_at, :updated_at
1212

1313
def initialize(json)
1414
hash = JSON.parse(json, symbolize_names: true)
@@ -20,6 +20,7 @@ def initialize(json)
2020
@email_verified = hash[:email_verified]
2121
@profile_picture_url = hash[:profile_picture_url]
2222
@external_id = hash[:external_id]
23+
@locale = hash[:locale]
2324
@last_sign_in_at = hash[:last_sign_in_at]
2425
@created_at = hash[:created_at]
2526
@updated_at = hash[:updated_at]
@@ -34,6 +35,7 @@ def to_json(*)
3435
email_verified: email_verified,
3536
profile_picture_url: profile_picture_url,
3637
external_id: external_id,
38+
locale: locale,
3739
last_sign_in_at: last_sign_in_at,
3840
created_at: created_at,
3941
updated_at: updated_at,

lib/workos/user_management.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ def create_user(
230230
# @param [String] last_name The user's last name.
231231
# @param [Boolean] email_verified Whether the user's email address was previously verified.
232232
# @param [String] external_id The users's external ID
233+
# @param [String] locale The user's locale.
233234
# @param [String] password The user's password.
234235
# @param [String] password_hash The user's hashed password.
235236
# @option [String] password_hash_type The algorithm originally used to hash the password.
@@ -243,6 +244,7 @@ def update_user(
243244
last_name: :not_set,
244245
email_verified: :not_set,
245246
external_id: :not_set,
247+
locale: :not_set,
246248
password: :not_set,
247249
password_hash: :not_set,
248250
password_hash_type: :not_set
@@ -255,6 +257,7 @@ def update_user(
255257
last_name: last_name,
256258
email_verified: email_verified,
257259
external_id: external_id,
260+
locale: locale,
258261
password: password,
259262
password_hash: password_hash,
260263
password_hash_type: password_hash_type,

spec/lib/workos/user_management_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,16 @@
442442
end
443443
end
444444

445+
it 'can update user locale' do
446+
VCR.use_cassette 'user_management/update_user/locale' do
447+
user = described_class.update_user(
448+
id: 'user_01K78B3ZB5B7119MYEXTQE5KNE',
449+
locale: 'en-US',
450+
)
451+
expect(user.locale).to eq('en-US')
452+
end
453+
end
454+
445455
it 'can update email addresses' do
446456
VCR.use_cassette 'user_management/update_user/email' do
447457
user = described_class.update_user(
@@ -462,6 +472,7 @@
462472
expect(body).not_to have_key(:first_name)
463473
expect(body).not_to have_key(:last_name)
464474
expect(body).not_to have_key(:email)
475+
expect(body).not_to have_key(:locale)
465476

466477
# Return a mock request object
467478
double('request')

spec/support/fixtures/vcr_cassettes/user_management/update_user/locale.yml

Lines changed: 76 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)