class EMG::MGP

  1. mgp.rb
Superclass: Object

This class is the actual protocol implementation

Constants

A_ETX = 3  
A_STX = 2  

Misc

ERR_BOUND = 4  
ERR_BUSY = 17  
ERR_COMM = 13  
ERR_CREDITS = 16  
ERR_DB = 14  
ERR_INVALARG = 5  
ERR_INVALCMD = 6  
ERR_INVALDESTADDR = 8  
ERR_INVALMSGID = 7  
ERR_INVALRESP = 12  
ERR_INVALSOURCEADDR = 9  
ERR_LOGIN = 3  
ERR_MESSAGE = 11  
ERR_NOACCESS = 10  
ERR_OK = 0  

Return codes

ERR_SYNTAX = 2  
ERR_TOOLONG = 18  
ERR_UDH = 15  
ERR_UNKNOWN = 1  
OPTION_ACLENTRYWHEREID = 0x008f  
OPTION_ACLENTRYWHOID = 0x008e  
OPTION_ARCORFUNC = 0x00a5  
OPTION_ARCORMOD = 0x00a4  
OPTION_ARCORUNIT = 0x00a6  
OPTION_AUROUTE = 0x00bc  
OPTION_AUROUTELIST = 0x00bd  
OPTION_AUTHCODE = 0x001d  
OPTION_AUTHNPI = 0x004e  
OPTION_AUTHTON = 0x004d  
OPTION_AVGINSTANCES1 = 0x0079  
OPTION_BILLINGID = 0x004f  
OPTION_BUFFEREDSTATUS = 0x00b3  
OPTION_CALLBACKNUM = 0x0030  
OPTION_CANCELMODE = 0x0039  
OPTION_CHARCODE = 0x001c  
OPTION_CHARGE = 0x00bf  
OPTION_CHARGE_COST = 0x00c0  
OPTION_CHARGE_COST_PRICE_ID = 0x00c2  
OPTION_CHARGE_PRICE_ID = 0x00c1  
OPTION_CHARGE_RESELLER = 0x00c9  
OPTION_CHARGE_RESELLER_PRICE_ID = 0x00ca  
OPTION_CLIENTCONFIG = 0x0062  
OPTION_COMPANY = 0x0063  
OPTION_CONCATSMSMAX = 0x004b  
OPTION_CONCATSMSREF = 0x0049  
OPTION_CONCATSMSSEQ = 0x004a  
OPTION_CONNECTOR = 0x003b  
OPTION_CONTENTLOCATION = 0x00a1  
OPTION_CONTENTTYPE = 0x00a0  
OPTION_CREDITS = 0x007f  
OPTION_CUSTOM_OPTION = 0x00c7  
OPTION_DBDATA = 0x007e  
OPTION_DBNAME = 0x007d  
OPTION_DBSQL = 0x007c  
OPTION_DCS = 0x0071  
OPTION_DELTIME = 0x0014  
OPTION_DESTADDR = 0x0008  
OPTION_DESTADDRNPI = 0x000a  
OPTION_DESTADDRSUBUNIT = 0x000d  
OPTION_DESTADDRTON = 0x0009  
OPTION_DESTADDRTYPE = 0x0081  
OPTION_DESTFULLNAME = 0x00a2  
OPTION_DESTNETWORK = 0x00b0  
OPTION_DESTNETWORKTYPE = 0x003f  
OPTION_DESTPORT = 0x000c  
OPTION_DESTSUBADDRESS = 0x000b  
OPTION_DLR = 0x0013  
OPTION_DLRADDRESS = 0x0046  
OPTION_DLRBUF = 0x00a3  
OPTION_DLREXPIRES = 0x0042  
OPTION_DLRID = 0x0051  
OPTION_DLRPID = 0x0047  
OPTION_DLR_IN = 0x00b7  
OPTION_DLR_OUT = 0x00b8  
OPTION_DOMAIN = 0x0048  
OPTION_DONETS = 0x0098  
OPTION_ENDMSECS = 0x0060  
OPTION_ENDSECS = 0x005f  
OPTION_HEADER = 0x0073  
OPTION_HPLMNADDR = 0x006e  
OPTION_ID = 0x0001  

Options

