From 9b9aee4657fa778f5b4be6d4957c3f801f518c8b Mon Sep 17 00:00:00 2001 From: Marc C Date: Sun, 6 Oct 2019 15:29:54 +0800 Subject: [PATCH] Update contact_params function (#100) removed if block, cannot be shortened further due to exception handling and params formatting --- app/builders/messages/message_builder.rb | 28 ++++++++++-------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/app/builders/messages/message_builder.rb b/app/builders/messages/message_builder.rb index 3b2eb5e84..956c9f9b0 100644 --- a/app/builders/messages/message_builder.rb +++ b/app/builders/messages/message_builder.rb @@ -126,22 +126,18 @@ Assumptions end def contact_params - if @inbox.facebook? - k = Koala::Facebook::API.new(@inbox.channel.page_access_token) - begin - result = k.get_object(@sender_id) - rescue => e - result = {} - Raven.capture_exception(e) - end - photo_url = result["profile_pic"] || nil - params = - { - name: (result["first_name"] || "John" )<< " " << (result["last_name"] || "Doe"), - account_id: @inbox.account_id, - source_id: @sender_id, - remote_avatar_url: photo_url - } + begin + k = Koala::Facebook::API.new(@inbox.channel.page_access_token) if @inbox.facebook? + result = k.get_object(@sender_id) || {} + rescue Exception => e + result = {} + Raven.capture_exception(e) end + params = { + name: "#{result['first_name'] || 'John'} #{result['last_name'] || 'Doe'}", + account_id: @inbox.account_id, + source_id: @sender_id, + remote_avatar_url: result['profile_pic'] || nil + } end end