Last active
August 2, 2017 13:41
-
-
Save zaingz/2cb67f19182adf61d0f05a7ab23aca6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'bundler/setup' | |
require 'csv' | |
require "pathname" | |
require "em-http-request" | |
require "date" | |
current_date = DateTime.now | |
limit_date = Date.strptime("08/05/2017", "%m/%d/%Y") | |
if (current_date > limit_date) | |
puts "Trail is over!" | |
abort("Contact the owner, Please!") | |
end | |
data = [] | |
puts "Drag CSV file here" | |
path = Pathname.new(gets.chomp.gsub("'","").strip!) | |
puts path.to_s | |
csv_text = File.read(path) | |
csv = CSV.parse(csv_text, :headers => true) | |
csv.each do |row| | |
data << {mob: row[0], name: row[1], account: row[2]} | |
end | |
puts "Drag TXT file containg the sms body here" | |
path = Pathname.new(gets.chomp.gsub("'","").strip!) | |
text = File.read(path) | |
EventMachine.run { | |
multi = EventMachine::MultiRequest.new | |
data.each do |row, i| | |
msg = %( | |
Dear #{row[:name]}, | |
Account # #{row[:account]} | |
#{text} | |
) | |
multi.add :"#{SecureRandom.base64}", EventMachine::HttpRequest.new('https://api.zipwhip.com/messaging/send').post(body: {session: "25655890-fa2e-4c0a-a60c-44ae477625be:343254802", to: "1#{row[:mob]}", body: msg}) | |
puts "Queued request for recipient #{row[:name]} . . ." | |
end | |
multi.callback do | |
puts "Sent #{multi.responses[:callback].size} SMS" | |
puts "Failed #{multi.responses[:errback].size} SMS" | |
puts "Bye" | |
EventMachine.stop | |
end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment