Module: Ohmage::API::Survey

Included in:
Ohmage::API
Defined in:
lib/ohmage/survey.rb

Instance Method Summary collapse

Instance Method Details

#survey_response_delete(params = {}) ⇒ Object

ohmage survey_response/delete call



42
43
44
45
# File 'lib/ohmage/survey.rb', line 42

def survey_response_delete(params = {})
  request = Ohmage::Request.new(self, :post, 'survey_response/delete', params)
  request.perform
end

#survey_response_read(params = {}) ⇒ Object

ohmage survey_response/read call



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

def survey_response_read(params = {}) # rubocop:disable all
  params[:column_list] = params[:column_list] || 'urn:ohmage:special:all'
  params[:output_format] = params[:output_format] || 'json-rows'
  params[:user_list] = params[:user_list] || 'urn:ohmage:special:all'
  params[:prompt_id_list] = 'urn:ohmage:special:all' unless params[:prompt_id_list] || params[:survey_id_list]
  request = Ohmage::Request.new(self, :post, 'survey_response/read', params)
  t = []
  # We can't possibly make Ohmage::SurveyReponse objects unless we use json-rows. json-columns and csv output is so odd for this.
  if params[:output_format] == 'json-rows' && params[:collapse] != true
    request.perform[:data].each do |v|
      t << Ohmage::SurveyResponse.new(v[:survey_key] => v)
    end
    t
  else
    request.perform
  end
end

#survey_response_update(params = {}) ⇒ Object

ohmage survey_response/update call



32
33
34
35
# File 'lib/ohmage/survey.rb', line 32

def survey_response_update(params = {})
  request = Ohmage::Request.new(self, :post, 'survey_response/update', params)
  request.perform
end

#survey_upload(params = {}) ⇒ Object

ohmage survey/upload call



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ohmage/survey.rb', line 52

def survey_upload(params = {})
  # loop around params, finding attached images/files, set them as form data.
  params.each do |param|
    if /[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}/.match(param.first)
      @mime_type = /[^;]*/.match(`file -b --mime "#{param[1]}"`)[0]
      params[param[0]] = HTTP::FormData::File.new(param[1], mime_type: @mime_type)
    end
    next
  end
  request = Ohmage::Request.new(self, :post, 'survey/upload', params)
  request.perform
end