Module: Missinglink

Extended by:
Missinglink
Includes:
Connection
Included in:
Missinglink
Defined in:
lib/missinglink.rb,
lib/missinglink/engine.rb,
lib/missinglink/version.rb,
lib/missinglink/connection.rb,
app/models/missinglink/survey.rb,
app/models/missinglink/survey_page.rb,
app/models/missinglink/survey_answer.rb,
app/models/missinglink/survey_question.rb,
app/models/missinglink/survey_response.rb,
app/helpers/missinglink/application_helper.rb,
app/models/missinglink/survey_page_question.rb,
app/models/missinglink/survey_response_answer.rb,
app/models/missinglink/survey_respondent_detail.rb,
app/controllers/missinglink/application_controller.rb

Defined Under Namespace

Modules: ApplicationHelper, Connection Classes: ApplicationController, Engine, Survey, SurveyAnswer, SurveyPage, SurveyPageQuestion, SurveyQuestion, SurveyRespondentDetail, SurveyResponse, SurveyResponseAnswer

Constant Summary collapse

VERSION =
"0.2.6"

Instance Method Summary collapse

Methods included from Connection

#credential_hash=, #credentials_provided?, #request

Instance Method Details

#answer_strategiesObject



40
41
42
# File 'lib/missinglink.rb', line 40

def answer_strategies
  @@answer_strategies ||= YAML.load_file(File.join(File.dirname(File.expand_path(__FILE__)), "../etc/question_types.yml"))
end

#fetch_respondents(survey) ⇒ Object



26
27
28
29
30
# File 'lib/missinglink.rb', line 26

def fetch_respondents(survey)
  return if survey.load_respondents.nil?

  fetch_responses(survey.reload)
end

#fetch_response_answers(survey, respondents) ⇒ Object



36
37
38
# File 'lib/missinglink.rb', line 36

def fetch_response_answers(survey, respondents)
  survey.load_response_details(respondents)
end

#fetch_responses(survey) ⇒ Object



32
33
34
# File 'lib/missinglink.rb', line 32

def fetch_responses(survey)
  fetch_response_answers(survey, survey.respondents_to_update)
end

#poll_surveysObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/missinglink.rb', line 9

def poll_surveys
  begin
    response = Connection.request('get_survey_list')
  rescue Exception => e
    puts "Exception raised when polling for surveys.\n#{ e.inspect }"
    return -1
  end

  (puts "Error polling surveys" && return) unless response

  response['surveys'].each do |s|
    survey = Survey.first_or_create_by_sm_survey_id(s['survey_id'].to_i)
    survey.update_attributes(analysis_url: s['analysis_url'])
    survey.load_survey_details
  end
end