Class: Qualtrics::Panel

Inherits:
Entity
  • Object
show all
Defined in:
lib/qualtrics/panel.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Entity

#configuration, configuration, #get, get, #library_id, #library_id=, #persisted?, post, #post, #success?, underscore_attributes

Constructor Details

#initialize(options = {}) ⇒ Panel

Returns a new instance of Panel.



30
31
32
33
34
35
# File 'lib/qualtrics/panel.rb', line 30

def initialize(options={})
  @name = options[:name]
  @id = options[:id]
  @category = options[:category]
  @library_id = options[:library_id]
end

Instance Attribute Details

#categoryObject

Returns the value of attribute category.



7
8
9
# File 'lib/qualtrics/panel.rb', line 7

def category
  @category
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/qualtrics/panel.rb', line 7

def id
  @id
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/qualtrics/panel.rb', line 7

def name
  @name
end

Class Method Details

.all(library_id = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/qualtrics/panel.rb', line 9

def self.all(library_id = nil)
  lib_id = library_id || configuration.default_library_id
  response = get('getPanels', {'LibraryID' => lib_id})
  if response.success?
    response.result['Panels'].map do |panel|
      new(underscore_attributes(panel))
    end
  else
    []
  end
end

.attribute_mapObject



21
22
23
24
25
26
27
28
# File 'lib/qualtrics/panel.rb', line 21

def self.attribute_map
  {
    'LibraryID' => :library_id,
    'Category' => :category,
    'Name' => :name,
    'PanelID' => :id
  }
end

Instance Method Details

#attributesObject



61
62
63
64
65
66
67
# File 'lib/qualtrics/panel.rb', line 61

def attributes
  {
    'LibraryID' => library_id,
    'Category' => category,
    'Name' => name
  }
end

#destroyObject



53
54
55
56
57
58
59
# File 'lib/qualtrics/panel.rb', line 53

def destroy
  response = post('deletePanel', {
    'LibraryID' => library_id,
    'PanelID' => self.id
    })
  response.success?
end

#saveObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/qualtrics/panel.rb', line 37

def save
  response = nil
  if persisted?
    raise Qualtrics::UpdateNotAllowed
  else
    response = post('createPanel', attributes)
  end

  if response.success?
    self.id = response.result['PanelID']
    true
  else
    false
  end
end