[api version bump] Update API documentation in the example scripts

Give better examples, and rewrite options parsing to be more consistent across examples.
Make it more obvious that you can use "--user" and "--api-key" with our python examples.

This bumps our python bindings to v0.1.9

(imported from commit 297468088f864b7d585e567dc45523ea681f1856)
This commit is contained in:
acrefoot 2013-05-29 14:00:27 -04:00
parent 35b822b58d
commit dfb8a16a55
22 changed files with 92 additions and 87 deletions

16
README
View file

@ -30,7 +30,12 @@ file is as follows:
key=<api key from the web interface> key=<api key from the web interface>
email=<your email address> email=<your email address>
You can obtain your Humbug API key from the Humbug settings page. Alternatively, you may explicitly use "--user" and "--api-key" in our
examples, which is especially useful if you are running several bots
which share a home directory.
You can obtain your Humbug API key, create bots, and manage bots all
from your Humbug [settings page](https://humbughq.com/#settings).
A typical simple bot sending API messages will look as follows: A typical simple bot sending API messages will look as follows:
@ -38,7 +43,7 @@ At the top of the file:
# Make sure the Humbug API distribution's root directory is in sys.path, then: # Make sure the Humbug API distribution's root directory is in sys.path, then:
import humbug import humbug
humbug_client = humbug.Client(email="your_email@example.com") humbug_client = humbug.Client(email="your-bot@example.com")
When you want to send a message: When you want to send a message:
@ -69,3 +74,10 @@ API directly from existing scripts.
humbug-send hamlet@example.com cordelia@example.com -m \ humbug-send hamlet@example.com cordelia@example.com -m \
"Conscience doth make cowards of us all." "Conscience doth make cowards of us all."
Alternatively, if you don't want to use your ~/.humbugrc file:
humbug-send --user shakespeare-bot@example.com \
--api-key a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5 \
hamlet@example.com cordelia@example.com -m \
"Conscience doth make cowards of us all."

View file

@ -58,6 +58,9 @@ def main(argv=None):
Examples: %prog --stream denmark --subject castle -m "Something is rotten in the state of Denmark." Examples: %prog --stream denmark --subject castle -m "Something is rotten in the state of Denmark."
%prog hamlet@example.com cordelia@example.com -m "Conscience doth make cowards of us all." %prog hamlet@example.com cordelia@example.com -m "Conscience doth make cowards of us all."
These examples assume you have a proper '~/.humbugrc'. You may also set your credentials with the
'--user' and '--api-key' arguments.
""" """
sys.path.append(os.path.join(os.path.dirname(__file__), '..')) sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

View file

@ -25,7 +25,8 @@ To use this script:
1. Create an RSS feed file containing 1 feed URL per line (default feed 1. Create an RSS feed file containing 1 feed URL per line (default feed
file location: ~/.cache/humbug-rss/rss-feeds) file location: ~/.cache/humbug-rss/rss-feeds)
2. Subscribe to the stream that will receive RSS updates (default stream: rss) 2. Subscribe to the stream that will receive RSS updates (default stream: rss)
3. Test the script by running it manually, like this: 3. create a ~/.humbugrc, or specify user and api-key with command line arguments
4. Test the script by running it manually, like this:
/usr/local/share/humbug/demos/rss-bot /usr/local/share/humbug/demos/rss-bot
@ -40,14 +41,6 @@ stream every 5 minutes is:
*/5 * * * * /usr/local/share/humbug/demos/rss-bot""" */5 * * * * /usr/local/share/humbug/demos/rss-bot"""
parser = optparse.OptionParser(usage) parser = optparse.OptionParser(usage)
parser.add_option('--email',
dest='email',
help='The email address for your Humbug account.',
metavar='EMAIL')
parser.add_option('--api-key',
dest='api_key',
help='API key for that user [default: read ~/.humbug-api-key]',
action='store')
parser.add_option('--stream', parser.add_option('--stream',
dest='stream', dest='stream',
help='The stream to which to send RSS messages.', help='The stream to which to send RSS messages.',
@ -63,11 +56,7 @@ parser.add_option('--feed-file',
help='The file containing a list of RSS feed URLs to follow, one URL per line', help='The file containing a list of RSS feed URLs to follow, one URL per line',
default=os.path.join(RSS_DATA_DIR, "rss-feeds"), default=os.path.join(RSS_DATA_DIR, "rss-feeds"),
action='store') action='store')
parser.add_option('--site', parser.add_option_group(humbug.generate_option_group(parser))
dest='site',
default="https://humbughq.com",
help=optparse.SUPPRESS_HELP,
action='store')
(opts, args) = parser.parse_args() (opts, args) = parser.parse_args()
def mkdir_p(path): def mkdir_p(path):

View file

@ -16,7 +16,7 @@ def write_config(config, since_id, user):
parser = optparse.OptionParser(r""" parser = optparse.OptionParser(r"""
%prog --user foo@humbughq.com --twitter-id twitter_handle %prog --user foo@example.com --api-key 0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5 --twitter-id twitter_handle
Slurp tweets on your timeline into a specific humbug stream. Slurp tweets on your timeline into a specific humbug stream.
@ -44,18 +44,9 @@ parser = optparse.OptionParser(r"""
Depends on: twitter-python Depends on: twitter-python
""") """)
parser.add_option('--user',
help='Humbug user email address',
metavar='EMAIL')
parser.add_option('--api-key',
help='API key for that user [default: read ~/.humbugrc]')
parser.add_option('--twitter-id', parser.add_option('--twitter-id',
help='Twitter username to poll for new tweets from"', help='Twitter username to poll for new tweets from"',
metavar='URL') metavar='URL')
parser.add_option('--site',
default="https://humbughq.com",
help='Humbug site [default: https://humbughq.com]',
metavar='URL')
parser.add_option('--stream', parser.add_option('--stream',
help='Default humbug stream to write tweets to') help='Default humbug stream to write tweets to')
parser.add_option('--limit-tweets', parser.add_option('--limit-tweets',
@ -63,6 +54,7 @@ parser.add_option('--limit-tweets',
type='int', type='int',
help='Maximum number of tweets to push at once') help='Maximum number of tweets to push at once')
parser.add_option_group(humbug.generate_option_group(parser))
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
if not options.twitter_id: if not options.twitter_id:

View file

@ -18,7 +18,7 @@ def write_config(config, since_id):
parser = optparse.OptionParser(r""" parser = optparse.OptionParser(r"""
%prog --user foo@humbughq.com --search="@nprnews,quantum physics" %prog --user foo@humbughq.com --api-key a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5 --search="@nprnews,quantum physics"
Send Twitter search results to a Humbug stream. Send Twitter search results to a Humbug stream.
@ -63,20 +63,10 @@ Make sure to go the application you created and click "create my
access token" as well. Fill in the values displayed. access token" as well. Fill in the values displayed.
""") """)
parser.add_option('--user',
help='Humbug user email address',
metavar='EMAIL')
parser.add_option('--api-key',
help='API key for that user [default: read ~/.humbugrc]')
parser.add_option('--search', parser.add_option('--search',
dest='search_terms', dest='search_terms',
help='Terms to search on', help='Terms to search on',
action='store') action='store')
parser.add_option('--site',
dest='site',
default="https://humbughq.com",
help=optparse.SUPPRESS_HELP,
action='store')
parser.add_option('--stream', parser.add_option('--stream',
dest='stream', dest='stream',
help='The stream to which to send tweets', help='The stream to which to send tweets',
@ -87,6 +77,7 @@ parser.add_option('--limit-tweets',
type='int', type='int',
help='Maximum number of tweets to send at once') help='Maximum number of tweets to send at once')
parser.add_option_group(humbug.generate_option_group(parser))
(opts, args) = parser.parse_args() (opts, args) = parser.parse_args()
if not opts.search_terms: if not opts.search_terms:

View file

@ -2,13 +2,13 @@
# Two quick API tests using curl # Two quick API tests using curl
curl https://humbughq.com/api/v1/send_message \ curl https://humbughq.com/api/v1/send_message \
-d "api-key=YOUR_API_KEY" \ -d "api-key=BOT_API_KEY" \
-d "email=YOUR_EMAIL" \ -d "email=BOT_EMAIL" \
-d "type=private" -d "content=test" \ -d "type=private" -d "content=test" \
-d "to=RECIPIENT_EMAIL" -d "to=RECIPIENT_EMAIL"
curl https://humbughq.com/api/v1/get_messages \ curl https://humbughq.com/api/v1/get_messages \
-d "api-key=YOUR_API_KEY" \ -d "api-key=BOT_API_KEY" \
-d "email=YOUR_EMAIL" -d "email=BOT_EMAIL"
# Or replace https://humbughq.com with your local test instance # Or replace https://humbughq.com with your local test instance

View file

@ -25,25 +25,29 @@ import sys
from os import path from os import path
import optparse import optparse
usage = """edit-message [options] --message=<msg_id> --content=<new content> --subject=<new subject> usage = """edit-message [options] --message=<msg_id> --subject=<new subject> --content=<new content> --user=<sender's email address> --api-key=<sender's api key>
Edits a message Edits a message that you sent
Example: edit-message --message="348135" --subject="my subject" --message="test message" Example: edit-message --message-id="348135" --subject="my subject" --content="test message" --user=othello-bot@example.com --api-key=a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5
You can omit --user and --api-key arguments if you have a properly set up ~/.humbugrc
""" """
parser = optparse.OptionParser(usage=usage)
parser.add_option('--subject', default="")
parser.add_option('--message', default="")
parser.add_option('--site', default='https://humbughq.com')
parser.add_option('--content', default="")
(options, args) = parser.parse_args()
sys.path.insert(0, path.join(path.dirname(__file__), '..')) sys.path.insert(0, path.join(path.dirname(__file__), '..'))
import humbug import humbug
client = humbug.Client(site=options.site)
parser = optparse.OptionParser(usage=usage)
parser.add_option('--message-id', default="")
parser.add_option('--subject', default="")
parser.add_option('--content', default="")
parser.add_option_group(humbug.generate_option_group(parser))
(options, args) = parser.parse_args()
client = humbug.init_from_options(options)
message_data = { message_data = {
"message_id": options.message, "message_id": options.message_id,
} }
if options.subject != "": if options.subject != "":
message_data["subject"] = options.subject message_data["subject"] = options.subject

View file

@ -25,11 +25,13 @@ import sys
from os import path from os import path
import optparse import optparse
usage = """get-public-streams --user=<email address> [options] usage = """get-public-streams --user=<bot's email address> --api-key=<bot's api key> [options]
Prints out all the public streams in the realm. Prints out all the public streams in the realm.
Example: get-public-streams --user=tabbott@humbughq.com Example: get-public-streams --user=othello-bot@example.com --api-key=a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5
You can omit --user and --api-key arguments if you have a properly set up ~/.humbugrc
""" """
sys.path.append(path.join(path.dirname(__file__), '..')) sys.path.append(path.join(path.dirname(__file__), '..'))

View file

@ -1,4 +1,4 @@
; Save this file as ~/.humbugrc ; Save this file as ~/.humbugrc
[api] [api]
key=<api key from the web interface> key=<your bot's api key from the web interface>
email=<your email address> email=<your bot's email address>

View file

@ -25,9 +25,11 @@ import sys
from os import path from os import path
import optparse import optparse
usage = """list-members [options] usage = """list-members --user=<bot's email address> --api-key=<bot's api key> [options]
List the names and e-mail addresses of the people in your realm. List the names and e-mail addresses of the people in your realm.
You can omit --user and --api-key arguments if you have a properly set up ~/.humbugrc
""" """
sys.path.append(path.join(path.dirname(__file__), '..')) sys.path.append(path.join(path.dirname(__file__), '..'))

View file

@ -25,11 +25,13 @@ import sys
from os import path from os import path
import optparse import optparse
usage = """list-subscriptions --user=<email address> [options] usage = """list-subscriptions --user=<bot's email address> --api-key=<bot's api key> [options]
Prints out a list of the user's subscriptions. Prints out a list of the user's subscriptions.
Example: list-subscriptions --user=tabbott@humbughq.com Example: list-subscriptions --user=tabbott@humbughq.com --api-key=a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5
You can omit --user and --api-key arguments if you have a properly set up ~/.humbugrc
""" """
sys.path.append(path.join(path.dirname(__file__), '..')) sys.path.append(path.join(path.dirname(__file__), '..'))
import humbug import humbug

View file

@ -25,11 +25,13 @@ import sys
from os import path from os import path
import optparse import optparse
usage = """print-messages --user=<email address> [options] usage = """print-messages --user=<bot's email address> --api-key=<bot's api key> [options]
Prints out each message received by the indicated user. Prints out each message received by the indicated bot or user.
Example: print-messages --user=tabbott@humbughq.com Example: print-messages --user=tabbott@humbughq.com --api-key=a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5
You can omit --user and --api-key arguments if you have a properly set up ~/.humbugrc
""" """
sys.path.append(path.join(path.dirname(__file__), '..')) sys.path.append(path.join(path.dirname(__file__), '..'))
import humbug import humbug

View file

@ -25,11 +25,13 @@ import sys
from os import path from os import path
import optparse import optparse
usage = """print-next-message --user=<email address> [options] usage = """print-next-message --user=<bot's email address> --api-key=<bot's api key> [options]
Prints out the next message received by the user. Prints out the next message received by the user.
Example: print-next-messages --user=tabbott@humbughq.com Example: print-next-messages --user=tabbott@humbughq.com --api-key=a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5
You can omit --user and --api-key arguments if you have a properly set up ~/.humbugrc
""" """
sys.path.append(path.join(path.dirname(__file__), '..')) sys.path.append(path.join(path.dirname(__file__), '..'))
import humbug import humbug

View file

@ -24,30 +24,30 @@
import sys import sys
from os import path from os import path
import optparse import optparse
import humbug
usage = """send-message [options] <recipients> usage = """send-message --user=<bot's email address> --api-key=<bot's api key> [options] <recipients>
Sends a test message to the specified recipients. Sends a test message to the specified recipients.
Example: send-message --sender=you@example.com --type=stream commits --subject="my subject" --message="test message" Example: send-message --user=your-bot@example.com --api-key=a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5 --type=stream commits --subject="my subject" --message="test message"
Example: send-message --sender=you@example.com user1@example.com user2@example.com Example: send-message --user=your-bot@example.com --api-key=a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5 user1@example.com user2@example.com
You can omit --user and --api-key arguments if you have a properly set up ~/.humbugrc
""" """
parser = optparse.OptionParser(usage=usage) parser = optparse.OptionParser(usage=usage)
parser.add_option('--api-key')
parser.add_option('--sender')
parser.add_option('--subject', default="test") parser.add_option('--subject', default="test")
parser.add_option('--message', default="test message") parser.add_option('--message', default="test message")
parser.add_option('--site', default='https://humbughq.com')
parser.add_option('--type', default='private') parser.add_option('--type', default='private')
parser.add_option_group(humbug.generate_option_group(parser))
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
if len(args) == 0: if len(args) == 0:
parser.error("You must specify recipients") parser.error("You must specify recipients")
sys.path.append(path.join(path.dirname(__file__), '..')) sys.path.append(path.join(path.dirname(__file__), '..'))
import humbug
client = humbug.Client( client = humbug.Client(
email=options.sender, email=options.user,
api_key=options.api_key, api_key=options.api_key,
verbose=True, verbose=True,
site=options.site) site=options.site)

View file

@ -25,12 +25,14 @@ import sys
from os import path from os import path
import optparse import optparse
usage = """subscribe --user=<email address> [options] --streams=<streams> usage = """subscribe --user=<bot's email address> --api-key=<bot's api key> [options] --streams=<streams>
Ensures the user is subscribed to the listed streams. Ensures the user is subscribed to the listed streams.
Examples: subscribe --user=tabbott@humbughq.com --streams=foo Examples: subscribe --user=tabbott@humbughq.com --api-key=a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5 --streams=foo
subscribe --user=tabbott@humbughq.com --streams='foo bar' subscribe --user=tabbott@humbughq.com --api-key=a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5 --streams='foo bar'
You can omit --user and --api-key arguments if you have a properly set up ~/.humbugrc
""" """
sys.path.append(path.join(path.dirname(__file__), '..')) sys.path.append(path.join(path.dirname(__file__), '..'))
import humbug import humbug

View file

@ -25,12 +25,14 @@ import sys
from os import path from os import path
import optparse import optparse
usage = """unsubscribe --user=<email address> [options] --streams=<streams> usage = """unsubscribe --user=<bot's email address> --api-key=<bot's api key> [options] --streams=<streams>
Ensures the user is not subscribed to the listed streams. Ensures the user is not subscribed to the listed streams.
Examples: unsubscribe --user=tabbott@humbughq.com --streams=foo Examples: unsubscribe --user=tabbott@humbughq.com --api-key=a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5 --streams=foo
unsubscribe --user=tabbott@humbughq.com --streams='foo bar' unsubscribe --user=tabbott@humbughq.com --api-key=a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5 --streams='foo bar'
You can omit --user and --api-key arguments if you have a properly set up ~/.humbugrc
""" """
sys.path.append(path.join(path.dirname(__file__), '..')) sys.path.append(path.join(path.dirname(__file__), '..'))
import humbug import humbug

View file

@ -33,7 +33,7 @@ from distutils.version import LooseVersion
from ConfigParser import SafeConfigParser from ConfigParser import SafeConfigParser
__version__ = "0.1.8" __version__ = "0.1.9"
# Check that we have a recent enough version # Check that we have a recent enough version
# Older versions don't provide the 'json' attribute on responses. # Older versions don't provide the 'json' attribute on responses.
@ -52,10 +52,10 @@ def generate_option_group(parser):
action='store') action='store')
group.add_option('--user', group.add_option('--user',
dest='email', dest='email',
help='Email address of the calling user.') help='Email address of the calling bot or user.')
group.add_option('--config-file', group.add_option('--config-file',
action='store', action='store',
help='Location of an ini file containing the above information.') help='Location of an ini file containing the\nabove information. (default ~/.humbugrc)')
group.add_option('-v', '--verbose', group.add_option('-v', '--verbose',
action='store_true', action='store_true',
help='Provide detailed output.') help='Provide detailed output.')

View file

@ -23,7 +23,7 @@
# Change these values to configure authentication for the plugin # Change these values to configure authentication for the plugin
HUMBUG_USER = "git@example.com" HUMBUG_USER = "git-bot@example.com"
HUMBUG_API_KEY = "0123456789abcdef0123456789abcdef" HUMBUG_API_KEY = "0123456789abcdef0123456789abcdef"
# commit_notice_destination() lets you customize where commit notices # commit_notice_destination() lets you customize where commit notices

View file

@ -20,9 +20,9 @@ import org.apache.commons.httpclient.NameValuePair
class HumbugListener extends AbstractIssueEventListener { class HumbugListener extends AbstractIssueEventListener {
Logger LOGGER = Logger.getLogger(HumbugListener.class.getName()); Logger LOGGER = Logger.getLogger(HumbugListener.class.getName());
// Your humbug account's email address // The email address of one of the bots you created on your Humbug settings page.
String humbugEmail = "" String humbugEmail = ""
// Your humbug API key // That bot's API key.
String humbugAPIKey = "" String humbugAPIKey = ""
// What stream to send messages to. Must already exist. // What stream to send messages to. Must already exist.

View file

@ -1,5 +1,5 @@
# Fill these values in with the appropriate values for your realm, and # Fill these values in with the appropriate values for your realm, and
# then install this value at /etc/nagios3/humbugrc # then install this value at /etc/nagios3/humbugrc
[api] [api]
email = nagios@example.com email = nagios-bot@example.com
key = 0123456789abcdef0123456789abcdef key = 0123456789abcdef0123456789abcdef

View file

@ -23,7 +23,7 @@
# Change these values to configure authentication for the plugin # Change these values to configure authentication for the plugin
HUMBUG_USER = "svn@example.com" HUMBUG_USER = "svn-bot@example.com"
HUMBUG_API_KEY = "0123456789abcdef0123456789abcdef" HUMBUG_API_KEY = "0123456789abcdef0123456789abcdef"
# commit_notice_destination() lets you customize where commit notices # commit_notice_destination() lets you customize where commit notices

View file

@ -23,7 +23,7 @@
# See humbug_trac.py for installation and configuration instructions # See humbug_trac.py for installation and configuration instructions
# Change these constants to configure the plugin: # Change these constants to configure the plugin:
HUMBUG_USER = "trac@example.com" HUMBUG_USER = "trac-bot@example.com"
HUMBUG_API_KEY = "0123456789abcdef0123456789abcdef" HUMBUG_API_KEY = "0123456789abcdef0123456789abcdef"
STREAM_FOR_NOTIFICATIONS = "trac" STREAM_FOR_NOTIFICATIONS = "trac"
TRAC_BASE_TICKET_URL = "https://trac.example.com/ticket" TRAC_BASE_TICKET_URL = "https://trac.example.com/ticket"