Class: Surveymonkey::Response

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/surveymonkey_api/response.rb

Overview

Response

Defined Under Namespace

Classes: Page, Question

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(survey_id, id, survey_structure = nil, survey_response = nil) ⇒ Response

Returns a new instance of Response.



7
8
9
10
11
12
13
# File 'lib/surveymonkey_api/response.rb', line 7

def initialize(survey_id, id, survey_structure = nil, survey_response = nil)
  @survey_id = survey_id
  @id = id
  @survey_response = survey_response
  @survey_structure = survey_structure
  @survey = Surveymonkey::Survey.new(survey_id)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/surveymonkey_api/response.rb', line 5

def id
  @id
end

#survey_idObject (readonly)

Returns the value of attribute survey_id.



5
6
7
# File 'lib/surveymonkey_api/response.rb', line 5

def survey_id
  @survey_id
end

#survey_responseObject (readonly)

Returns the value of attribute survey_response.



5
6
7
# File 'lib/surveymonkey_api/response.rb', line 5

def survey_response
  @survey_response
end

Instance Method Details

#infoObject



23
24
25
# File 'lib/surveymonkey_api/response.rb', line 23

def info
  raw_details.dup.tap { |h| h.delete('pages') }
end

#pages(options = {}) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/surveymonkey_api/response.rb', line 27

def pages(options = {})
  @pages ||= raw_details(options)['pages'].each_with_object([]) do |page, arr|
    unless page['questions'].empty?
      page_structure = survey_structure['pages'].detect { |p| p['id'] == page['id'] }
      arr << Surveymonkey::Response::Page.new(page, page_structure)
    end
  end
end

#raw_details(options = {}) ⇒ Object



19
20
21
# File 'lib/surveymonkey_api/response.rb', line 19

def raw_details(options = {})
  @raw_details ||= survey_response || client.survey_response(survey_id, id, options)
end

#survey_structureObject



15
16
17
# File 'lib/surveymonkey_api/response.rb', line 15

def survey_structure
  @survey_structure ||= details
end