OPTION_IMSI = 0x008a  
OPTION_INREPLYTO = 0x009a  
OPTION_INSTANCE = 0x005b  
OPTION_INSTANCES = 0x0055  
OPTION_INSTANCES_INUSE = 0x00af  
OPTION_INTERFACEVERSION = 0x003a  
OPTION_ISADMIN = 0x0069  
OPTION_ITSSESSIONINFO = 0x00ab  
OPTION_KEYWORD = 0x0074  
OPTION_LANGUAGEINDICATOR = 0x0031  
OPTION_LAST = 0x00d0  
OPTION_LASTDLRMSECS = 0x00ad  
OPTION_LASTDLRSECS = 0x00ac  
OPTION_LICENSEDATA = 0x00c8  
OPTION_LONGMESSAGE = 0x0036  
OPTION_LONGMODE = 0x0037  
OPTION_LRADDR = 0x006c  
OPTION_LRPID = 0x006d  
OPTION_MAPPING = 0x0045  
OPTION_MAXINSTANCES = 0x0078  
OPTION_MAXMESSAGELENGTH = 0x0072  
OPTION_MAXQUEUESIZE = 0x00cc  
OPTION_MAXQUEUESIZE_SOFT = 0x00cd  
OPTION_MCC = 0x00ce  
OPTION_MESSAGE = 0x0010  
OPTION_MESSAGEID = 0x0099  
OPTION_MESSAGELEN = 0x0011  
OPTION_MESSAGEMODE = 0x002a  
OPTION_MESSAGESTATE = 0x0034  
OPTION_MESSAGE_ERROR = 0x00ba  
OPTION_MMSDESTADDR = 0x0091  
OPTION_MMS_RELAY_SERVER_ID = 0x00b6  
OPTION_MNC = 0x00cf  
OPTION_MODE = 0x007b  
OPTION_MORE_MESSAGES = 0x00c5  
OPTION_MSC = 0x00d0  
OPTION_MSGCLASS = 0x001b  
OPTION_MSGSUBTYPE = 0x001a  
OPTION_MSGTYPE = 0x0019  
OPTION_MSISDN = 0x0092  
OPTION_NAME = 0x0064  
OPTION_NETWORKERRORCODE = 0x0033  
OPTION_NETWORK_ERROR = 0x00bb  
OPTION_NEWPASSWORD = 0x0018  
OPTION_NOTE = 0x0061  
OPTION_OPERATOR = 0x00b9  
OPTION_OPSENTEXPIRES = 0x0041  
OPTION_ORIGDESTADDR = 0x0087  
OPTION_ORIGID = 0x008c  
OPTION_ORIGIN = 0x0096  
OPTION_ORIGSOURCEADDR = 0x0086  
OPTION_OTOA = 0x0070  
OPTION_OUTCONNECTOR = 0x003c  
OPTION_PASSWORD = 0x0017  
OPTION_PBID = 0x0068  
OPTION_PBNAME = 0x0065  
OPTION_PBTYPE = 0x0066  
OPTION_PDUSEQ = 0x0084  
OPTION_PDUSEQMAX = 0x0085  
OPTION_PLUGINARG = 0x0090  
OPTION_PRIORITY = 0x0020  
OPTION_PRIVACYINDICATOR = 0x002f  
OPTION_PROTOCOL = 0x0054  
OPTION_PROTOCOLID = 0x002b  
OPTION_PROXY = 0x00be  
OPTION_QPRIORITY = 0x0076  
OPTION_QSTATS1 = 0x0058  
OPTION_QSTATS15 = 0x005a  
OPTION_QSTATS5 = 0x0059  
OPTION_QUEUESIZE = 0x0056  
OPTION_QUOTEDREPLY = 0x009c  
OPTION_QUOTEDREPLY_SEPARATOR = 0x009d  
OPTION_REASON = 0x0067  
OPTION_REASONTEXT = 0x00aa  
OPTION_RECEIPTEDMESSAGEID = 0x0035  
OPTION_REFERENCES = 0x009b  
OPTION_REGISTEREDDELIVERY = 0x0038  
OPTION_REMOTEIP = 0x0022  
OPTION_REMOVEPREFIX = 0x0075  
OPTION_REMOVEPREFIX_SOURCEADDR = 0x0083  
OPTION_REPLACEIFPRESENTFLAG = 0x002c  
OPTION_REPLACEPID = 0x006b  
OPTION_REPLYPATH = 0x001f  
OPTION_REQUIREPREFIX = 0x004c  
OPTION_REQUIREPREFIX_SOURCEADDR = 0x0082  
OPTION_RETCODE = 0x0028  
OPTION_ROUTE = 0x0026  
OPTION_ROUTE2 = 0x0043  
OPTION_ROUTEDLR = 0x0027  
OPTION_SCAADDR = 0x00a7  
OPTION_SCAADDRNPI = 0x00a9  
OPTION_SCAADDRTON = 0x00a8  
OPTION_SCTS = 0x0015  
OPTION_SENDERADDRESS = 0x0095  
OPTION_SENDERTS = 0x0089  
OPTION_SERVICEDESCRIPTION = 0x0088  
OPTION_SERVICEID = 0x008d  
OPTION_SERVICETYPE = 0x0029  
OPTION_SERVICETYPEIN = 0x009e  
OPTION_SINGLESHOT = 0x0050  
OPTION_SMPPOPTION = 0x00b2  
OPTION_SMPP_DLR_TEXT = 0x00c6  
OPTION_SMPP_PDU_BODY = 0x00c4  
OPTION_SMPP_PDU_HEADER = 0x00c3  
OPTION_SMPP_USSD_SERVICE_OP = 0x00cb  
OPTION_SMSCID = 0x0040  
OPTION_SMSCOP = 0x0024  
OPTION_SMTP_RET = 0x00ae  
OPTION_SOURCEADDR = 0x0002  
OPTION_SOURCEADDRNPI = 0x0004  
OPTION_SOURCEADDRSUBUNIT = 0x0007  
OPTION_SOURCEADDRTON = 0x0003  
OPTION_SOURCEADDRTYPE = 0x0080  
OPTION_SOURCEFULLNAME = 0x009f  
OPTION_SOURCENETWORKTYPE = 0x003e  
OPTION_SOURCEPORT = 0x0006  
OPTION_SOURCESUBADDRESS = 0x0005  
OPTION_STARTMSECS = 0x005e  
OPTION_STARTSECS = 0x005d  
OPTION_STATE = 0x0053  
OPTION_STATIC = 0x007a  
OPTION_STATUS = 0x003d  
OPTION_SUBJECT = 0x006f  
OPTION_SUBMITTS = 0x0097  
OPTION_SYSTEMTYPE = 0x0023  
OPTION_TARIFFCLASS = 0x0021  
OPTION_TARIFFNAME = 0x00b1  
OPTION_TCPSOURCEIP = 0x0094  
OPTION_TCPSOURCEPORT = 0x0044  
OPTION_TTSSESSIONINFO = 0x0032  
OPTION_TYPE = 0x0057  
OPTION_UDH = 0x000e  
OPTION_UDHI = 0x006a  
OPTION_UDHLEN = 0x000f  
OPTION_USERMESSAGEREFERENCE = 0x002d  
OPTION_USERNAME = 0x0016  
OPTION_USERRESPONSECODE = 0x002e  
OPTION_VLR = 0x008b  
OPTION_VP = 0x0012  
OPTION_WAPAPPLICATION = 0x00b4  
OPTION_XPRIORITY = 0x0093  
OPTION_XSER_EXTRA = 0x00b5  
OPTION_XUSERNAME = 0x0077  
OP_BEGINBATCH = (4)  
OP_BEGINBATCH_RESP = (104)  
OP_CONFIRMMESSAGE = (30)  
OP_CONFIRMMESSAGE_RESP = (130)  
OP_CONNECTORHOLD = (27)  
OP_CONNECTORHOLD_RESP = (127)  
OP_DBREQUEST = (28)  
OP_DBREQUEST_RESP = (128)  
OP_DELETEMESSAGE = (11)  
OP_DELETEMESSAGE_RESP = (111)  
OP_ENDBATCH = (5)  
OP_ENDBATCH_RESP = (105)  
OP_FORCECLOSE = (34)  
OP_FORCECLOSE_RESP = (134)  
OP_GETCONNECTORINFO = (6)  
OP_GETCONNECTORINFO_RESP = (106)  
OP_GETCONNECTORQUEUE = (8)  
OP_GETCONNECTORQUEUE_RESP = (108)  
OP_GETDBINFO = (31)  
OP_GETDBINFO_RESP = (131)  
OP_GETFIRSTMESSAGE = (29)  
OP_GETFIRSTMESSAGE_RESP = (129)  
OP_GETORPHANS = (9)  
OP_GETORPHANS_RESP = (109)  
OP_GETROUTELOG = (14)  
OP_GETROUTELOG_RESP = (114)  
OP_KEEPALIVE = (13)  
OP_KEEPALIVE_RESP = (113)  
OP_LOGOFF = (3)  
OP_LOGOFF_RESP = (103)  
OP_LOGON = (1)  

