Class: Applicants::ApplicantsController

Inherits:
ApplicationController show all
Includes:
ApplicantsHelper
Defined in:
app/controllers/applicants/applicants_controller.rb

Constant Summary collapse

PANEL_ID_PARAMETER_NAME =
'panel'
CALLBACK_ERROR_MESSAGES =
{
    ok:             "OK",
    internal_error: "Internal error",
    url_missing:    "URL is missing",
    id_missing:     "ID is missing",
    id_not_found:   "ID was not found",
    transition:     "Applicant already in final state. Callback Ignored."
}
EVENT_PARAM =
'event'
VIDEO_URL_PARAM =
'video_url'
VIDEO_RECEIVED_EVENT =
'video_received'

Instance Method Summary collapse

Methods included from ApplicantsHelper

#admin_navigation_link, #current_translations, #detect_user_operating_system, #icon, #macintosh_activator_filename, #macintosh_activator_url, #macintosh_installer_url, #macintosh_operating_system_user?, #mobile_operating_system_user?, #screen_recorder_descriptor_url, #stale_state, #test_exclude, #video_transition_time_string, #viewing?, #windows_activator_filename, #windows_activator_url, #windows_installer_url, #windows_operating_system_user?

Instance Method Details

#activatorObject



103
104
105
106
107
108
109
110
111
# File 'app/controllers/applicants/applicants_controller.rb', line 103

def activator
  if macintosh_operating_system_user?
    render :activator_mac
  elsif windows_operating_system_user?
    render :activator_win
  else
    render :activator_mobile
  end
end

#createObject



52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/applicants/applicants_controller.rb', line 52

def create
  @applicant = Applicants::Applicant.new(params[:applicant])
  if @applicant.save
    redirect_to thank_you_applicant_path(email: @applicant.email)
  else
    render :new
  end
rescue ActiveRecord::RecordNotUnique
  @applicant.errors.add :email, :taken
  render :new
end

#downloadObject



76
77
78
79
80
81
82
83
84
85
86
# File 'app/controllers/applicants/applicants_controller.rb', line 76

def download
  if macintosh_operating_system_user?
    render :download_mac
  elsif windows_operating_system_user?
    render :download_win
  elsif mobile_operating_system_user?
    render :download_mobile
  else
    render :download
  end
end

#indexObject



31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/applicants/applicants_controller.rb', line 31

def index
  respond_to do |format|
    format.html { redirect_to new_applicant_url }

    format.json do
      if params[:q]
        @applicants = Applicants::Applicant.where(params[:q])
      end
    end
  end
end

#legacy_video_readyObject



64
65
66
67
# File 'app/controllers/applicants/applicants_controller.rb', line 64

def legacy_video_ready
  @applicant.video_ready!
  render nothing: true, status: :ok
end

#newObject



43
44
45
46
47
48
49
50
# File 'app/controllers/applicants/applicants_controller.rb', line 43

def new
  @applicant = Applicants::Applicant.new
  if @panel
    @applicant.panel = @panel
    @applicant.build_applicant_panel_parameter_set(panel_id: @panel.id, parameters: @parameters.to_json)
  end
  respond_with(@applicant)
end

#resend_confirmation_emailObject



96
97
98
99
100
101
# File 'app/controllers/applicants/applicants_controller.rb', line 96

def resend_confirmation_email
  if @applicant = Applicants::Applicant.find_by_email(params[:email])
    resend_email
  end
    render json: {message: I18n.t('applicants.request_response.email.check_email')}
end

#screen_recorder_callbacksObject



69
70
71
72
73
74
# File 'app/controllers/applicants/applicants_controller.rb', line 69

def screen_recorder_callbacks
  if params.has_key? :questions
    @applicant.update_attribute(:answers, params[:questions])
  end
  render text: "1"
end

#thank_youObject



27
28
29
# File 'app/controllers/applicants/applicants_controller.rb', line 27

def thank_you
  @email = params[:email]
end

#tipsObject



88
89
90
91
92
93
94
# File 'app/controllers/applicants/applicants_controller.rb', line 88

def tips
  if macintosh_operating_system_user?
    render :tips_mac
  else
    render :tips
  end
end

#video_server_callbackObject

example: curl -v -X PUT -H “Content-Type: application/json” -d “href="www.abc.com">www.abc.com"” “localhost:3000/applicants/–APPLICANT_ID–/video_server_callback



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'app/controllers/applicants/applicants_controller.rb', line 118

def video_server_callback
  # we can ignore this event; we only care about 'video_processed_mp4'
  event = params[EVENT_PARAM]
  render text: CALLBACK_ERROR_MESSAGES[:ok],           status: 200 and return if event == VIDEO_RECEIVED_EVENT

  url = Applicants::VideoUrlUtility.new(params[VIDEO_URL_PARAM].to_s).strip_params
  render text: CALLBACK_ERROR_MESSAGES[:url_missing],  status: 400 and return if url.blank?
  render text: CALLBACK_ERROR_MESSAGES[:id_not_found], status: 404 and return if @applicant.nil? && params[:id].present?
  render text: CALLBACK_ERROR_MESSAGES[:id_missing],   status: 400 and return if @applicant.nil?
  render text: CALLBACK_ERROR_MESSAGES[:transition],   status: 200 and return if @applicant.unacceptable_transition_for_video_ready?

  if @applicant.videos.create(video_url: url)
    @applicant.video_ready!
    render text: CALLBACK_ERROR_MESSAGES[:ok], status: 200
  else
    render text: CALLBACK_ERROR_MESSAGES[:internal_error], status: 500
  end
end