Sha256: 307dd2ec8f6afc587473abfe3822c5518df4f92ec5fd8955dd40338997330ae9

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

require_relative '../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 = Esendex::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 = Esendex::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

2 entries across 2 versions & 1 rubygems

Version Path
esendex-0.4.0 lib/tasks/esendex.rake
esendex-0.3.2 lib/tasks/esendex.rake