Make send-message API example program more flexible
(imported from commit e1fa90169500f84b088f1697c31641c24ed93bc8)
This commit is contained in:
parent
dcfcbadf89
commit
83a446d1ea
|
@ -3,11 +3,11 @@ import sys
|
||||||
import os
|
import os
|
||||||
import optparse
|
import optparse
|
||||||
|
|
||||||
usage = """send-message --user=<email address> [options]
|
usage = """send-message [options] <recipient>
|
||||||
|
|
||||||
Sends a test message from by the provided user to tabbott@humbhughq.com.
|
Sends a test message to the specified user.
|
||||||
|
|
||||||
Example: send-message --user=tabbott@humbughq.com --site=http://127.0.0.1:8000
|
Example: send-message --site=http://127.0.0.1:8000 iago@humbughq.com
|
||||||
"""
|
"""
|
||||||
parser = optparse.OptionParser(usage=usage)
|
parser = optparse.OptionParser(usage=usage)
|
||||||
parser.add_option('--site',
|
parser.add_option('--site',
|
||||||
|
@ -16,16 +16,23 @@ parser.add_option('--site',
|
||||||
action='store')
|
action='store')
|
||||||
parser.add_option('--api-key',
|
parser.add_option('--api-key',
|
||||||
dest='api_key',
|
dest='api_key',
|
||||||
default="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
default='4e5d97591bec64bf57d2698ffbb563e3',
|
||||||
action='store')
|
action='store')
|
||||||
parser.add_option('--user',
|
parser.add_option('--sender',
|
||||||
dest='user',
|
dest='sender',
|
||||||
|
default='othello@humbughq.com',
|
||||||
|
action='store')
|
||||||
|
parser.add_option('--recipient',
|
||||||
|
dest='recipient',
|
||||||
action='store')
|
action='store')
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
|
if len(args) != 1:
|
||||||
|
parser.error("Wrong number of arguments")
|
||||||
|
|
||||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
|
||||||
import api.common
|
import api.common
|
||||||
client = api.common.HumbugAPI(email=options.user,
|
client = api.common.HumbugAPI(email=options.sender,
|
||||||
api_key=options.api_key,
|
api_key=options.api_key,
|
||||||
verbose=True,
|
verbose=True,
|
||||||
site=options.site)
|
site=options.site)
|
||||||
|
@ -33,6 +40,6 @@ client = api.common.HumbugAPI(email=options.user,
|
||||||
message_data = {
|
message_data = {
|
||||||
"type": "private",
|
"type": "private",
|
||||||
"content": "test",
|
"content": "test",
|
||||||
"recipient": "tabbott@humbughq.com",
|
"recipient": args[0]
|
||||||
}
|
}
|
||||||
print client.send_message(message_data)
|
print client.send_message(message_data)
|
||||||
|
|
Loading…
Reference in a new issue