class Poptart::Question

Attributes

key[RW]
question_type[RW]
responses[RW]
text[RW]

Public Class Methods

all(params = {}) click to toggle source
# File lib/poptart/question.rb, line 36
def self.all(params = {})
  response = get(root.url(relation: 'questions'))
  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: [], question_type: nil, key: nil) click to toggle source
# File lib/poptart/question.rb, line 15
def self.create(text,
                responses: [],
                question_type: nil,
                key: nil)

  question_data = {
    'question_type' => question_type,
    'responses' => responses,
    'text' => text,
    'key' => key
  }
  url = root.url(relation: 'questions', method: 'POST')
  response = post(url, 'question' => question_data)
  new(response)
end
find(id_or_key) click to toggle source
# File lib/poptart/question.rb, line 31
def self.find(id_or_key)
  response = get(root.url(relation: 'questions', id: id_or_key))
  new(response)
end
new(response) click to toggle source
Calls superclass method Poptart::Model::new
# File lib/poptart/question.rb, line 7
def initialize(response)
  super
  @responses = params['responses']
  @question_type = params['question_type']
  @text = params['text']
  @key = params['key']
end