class Qualtrics::Message

Constants

ALLOWED_CATEGORIES

Attributes

body[RW]
category[RW]
id[RW]
language[RW]
name[RW]

Public Class Methods

all(library_id = nil) click to toggle source
# 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_map() click to toggle source
# 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
new(options={}) click to toggle source
# 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

Public Instance Methods

attributes() click to toggle source

def destroy

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

end

# File lib/qualtrics/message.rb, line 53
def attributes
  {
    'LibraryID' => library_id,
    'Category' => category,
    'Name' => name,
    'Message' => body,
    'Language' => language
  }
end
save() click to toggle source
# 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