From 87352b04f10badecf2e01c043f0e930262b4790d Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 22 Aug 2016 18:52:12 +0930 Subject: [PATCH] Refactor to a method to DRY, even if its not 100% the best spot for it to live long term --- app/controllers/authentications_controller.rb | 11 +-------- lib/actions/oauth_signup_action.rb | 24 ++++++++++++------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/app/controllers/authentications_controller.rb b/app/controllers/authentications_controller.rb index 8b84aa04c..34ed65aa8 100644 --- a/app/controllers/authentications_controller.rb +++ b/app/controllers/authentications_controller.rb @@ -7,16 +7,7 @@ class AuthenticationsController < ApplicationController auth = request.env['omniauth.auth'] @authentication = nil if auth - - name = '' - case auth['provider'] - when 'twitter' - name = auth['info']['nickname'] - when 'flickr', 'facebook' - name = auth['info']['name'] - else - name = auth['info']['name'] - end + name = Growstuff::OauthSignupAction.new.determine_name(auth) @authentication = current_member.authentications .create_with( diff --git a/lib/actions/oauth_signup_action.rb b/lib/actions/oauth_signup_action.rb index 144af6002..8102d53e8 100644 --- a/lib/actions/oauth_signup_action.rb +++ b/lib/actions/oauth_signup_action.rb @@ -38,15 +38,7 @@ class Growstuff::OauthSignupAction # - We need to create it # def establish_authentication(auth, member) - name = '' - case auth['provider'] - when 'twitter' - name = auth['info']['nickname'] - when 'flickr', 'facebook' - name = auth['info']['name'] - else - name = auth['info']['name'] - end + name = determine_name(auth) authentication = member.authentications .create_with( @@ -67,4 +59,18 @@ class Growstuff::OauthSignupAction def member_created? @member_created end + + def determine_name(auth) + name = '' + case auth['provider'] + when 'twitter' + name = auth['info']['nickname'] + when 'flickr', 'facebook' + name = auth['info']['name'] + else + name = auth['info']['name'] + end + + name + end end \ No newline at end of file