Sha256: eeb6411d39256f1825ffc37f18f36984dfbc50742b61a8572164c103d4695937

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

require_relative '../esendex'
include Esendex

namespace :esendex do
  desc "Validates whether credentials are correct and returns message credit balance"
  task :validate, [:username, :password, :account_reference] do |t, args|
    begin
      Esendex.configure do |config|
        config.username = args.username
        config.password = args.password
        config.account_reference = args.account_reference
      end
      account = Account.new
      messages_remaining = account.messages_remaining
      puts "Validated user #{Esendex.username} on account #{account.reference}. #{messages_remaining} messages remaining"
    rescue => e
      puts "Failed to validate credentials #{e.message}"
    end
  end

  desc "Sends a message using the credentials specifed in the environment"
  task :send_message, [:to, :body, :from] do |t, args|
    begin
      account = Account.new
      batch_id = account.send_message(args)
      puts "Message sent to #{args.to}. Batch ID: #{batch_id}"
    rescue => e
      puts "Failed to send message #{e.message}"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
esendex-0.3.1 lib/tasks/esendex.rake
esendex-0.3.0 lib/tasks/esendex.rake
esendex-0.2.3 lib/tasks/esendex.rake