-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01_basic_usage.rb
More file actions
50 lines (42 loc) · 1.13 KB
/
01_basic_usage.rb
File metadata and controls
50 lines (42 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true
# Basic usage example for kwtsms Ruby gem
#
# Setup:
# gem install kwtsms
#
# Create a .env file:
# KWTSMS_USERNAME=ruby_username
# KWTSMS_PASSWORD=ruby_password
# KWTSMS_SENDER_ID=YOUR-SENDER
# KWTSMS_TEST_MODE=1
require "kwtsms"
# Create client from environment variables / .env file
sms = KwtSMS::Client.from_env
# Verify credentials and check balance
ok, balance, err = sms.verify
if ok
puts "Connected! Balance: #{balance} credits"
else
puts "Failed: #{err}"
exit 1
end
# Send a single SMS
result = sms.send_sms("96598765432", "Hello from kwtsms-ruby!")
if result["result"] == "OK"
puts "Sent! msg-id: #{result['msg-id']}"
puts "Balance after: #{result['balance-after']}"
else
puts "Error: #{result['description']}"
puts "Action: #{result['action']}" if result["action"]
end
# Send to multiple numbers
result = sms.send_sms(
["96598765432", "96512345678"],
"Bulk message test"
)
puts result.inspect
# Validate phone numbers
report = sms.validate(["96598765432", "invalid", "+96512345678"])
puts "Valid: #{report['ok']}"
puts "Errors: #{report['er']}"
puts "Rejected: #{report['rejected']}"