From d8b419332937a169e39abdac8996ee42ff69d055 Mon Sep 17 00:00:00 2001 From: Stephen Crosby Date: Fri, 8 Jan 2016 21:48:47 -0800 Subject: [PATCH] simplify old user data json parsing --- lib/airbrake_api/v3/notice_parser.rb | 12 ++++++++---- spec/fixtures/api_v3_request_with_deprecated_user_keys.json | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/airbrake_api/v3/notice_parser.rb b/lib/airbrake_api/v3/notice_parser.rb index 9517f70..fcae8fd 100644 --- a/lib/airbrake_api/v3/notice_parser.rb +++ b/lib/airbrake_api/v3/notice_parser.rb @@ -69,10 +69,14 @@ module AirbrakeApi end def user_attributes - context['user'] || begin - hash = context.slice('userId', 'userUsername', 'userName', 'userEmail') - Hash[hash.map { |key, value| [key[4..-1].downcase, value] }] - end + return context['user'] if context['user'] + + { + 'id' => context['userId'], + 'name' => context['userName'], + 'email' => context['userEmail'], + 'username' => context['userUsername'] + }.compact end def url diff --git a/spec/fixtures/api_v3_request_with_deprecated_user_keys.json b/spec/fixtures/api_v3_request_with_deprecated_user_keys.json index 01a1324..de39e33 100644 --- a/spec/fixtures/api_v3_request_with_deprecated_user_keys.json +++ b/spec/fixtures/api_v3_request_with_deprecated_user_keys.json @@ -22,7 +22,7 @@ "sourceMapEnabled":true, "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", "url":"http://localhost:3000/kontakt", - "userId":1,"userUsername":"john", + "userId":1, "userName":"John Doe", "userUsername": "john", "userEmail":"john.doe@example.org", -- libgit2 0.21.2