Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8340375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:09:54+00:00 2026-06-09T05:09:54+00:00

quick question: i’m using the linkedin gem to pull user data, but my app

  • 0

quick question: i’m using the linkedin gem to pull user data, but my app breaks if a particular data field is blank on the user’s linkedin profile. is there an optimal way to scan each profile for blankness in all data fields and pull only those that are present to prevent breaking?

here is my auth_controller…i know it is not DRY and in need of refactoring. Thanks!

require 'linkedin'

class AuthController < ApplicationController

  def index
    client = LinkedIn::Client.new(ENV['LINKEDIN_KEY'], ENV['LINKEDIN_SECRET'])
    request_token = client.request_token(:oauth_callback => 
                                      "http://#{request.host_with_port}/callback")
    session[:rtoken] = request_token.token
    session[:rsecret] = request_token.secret
    redirect_to client.request_token.authorize_url
  end

  def callback
    client = LinkedIn::Client.new(ENV['LINKEDIN_KEY'], ENV['LINKEDIN_SECRET'])
    if session[:atoken].nil?
      pin = params[:oauth_verifier]
      atoken, asecret = client.authorize_from_request(session[:rtoken], session[:rsecret], pin)
      session[:atoken] = atoken
      session[:asecret] = asecret
    else
      client.authorize_from_access(session[:atoken], session[:asecret])
    end

        current_user = client.profile(:fields => %w(positions educations))
        @user = current_user
        educations = current_user.educations.all
        positions = current_user.positions.all

        companies = current_user.positions.all.map{ |t| t.company }

        @current_company = companies[0]['name']
      @past_company_one = companies[1]['name']
      @past_company_two = companies[2]['name']
      @past_company_three = companies[3]['name']

      @current_industry = companies[0]['industry']
    @past_industry_one = companies[1]['industry']
    @past_industry_two = companies[2]['industry']
    @past_industry_three = companies[3]['industry']

        @first_name = client.profile(:fields => ["first_name"]).first_name
    @last_name = client.profile(:fields => ["last_name"]).last_name
    @headline = client.profile(:fields => ["headline"]).headline
        @picture = client.profile(:fields => ["picture-url"]).picture_url

        @school_one_name = educations[0]['school-name']
        @school_one_degree = educations[0]['degree']
    @school_one_field = educations[0]['field-of-study']
    @school_one_start = educations[0]['start-date']['year'].to_s
    @school_one_end = educations[0]['end-date']['year'].to_s

    @school_two_name = educations[1]['school-name']
        @school_two_degree = educations[1]['degree']
    @school_two_field = educations[1]['field-of-study']
    @school_two_start = educations[1]['start-date']['year'].to_s
    @school_two_end = educations[1]['end-date']['year'].to_s

    @current_title = positions[0]['title']
    @past_title_one = positions[1]['title']
    @past_title_two = positions[2]['title']
    @past_title_three = positions[3]['title']

    @current_start_date = Date::MONTHNAMES[positions[0]['start-date']['month']] + " " + positions[0]['start-date']['year'].to_s

    @past_start_date_one = Date::MONTHNAMES[positions[1]['start-date']['month']] + " " + positions[1]['start-date']['year'].to_s
    @past_end_date_one = Date::MONTHNAMES[positions[1]['end-date']['month']] + " " + positions[1]['end-date']['year'].to_s

    @past_start_date_two = Date::MONTHNAMES[positions[2]['start-date']['month']] + " " + positions[2]['start-date']['year'].to_s
    @past_end_date_two = Date::MONTHNAMES[positions[2]['end-date']['month']] + " " + positions[2]['end-date']['year'].to_s

    @past_start_date_three = Date::MONTHNAMES[positions[3]['start-date']['month']] + " " + positions[3]['start-date']['year'].to_s
    @past_end_date_three = Date::MONTHNAMES[positions[3]['end-date']['month']] + " " + positions[3]['end-date']['year'].to_s

  end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T05:09:55+00:00Added an answer on June 9, 2026 at 5:09 am

    considering your current code may break upon any unexpected values in the response and assuming it’s happening in your above callback method, you may consider just applying quick’n’dirty exception handling to your code.

    for example, by simply enclosing the potentially offending code in a begin / end block and using a rescueclause to handle any exceptions:

    def callback
      client = LinkedIn::Client.new(ENV['LINKEDIN_KEY'], ENV['LINKEDIN_SECRET'])
    
      if session[:atoken].nil?
        # ...code
        else
        #...code
      end
    
      # start handling exceptions here
      begin
        # ...potentially offending code here
        current_user = client.profile(:fields => %w(positions educations))
        # ...more code
        @past_end_date_three = Date::MONTHNAMES[positions[3]['end-date']['month']] + " " + positions[3]['end-date']['year'].to_s
      rescue
        # oops, something happened:
        # ...your code to handle the exception here
      end
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Quick question (and sorry if it's already been asked, I have looked but couldn't
Quick question: I'm using jquery ajax to call a page that returns some json
Quick question, having a look around it seems this is the case, but it
Quick question i imagine, but i'm having trouble getting a clear answer from googling.
quick question. In my user database I have 5 separate tables all containing different
Quick Question: I have the following array (multidimensional): Array ( [preorder] => 0 [data]
Quick question, How does Game Center handle different app versions for turn based games?
Quick question, I found answers close to this but nothing that helps me. I
Quick question, I am working on an APNS enabled app and I just want
quick question here. I'm wondering how to create a 2D vector from user input.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.