Operations

OP_LOGON_RESP = (101)  
OP_MODIFYMESSAGE = (12)  
OP_MODIFYMESSAGE_RESP = (112)  
OP_MOVEMESSAGE = (33)  
OP_MOVEMESSAGE_RESP = (133)  
OP_PBADD = (22)  
OP_PBADD_RESP = (122)  
OP_PBCREATE = (20)  
OP_PBCREATE_RESP = (120)  
OP_PBDELETE = (21)  
OP_PBDELETE_RESP = (121)  
OP_PBLIST = (25)  
OP_PBLIST_RESP = (125)  
OP_PBREMOVE = (24)  
OP_PBREMOVE_RESP = (124)  
OP_PBUPDATE = (23)  
OP_PBUPDATE_RESP = (123)  
OP_QUERYMESSAGE = (10)  
OP_QUERYMESSAGE_RESP = (110)  
OP_REFRESH = (7)  
OP_REFRESH_RESP = (107)  
OP_RELOAD = (32)  
OP_RELOAD_RESP = (132)  
OP_REQUESTMESSAGE = (26)  
OP_REQUESTMESSAGE_RESP = (126)  
OP_RESCHEDULE_MESSAGE = (35)  
OP_RESCHEDULE_MESSAGE_RESP = (135)  
OP_SENDMESSAGE = (2)  
OP_SENDMESSAGE_RESP = (102)  
PBTYPE_SYSTEM = 1  
PBTYPE_USER = 0  

