Created
December 15, 2019 00:01
-
-
Save jrgifford/ea3d7240a909156615f372d72b87a535 to your computer and use it in GitHub Desktop.
PageMe - The Simple "Page somebody" library
This file contains hidden or 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
require 'pry' | |
require 'socket' | |
class PageMe | |
def initialize(server:, pager:, port: 444) | |
@server = server | |
@pager = pager | |
@port = port | |
end | |
def send_message!(subject:, message:) | |
send_command(connection, "PAGER #{@pager}") | |
send_command(connection, "SUBJECT #{subject}") | |
send_command(connection, "MESSAGE #{message}") | |
send_command(connection, "SEND") | |
send_command(connection, "QUIT") | |
connection.close | |
end | |
private | |
def send_command(socket, command_string) | |
socket.puts(command_string) | |
puts socket.gets | |
end | |
# This method returns a TCP connection | |
def connection | |
@connection ||= TCPSocket.new(@server, @port) | |
end | |
end | |
page = PageMe.new(server: "snpp.myairmail.com", pager: 6142419957) | |
page.send_message!(subject: "Hello, World!", message: "Isn't this nifty?") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment