module QualtricsInterface
Public Instance Methods
get_api(method_url, api_conditions)
click to toggle source
# 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
get_participant_link(participant_id, survey_name)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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_key()
click to toggle source
Initialization parameters are used to provide credentials in RICE The Account table is used for saving credentials for multiple survey developers.
# 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
process_link_clicked_event(participant_id, survey_name)
click to toggle source
# 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