lib/ghtorrent/ghtorrent.rb
def ensure_user_byuname(user)
      users = db[:users]
      usr = users.first(:login => user)

      if usr.nil?
        u = retrieve_user_byusername(user)

        if u.nil?
          warn "User #{user} does not exist"
          return
        end

        email = unless u['email'].nil?
                  if u['email'].strip == '' then
                    nil
                  else
                    u['email'].strip
                  end
                end

        geo = geolocate(location: u['location'])

        users.insert(:login => u['login'],
                     :name => u['name'],
                     :company => u['company'],
                     :email => email,
                     :fake => false,
                     :deleted => false,
                     :type => user_type(u['type']),
                     :long => geo[:long],
                     :lat => geo[:lat],
                     :country_code => geo[:country_code],
                     :state => geo[:state],
                     :city => geo[:city],
                     :created_at => date(u['created_at']))

        info "Added user #{user}"

        if user_type(u['type']) == 'ORG'
          info "User #{user} is an organization. Retrieving members"
          ensure_org(u['login'], true)
        end

        users.first(:login => user)
      else
        debug "User #{user} exists"
        usr
      end
    end
def ensure_user_byuname(user)
      users = db[:users]
      usr = users.first(:login => user)

      if usr.nil?
        u = retrieve_user_byusername(user)

        if u.nil?
          warn "User #{user} does not exist"
          return
        end

        email = unless u['email'].nil?
                  if u['email'].strip == '' then
                    nil
                  else
                    u['email'].strip
                  end
                end

        geo = geolocate(location: u['location'])

        users.insert(:login => u['login'],
                     :name => u['name'],
                     :company => u['company'],
                     :email => email,
                     :fake => false,
                     :deleted => false,
                     :type => user_type(u['type']),
                     :long => geo[:long],
                     :lat => geo[:lat],
                     :country_code => geo[:country_code],
                     :state => geo[:state],
                     :city => geo[:city],
                     :created_at => date(u['created_at']))

        info "Added user #{user}"

        if user_type(u['type']) == 'ORG'
          info "User #{user} is an organization. Retrieving members"
          ensure_org(u['login'], true)
        end

        users.first(:login => user)
      else
        debug "User #{user} exists"
        usr
      end
    end
Ensure that a user exists, or fetch its latest state from Github
 ==Parameters:
  user::
     The login name to lookup the user by

 == Returns:
 If the user can be retrieved, it is returned as a Hash. Otherwise,
 the result is nil