Module: QualtricsInterface

Included in:
BhtSurvey::QualtricsSurveysController
Defined in:
lib/bht_survey/qualtrics_interface.rb

Instance Method Summary collapse

Instance Method Details

#get_api(method_url, api_conditions) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/bht_survey/qualtrics_interface.rb', line 2

def get_api method_url, api_conditions
  url =   ENV['API_URL'] || 'http://api-assessment.bhtcloud.org/'
  connect_to_api = Faraday.new(url: url)  do |faraday|
    faraday.response :logger do | logger |
      logger.filter(/(api_key=)(\w+)/,'\1[REMOVED]') #TODO remove the qualtics key
    end
    faraday.adapter  Faraday.default_adapter  # make requests with Net::HTTP
  end

  local_response = connect_to_api.get method_url, api_conditions
  result = JSON.parse(local_response.body)
  result
end


45
46
47
48
49
# File 'lib/bht_survey/qualtrics_interface.rb', line 45

def get_participant_link participant_id, survey_name
  api_params = {workspace_key: get_workspace_key, participant_id: participant_id, assessment_name: survey_name}
  result = get_api 'api/v1/participant_link', api_params
  result['response']
end

#get_participant_state(participant_id, survey_name) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/bht_survey/qualtrics_interface.rb', line 36

def get_participant_state participant_id, survey_name
  states = get_participant_states participant_id
  result = states.detect{|state|state['name'] == survey_name}
  state = result && result['status']
  #flags = {nil => 0, 'not_started' => 0, 'in progress' => 1, 'responded' => 2}
  #flags[state] || 0
  state || 'not_started'
end

#get_participant_states(participant_id) ⇒ Object



30
31
32
33
34
# File 'lib/bht_survey/qualtrics_interface.rb', line 30

def get_participant_states participant_id
  api_params = {workspace_key: get_workspace_key, participant_id: participant_id}
  result = get_api 'api/v1/participant_states', api_params
  result['response']
end

#get_results(participant_id, survey_name) ⇒ Object



51
52
53
54
55
# File 'lib/bht_survey/qualtrics_interface.rb', line 51

def get_results participant_id, survey_name
  api_params = {workspace_key: get_workspace_key, participant_id: participant_id, assessment_name: survey_name}
  result = get_api 'api/v1/survey_results', api_params
  result['response']
end

#get_workspace_keyObject

Initialization parameters are used to provide credentials in RICE The Account table is used for saving credentials for multiple survey developers.



19
20
21
22
23
24
25
26
27
28
# File 'lib/bht_survey/qualtrics_interface.rb', line 19

def get_workspace_key
  api_params = {
    qualtrics_id: ENV['QUALTRICS_ID'],
    qualtrics_library: ENV['QUALTRICS_LIBRARY'],
    study_workspace_name: ENV['STUDY_WORKSPACE_NAME']
  }
  Rails.logger.debug ">>>>>>>>>>>>>>>>>>> #{api_params.inspect}"
  result = get_api 'api/v1/study_workspace', api_params
  result['response']['workspace_key']  
end


57
58
59
# File 'lib/bht_survey/qualtrics_interface.rb', line 57

def process_link_clicked_event participant_id, survey_name
  puts "===>>>> REPLACEME this method in application controller to track link click (in progress state) for  participant #{participant_id} accessing #{survey_name}"
end