Phone book types

STATUS_CANCELED = 7  
STATUS_DELETED = 4  
STATUS_DELIVERED = 1  

Status codes

STATUS_EXPIRED = 5  
STATUS_FAILED = 3  
STATUS_INPROCESS = 2  
STATUS_ORPHANED = 9  
STATUS_QUEUED = 8  
STATUS_REJECTED = 6  
STATUS_RELAYED = 10  
STATUS_UNKNOWN = 11  

Attributes

admin [R]
charcode [R]
clientconfig [R]
credits [R]
host [R]
name [R]
perms [R]
port [R]
remoteip [R]
socket [R]
systemtype [R]

Public Class methods

new ()
[show source]
# File mgp.rb, line 508
def initialize
        @admin = false
        @socket = nil
end
settings= (settings)
[show source]
# File mgp.rb, line 40
def MGP.settings=(settings)
        @@settings = settings
end

Public Instance methods

admin? ()

Test if the currently logged in user has administration privileges.

[show source]
# File mgp.rb, line 560
def admin?
        @admin = false if @socket.nil?
        @admin
end
close ()

Close the connection to server.

[show source]
# File mgp.rb, line 552
def close
        return if @socket.nil?
        @socket.close
        @socket = nil
end
confirm_message (id, ret)

Confirm that the given message has been succesfully received.

If this function isn't called, the same message will be delivered again after the next login.

The parameter id should be the value from #SMS.messageid, and the result code ERR_OK or any of the other ERR_* values.

[show source]
# File mgp.rb, line 666
def confirm_message(id, ret)
        result = send_operation(OP_CONFIRMMESSAGE,
                { OPTION_ID => id, OPTION_RETCODE => ret })
        find(result, OPTION_RETCODE)
end
connect (host, port, options = {})

Connect to the EMG server on the specified host and port. The EMG server must have an incoming MGP connector listening on the specified IP address/hostname and port.

Valid options:

:ssl => true

Use SSL.

:username => 'user'

Login with this username.

:password => 'pw'

Login with this password.

The :username and :password options are only used if a function block is used.

The yield block is optional. If given, the session is closed and the socket disconnected when the yield block returns.

