Skip to content

Commit d8b4193

Browse files
committed
simplify old user data json parsing
1 parent 6a547b7 commit d8b4193

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lib/airbrake_api/v3/notice_parser.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,14 @@ def request
6969
end
7070

7171
def user_attributes
72-
context['user'] || begin
73-
hash = context.slice('userId', 'userUsername', 'userName', 'userEmail')
74-
Hash[hash.map { |key, value| [key[4..-1].downcase, value] }]
75-
end
72+
return context['user'] if context['user']
73+
74+
{
75+
'id' => context['userId'],
76+
'name' => context['userName'],
77+
'email' => context['userEmail'],
78+
'username' => context['userUsername']
79+
}.compact
7680
end
7781

7882
def url

spec/fixtures/api_v3_request_with_deprecated_user_keys.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"sourceMapEnabled":true,
2323
"userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36",
2424
"url":"http://localhost:3000/kontakt",
25-
"userId":1,"userUsername":"john",
25+
"userId":1,
2626
"userName":"John Doe",
2727
"userUsername": "john",
2828
"userEmail":"[email protected]",

0 commit comments

Comments
 (0)