Sha256: 73a9585e35acf768a00cde185ae77662a519c8e34191badc62db5d5a339059ad

Contents?: true

Size: 1.45 KB

Versions: 24

Compression:

Stored size: 1.45 KB

Contents

#########################################################################
# Operation to send email to a group of workers.                        #
#                                                                       #
# Caveats:                                                              #
#   - A message can only be send to a maximum of 100 workers at a time. #
#   - The message length must be 4096 characters or less.               #
#   - The subject length must be 200 characters or less.                #
#########################################################################

module RTurk
  class NotifyWorkers < Operation
    attr_accessor :worker_ids, :subject, :message_text
    require_params :worker_ids, :subject, :message_text

    def to_params
      message_text.strip!

      if worker_ids.length > 100
        raise ArgumentError, 'Cannot send a message to more than 100 workers at a time.'
      elsif message_text.length > 4096
        raise ArgumentError, 'Message cannot be longer than 4096 characters.'
      elsif subject.length > 200
        raise ArgumentError, 'Subject cannot be longer than 200 characters.'
      end

      id_hash = {}
      worker_ids.each_with_index do |worker_id, index|
        id_hash["WorkerId.#{index}"] = worker_id
      end

      { 'Subject'     => self.subject,
        'MessageText' => self.message_text }.merge(id_hash)
    end
  end

  def self.NotifyWorkers(*args)
    RTurk::NotifyWorkers.create(*args)
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
rturk-2.12.1 lib/rturk/operations/notify_workers.rb
rturk-2.12.0 lib/rturk/operations/notify_workers.rb
rturk-2.11.3 lib/rturk/operations/notify_workers.rb
rturk-2.11.2 lib/rturk/operations/notify_workers.rb
rturk-2.11.1 lib/rturk/operations/notify_workers.rb
rturk-2.11.0 lib/rturk/operations/notify_workers.rb
rturk-2.10.3 lib/rturk/operations/notify_workers.rb
rturk-2.10.2 lib/rturk/operations/notify_workers.rb
rturk-2.10.1 lib/rturk/operations/notify_workers.rb
rturk-2.10.0 lib/rturk/operations/notify_workers.rb
rturk-2.9.0 lib/rturk/operations/notify_workers.rb
rturk-2.8.0 lib/rturk/operations/notify_workers.rb
rturk-2.7.0 lib/rturk/operations/notify_workers.rb
rturk-2.6.0 lib/rturk/operations/notify_workers.rb
rturk-2.5.2 lib/rturk/operations/notify_workers.rb
rturk-2.5.0 lib/rturk/operations/notify_workers.rb
rturk-2.4.1 lib/rturk/operations/notify_workers.rb
rturk-2.4.0 lib/rturk/operations/notify_workers.rb
rturk-2.3.6 lib/rturk/operations/notify_workers.rb
rturk-2.3.5 lib/rturk/operations/notify_workers.rb