[show source]
# File mgp.rb, line 528
def connect(host, port, options = {}) # :yields: client
        self.close
        @host = host || (@@settings || {})[:host]
        @port = (port || (@@settings || {})[:port] || "0").to_i
        raise "Invalid port number #{port}" if @port == 0
        @usessl = options[:ssl]
        ret = reconnect
        if block_given?
                begin
                        username = options[:username] || (@@settings || {})[:username]
                        password = options[:password] || (@@settings || {})[:password]
                        unless username.nil? || password.nil?
                                self.logon(username, password)
                        end
                        yield(self)
                ensure
                        self.logoff unless @socket.nil?
                end
        end
        ret
end
connector_hold (name, status)

Set the “hold” status of the connector identified by “name”.

The “status” should either be true to pause outgoing traffic on the connector or false to reenable traffic again.

Returns the result code and the current status.

[show source]
# File mgp.rb, line 714
def connector_hold(name, status)
        result = send_operation(OP_CONNECTORHOLD,
                { OPTION_CONNECTOR => name, OPTION_STATUS => (status ? 1 : 0) })
        [find(result, OPTION_RETCODE), find(result, OPTION_STATUS)]
end
delete_all (connector)

Delete all messages on the specified connector

[show source]
# File mgp.rb, line 631
def delete_all(connector)
        result = send_operation(OP_DELETEMESSAGE, { OPTION_CONNECTOR => connector })
        find(result, OPTION_RETCODE)
end
delete_message (id)

Delete the message with the specified message id.

[show source]
# File mgp.rb, line 624
def delete_message(id)
        result = send_operation(OP_DELETEMESSAGE, { OPTION_ID => id })
        find(result, OPTION_RETCODE)
end
delete_orphans ()

Delete all orphans

[show source]
# File mgp.rb, line 637
def delete_orphans
        result = send_operation(OP_DELETEMESSAGE)
        find(result, OPTION_RETCODE)
end
force_close (connector, mode)

Bounce/open/close connector

[show source]
# File mgp.rb, line 909
def force_close(connector, mode)
        result = send_operation(OP_FORCECLOSE,
                { OPTION_CONNECTOR => connector,
                  OPTION_MODE => mode })
        find(result, OPTION_RETCODE)
end
get_connector_info (connector = nil)

Fetch information about one or all connectors.

Returns the result code, and a hash table.

The hash table keys are the connector names, and the values are a separate hash table with the values for that connector. In this second level has, the used keys are these:

OPTION_TYPE

1 for incoming, 2 for outgoing.

OPTION_PROTOCOL

Protocol number.

OPTION_INSTANCES

The value of the INSTANCES parameter in the server.cfg file.

OPTION_INSTANCES_INUSE

How many instances that are currently in use.

OPTION_MAXINSTANCES

The maximum number of used instances.

OPTION_STATE

Current connector state.

OPTION_QUEUESIZE

Number of messages in the outgoing queue.

OPTION_QSTATS1

Average message throughput for the past minute.

OPTION_QSTATS5

Average message throughput for the past five minutes.

OPTION_QSTATS15

Average message throughput for the past fifteen minutes.

It also has a key OPTION_INSTANCE. The value for this key is a third hash table, containing information about each connector instance. The keys used here are these:

OPTION_STATE

State for this instance.

OPTION_REMOTEIP

If connected, the remote IP address.

OPTION_USERNAME

If connected, the name of the logged in user.

[show source]
# File mgp.rb, line 747
def get_connector_info(connector = nil)
        do_get_info(OP_GETCONNECTORINFO, OPTION_CONNECTOR,
                connector, OPTION_CONNECTOR)
end
get_connector_queue (connector, maxsize = nil)

Fetch the list of pending messages on a connector.

The maxsize parameter can be given to limit the size of the result set.

[show source]
# File mgp.rb, line 677
def get_connector_queue(connector, maxsize = nil)
        args = { OPTION_CONNECTOR => connector }
        args[OPTION_QUEUESIZE] = maxsize unless maxsize.nil?
        result = send_operation(OP_GETCONNECTORQUEUE, args)
        retcode = extract(result, OPTION_RETCODE)
        qs = extract(result, OPTION_QUEUESIZE)
        [retcode, extract_sms(result), qs]
end
get_db_info (db = nil)

Fetch information about one or all database profiles.

Returns the result code, and a hash table.

The hash table keys are the profile names, and the values are a separate hash table with the values for that profile. In this second level has, the used keys are these:

