Class: Qualtrics::Message

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

Constant Summary collapse

ALLOWED_CATEGORIES =
%w(InviteEmails InactiveSurveyMessages ReminderEmails
ThankYouEmails EndOfSurveyMessages GeneralMessages
ValidationMessages LookAndFeelMessages)

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 = {}) ⇒ Message

Returns a new instance of Message.



24
25
26
27
28
29
30
31
# File 'lib/qualtrics/message.rb', line 24

def initialize(options={})
  @name = options[:name]
  @id = options[:id]
  @category = options[:category]
  @library_id = options[:library_id]
  @body = options[:body]
  @language = options[:language] || 'EN'
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



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

def body
  @body
end

#categoryObject

Returns the value of attribute category.



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

def category
  @category
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#languageObject

Returns the value of attribute language.



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

def language
  @language
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.all(library_id = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/qualtrics/message.rb', line 10

def self.all(library_id = nil)
  lib_id = library_id || configuration.default_library_id
  response = get('getLibraryMessages', {'LibraryID' => lib_id})
  if response.success?
    response.result.map do |category, messages|
      messages.map do |message_id, name|
        new(id: message_id, name: name, category: category_map[category])
      end
    end.flatten
  else
    []
  end
end

.category_mapObject



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/qualtrics/message.rb', line 63

def self.category_map
  {
    'INVITE' =>         'InviteEmails',
    'REMINDER' =>       'ReminderEmails',
    'THANKYOU' =>       'ThankYouEmails',
    'ENDOFSURVEY' =>    'EndOfSurveyMessages',
    'INACTIVESURVEY' => 'InactiveSurveyMessages',
    'GENERAL' =>        'GeneralMessages',
    'LOOKANDFEEL' =>    'LookAndFeelMessages'
  }
end

Instance Method Details

#attributesObject

def destroy

response = post('deleteLibraryMessage', {
  'LibraryID' => library_id,
  'MessageID' => self.id
})
response.success?

end



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

def attributes
  {
    'LibraryID' => library_id,
    'Category' => category,
    'Name' => name,
    'Message' => body,
    'Language' => language
  }
end

#saveObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/qualtrics/message.rb', line 33

def save
  return false if !valid?
  response = post('createLibraryMessage', attributes)

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