How Can I Send Sms Using Ruby?
If you are using Linux or Mac, run the following command in the Terminal to install Ruby:
sudo apt install ruby # Debian/Ubuntu brew install ruby # macOS ruby -v # Check Ruby version
Copy and paste this code into a Ruby script, save the file as send_sms.rb, and replace its contents with the provided Ruby code. Then, update the Authentication_id and Authentication_key with your credentials. Click Authentication Key ID, and a page will display your 32-character Authentication ID and 32-character Authentication Key, which you can copy and paste into the script.
require 'net/http' require 'json' url = URI("https://msgpserver.com/api/") payload = { mtype: "N", to: "+91XXXXXXXXXX", message: "This is a test message from Ruby...", auth_id: "Authentication_Id", auth_key: "Authentication_Key" }.to_json http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url, { 'Content-Type' => 'application/json' }) request.body = payload response = http.request(request) puts "Response: #{response.body}"
Return Success Response.
[ SUCCESS ] {'status': 'success', 'login': 'success', 'recharge': 'success', 'host': 'success', 'msg': 'success'}
Return Error Response.
[ ERROR ] {'status': 'success', 'login': 'success', 'recharge': 'success', 'host': 'error', 'msg': 'error'} {'status': 'success', 'login': 'success', 'recharge': 'expire', 'host': 'error', 'msg': 'error'} {'status': 'online', 'login': 'error', 'recharge': 'error', 'host': 'error', 'msg': 'error'}
Are you satisfied this Answer?