OPTION_NAME

The database profile name.

OPTION_DBNAME

The database name.

OPTION_TYPE

MYSQL for MySQL, PGSQL for PostgreSQL.

OPTION_INSTANCES

The value of the INSTANCES parameter in the server.cfg file.

It also has a key OPTION_INSTANCE. The value for this key is a third hash table, containing information about each profile instance. The keys used here are these:

OPTION_STATE

State for this instance.

[show source]
# File mgp.rb, line 771
def get_db_info(db = nil)
        do_get_info(OP_GETDBINFO, OPTION_DBNAME, db, OPTION_NAME)
end
get_first_message ()

Fetch the first message on the current connector.

Returns the result code, the current queue size on the connector, and the fetched message.

Afterwards, a call to #confirm_message must be done to remove it from the server. Otherwise the same message will be returned again on the next connection.

[show source]
# File mgp.rb, line 651
def get_first_message
        result = send_operation(OP_GETFIRSTMESSAGE)
        retcode = extract(result, OPTION_RETCODE)
        queuesize = extract(result, (OPTION_QUEUESIZE)) || 0
        [retcode, queuesize, result.empty? ? nil : SMS.new(result)]
end
get_orphans (p = {})

Fetch the list of the most recent messages that couldn't be routed.

The supported optional parameters are:

:username => 'user'

Only fetch messages for this user.

:maxsize => n

Limit the size of the result set.

[show source]
# File mgp.rb, line 703
def get_orphans(p = {})
        do_get_list(OP_GETORPHANS, p)
end
get_routelog (p = {})

Fetch the list of the most recent messages, including their routing and delivery status.

The supported optional parameters are:

:username => 'user'

Only fetch messages for this user.

:maxsize => n

Limit the size of the result set.

[show source]
# File mgp.rb, line 693
def get_routelog(p = {})
        do_get_list(OP_GETROUTELOG, p)
end
logoff ()

Log out from the EMG server.

This also closes the socket.

[show source]
# File mgp.rb, line 597
def logoff
        result = send_operation(OP_LOGOFF)
        find(result, OPTION_RETCODE)
end
logon (username, password)

Log on to the server using the specified username and password.

The connector must have a USERS file with the user credentials or reference a databaseprofile (USERDB) with the user specified.

If a yield block is given, the session and socket is automatically closed when the block returns.

[show source]
# File mgp.rb, line 573
def logon(username, password) # :yields: client
        params = { OPTION_USERNAME => username, OPTION_PASSWORD => password }
        result = send_operation(OP_LOGON, params)
        @admin = (find(result, OPTION_ISADMIN) || 0) & 1 == 1
        @systemtype = find(result, OPTION_SYSTEMTYPE)
        @charcode = find(result, OPTION_CHARCODE)
        @name = find(result, OPTION_NAME)
        @remoteip = find(result, OPTION_REMOTEIP)
        @perms = find(result, OPTION_USERRESPONSECODE)
        @credits = find(result, OPTION_CREDITS)
        if block_given?
                begin
                        yield(self)
                ensure
                        self.logoff unless @socket.nil?
                end
        end
        find(result, OPTION_RETCODE)
end
move_messages (connector_from, connector_to)

Move message queue between connectors

[show source]
# File mgp.rb, line 900
def move_messages(connector_from, connector_to)
        result = send_operation(OP_MOVEMESSAGE,
                { OPTION_CONNECTOR => connector_from,
                  OPTION_OUTCONNECTOR => connector_to })
        find(result, OPTION_RETCODE)
end
pb_add (pbid, company, name, destaddr)

Add an entry to a phonebook.

Only a user with administration privileges can add entries to a system phonebook.

Returns the result code.

[show source]
# File mgp.rb, line 836
def pb_add(pbid, company, name, destaddr)
        result = send_operation(OP_PBADD,
                { OPTION_PBID => pbid, OPTION_COMPANY => company,
                  OPTION_NAME => name, OPTION_DESTADDR => destaddr })
        find(result, OPTION_RETCODE)
end
pb_create (pbtype, name)

Create a new phonebook.

The parameter pbtype should be 0 to create a user phonebook, and 1 to create a system phonebook. Only a user with administration privileges can create a system phonebook.

Returns the result code.

