class Qualtrics::Mailer

Attributes

from_email[RW]
from_name[RW]
send_date[RW]
sent_from_address[RW]
subject[RW]

Public Class Methods

new(options={}) click to toggle source
# File lib/qualtrics/mailer.rb, line 15
def initialize(options={})
  @send_date = options[:send_date] || post_time
  @from_email = options[:from_email]
  @from_name = options[:from_name]
  @subject = options[:subject]
  @sent_from_address = options[:sent_from_address] || 'noreply@qemailserver.com'
end

Public Instance Methods

attributes() click to toggle source
# File lib/qualtrics/mailer.rb, line 82
def attributes
  {
    'SendDate'        => send_date,
    'FromEmail'       => from_email,
    'FromName'        => from_name,
    'Subject'         => subject,
    'SentFromAddress' => sent_from_address
  }
end
send_reminder(distribution, message) click to toggle source
# File lib/qualtrics/mailer.rb, line 64
def send_reminder(distribution, message)
  return false if !valid?

  response = post('sendReminder', attributes.merge(
    {
      'ParentEmailDistributionID' => distribution.id,
      'MessageID' => message.id,
      'LibraryID' => library_id,
    })
  )

  if response.success?
    create_distribution(response, distribution.survey_id, message.id)
  else
    false
  end
end
send_survey_to_individual(recipient, message, survey) click to toggle source
# File lib/qualtrics/mailer.rb, line 23
def send_survey_to_individual(recipient, message, survey)
  return false if !valid?

  response = post('sendSurveyToIndividual', attributes.merge(
    {
      'RecipientID' => recipient.id,
      'MessageID' => message.id,
      'SurveyID' => survey.id,
      'MessageLibraryID' => library_id,
      'PanelID' => recipient.panel_id,
      'PanelLibraryID' => library_id
    })
  )

  if response.success?
    create_distribution(response, survey.id, message.id)
  else
    false
  end
end
send_survey_to_panel(panel, message, survey) click to toggle source
# File lib/qualtrics/mailer.rb, line 44
def send_survey_to_panel(panel, message, survey)
  return false if !valid?

  response = post('sendSurveyToPanel', attributes.merge(
    {
      'PanelID' => panel.id,
      'MessageID' => message.id,
      'SurveyID' => survey.id,
      'MessageLibraryID' => library_id,
      'PanelLibraryID' => library_id
    })
  )

  if response.success?
    create_distribution(response, survey.id, message.id)
  else
    false
  end
end

Private Instance Methods

create_distribution(response, survey_id, message_id) click to toggle source
# File lib/qualtrics/mailer.rb, line 98
def create_distribution(response, survey_id, message_id)
  Qualtrics::Distribution.new({
    message_id: message_id,
    survey_id: survey_id,
    id: response.result['EmailDistributionID']
  })
end
post_time() click to toggle source
# File lib/qualtrics/mailer.rb, line 94
def post_time
  formatted_time Time.now
end