Class: Poptart::Question

Inherits:
Model
  • Object
show all
Extended by:
Request
Defined in:
lib/poptart/question.rb

Instance Attribute Summary collapse

Attributes inherited from Model

#id, #links, #params, #root

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Request

connection, get, post, put

Methods inherited from Model

#questions_url, root, #survey_questions_url, #surveys_url, #users_url

Constructor Details

#initialize(response) ⇒ Question

Returns a new instance of Question.



7
8
9
10
11
12
13
14
15
# File 'lib/poptart/question.rb', line 7

def initialize(response)
  super
  @responses = params['responses']
  @freeform = params['freeform']
  @question_type = params['question_type']
  @absolute_index = params['absolute_index']
  @parent_question_id = params['parent_question_id']
  @key = params['key']
end

Instance Attribute Details

#absolute_indexObject

Returns the value of attribute absolute_index.



5
6
7
# File 'lib/poptart/question.rb', line 5

def absolute_index
  @absolute_index
end

#freeformObject

Returns the value of attribute freeform.



5
6
7
# File 'lib/poptart/question.rb', line 5

def freeform
  @freeform
end

#keyObject

Returns the value of attribute key.



5
6
7
# File 'lib/poptart/question.rb', line 5

def key
  @key
end

#parent_question_idObject

Returns the value of attribute parent_question_id.



5
6
7
# File 'lib/poptart/question.rb', line 5

def parent_question_id
  @parent_question_id
end

#question_typeObject

Returns the value of attribute question_type.



5
6
7
# File 'lib/poptart/question.rb', line 5

def question_type
  @question_type
end

#responsesObject

Returns the value of attribute responses.



5
6
7
# File 'lib/poptart/question.rb', line 5

def responses
  @responses
end

Class Method Details

.all(params = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/poptart/question.rb', line 28

def self.all(params = {})
  response = get(root.questions_url)
  JSON.parse(response.body).map do |question|
    if params[:type]
      if question['question_type'] == params[:type]
        new(question)
      end
    else
      new(question)
    end
  end.compact
end

.create(text, responses: [], freeform: false, absolute_index: nil, parent_question_id: nil, key: nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/poptart/question.rb', line 17

def self.create(text, responses: [], freeform: false, absolute_index: nil, parent_question_id: nil, key: nil)
  response = post(root.questions_url, question: { question_type: question_type,
                                                  responses: responses,
                                                  text: text,
                                                  freeform: freeform,
                                                  absolute_index: absolute_index,
                                                  parent_question_id: parent_question_id,
                                                  key: key})
  new(response)
end

Instance Method Details

#freeform?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/poptart/question.rb', line 41

def freeform?
  @freeform
end