[show source]
# File mgp.rb, line 812
def pb_create(pbtype, name)
        result = send_operation(OP_PBCREATE,
                { OPTION_PBTYPE => pbtype, OPTION_PBNAME => name })
        find(result, OPTION_RETCODE)
end
pb_delete (pbid)

Delete a phonebook.

Only a user with administration privileges can delete a system phonebook.

Returns the result code.

[show source]
# File mgp.rb, line 824
def pb_delete(pbid)
        result = send_operation(OP_PBDELETE, { OPTION_PBID => pbid })
        find(result, OPTION_RETCODE)
end
pb_list (pbid = nil)

Fetch a phonebook list.

If the parameter is absent, the list of available phonebooks is returned.

The list is a hash table, with the phonebook id as the key, and a hash table with options as the value. In this second hash table, the following keys are used:

OPTION_PBNAME

The name of the phonebook. This can be any printable string.

OPTION_PBTYPE

0 for a user phonebook, 1 for a system phonebook.

If the optional pbid is given, the list of entries in that phonebook is returned.

The list is a hash table, with the phonebook entry id as the key, and a hash table with options as the value. In this second hash table, the following keys are used:

OPTION_COMPANY

Company name.

OPTION_NAME

Personal name.

OPTION_DESTADDR

Phone number or email adress.

[show source]
# File mgp.rb, line 797
def pb_list(pbid = nil)
        result = send_operation(OP_PBLIST,
                ({ OPTION_PBID => pbid } unless pbid.nil?))
        retcode = extract(result, OPTION_RETCODE)
        [retcode, extract_info(result, OPTION_PBID)]
end
pb_remove (entryid)

Delete a phonebook entry.

Only a user with administration privileges can delete entries in a system phonebook.

[show source]
# File mgp.rb, line 879
def pb_remove(entryid)
        result = send_operation(OP_PBREMOVE, { OPTION_PBID => entryid })
        find(result, OPTION_RETCODE)
end
pb_update (id, params = {})

Update a phonebook entry.

Only a user with administration privileges can update entries in a system phonebook.

Supported keys for the params hash:

  • :company => 'company name'

  • :name => 'personal name'

  • :destaddr => 'phone number'

Returns the result code.

[show source]
# File mgp.rb, line 856
def pb_update(id, params = {})
        args = { OPTION_PBID => id }
        params.each {|k,v|
                case k
                when :company
                        args[OPTION_COMPANY] = v
                when :name
                        args[OPTION_NAME] = v
                when :destaddr
                        args[OPTION_DESTADDR] = v
                else
                        raise "Unknown PB entry parameter `#{k}'"
                end
        }
        result = send_operation(OP_PBUPDATE, args)
        find(result, OPTION_RETCODE)
end
query_message (id)

Query the status of a message.

Returns the result code and an SMS object containing the available fields.

[show source]
# File mgp.rb, line 616
def query_message(id)
        result = send_operation(OP_QUERYMESSAGE, { OPTION_ID => id })
        retcode = extract(result, OPTION_RETCODE)
        [retcode, SMS.new(result)]
end
reload (closeall = false)

Reload or refresh the EMG server.

When the closeall parameter is true all connections will be closed and the current MGP connection will also be lost. This corresponds to running “emgd -refresh” from the command-line.

When the closeall parameter is false connections will be kept. This corresponds to running “emgd -reload” from the command-line.

[show source]
# File mgp.rb, line 893
def reload(closeall = false)
        result = send_operation(closeall ? OP_REFRESH : OP_RELOAD)
        find(result, OPTION_RETCODE)
end
reschedule_message (id, delay = 0, connector = nil)
[show source]
# File mgp.rb, line 916
def reschedule_message(id, delay = 0, connector = nil)
        args = { OPTION_ID => id, OPTION_DELTIME => delay }
        args[OPTION_CONNECTOR] = connector unless connector.nil?
        result = send_operation(OP_RESCHEDULE_MESSAGE, args)
        find(result, OPTION_RETCODE)
end
send_message (sms)

Send a message.

Returns the result code and (if successful) the message id.

[show source]
# File mgp.rb, line 606
def send_message(sms)
        result = send_operation(OP_SENDMESSAGE, sms.options)
        @credits = find(result, OPTION_CREDITS)
        return [find(result, OPTION_RETCODE), find(result, OPTION_ID)]
end