starting messing the actually making a requests call
This commit is contained in:
parent
4192c1b66f
commit
d5c91e5482
25
klugman/base.py
Normal file
25
klugman/base.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# Copyright (c) 2014 Dark Secret Software Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
# implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
def _remove_empty(kv):
|
||||||
|
"""Remove kv pairs from dictionary where value is empty."""
|
||||||
|
return dict([(k, v) for k, v in kv.iteritems() if v])
|
||||||
|
|
||||||
|
|
||||||
|
def get(url, cmd, params):
|
||||||
|
return requests.get("%s/%s" % (url, cmd), params=params)
|
@ -59,4 +59,5 @@ if __name__ == '__main__':
|
|||||||
print "base url:", url
|
print "base url:", url
|
||||||
argv = [arguments['<command>']] + arguments['<args>']
|
argv = [arguments['<command>']] + arguments['<args>']
|
||||||
|
|
||||||
impl(url, arguments, argv)
|
api = impl(url, arguments)
|
||||||
|
api.dispatch(argv)
|
||||||
|
@ -32,6 +32,15 @@ from docopt import docopt
|
|||||||
|
|
||||||
class V1(object):
|
class V1(object):
|
||||||
|
|
||||||
def __init__(self, base_url, base_args, cmdline):
|
def __init__(self, base_url, base_args):
|
||||||
arguments = docopt(__doc__, argv=cmdline)
|
self.base_url = base_url
|
||||||
print arguments
|
self.base_args = base_args
|
||||||
|
|
||||||
|
def dispatch(self, cmdline):
|
||||||
|
self.arguments = docopt(__doc__, argv=cmdline)
|
||||||
|
print self.arguments
|
||||||
|
|
||||||
|
if self.arguments['events']:
|
||||||
|
response = self.do_events()
|
||||||
|
# handle cmdline output here.
|
||||||
|
|
||||||
|
@ -13,8 +13,56 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
|
"""usage:
|
||||||
|
klugman.py events [options]
|
||||||
|
klugman.py events (-h | --help)
|
||||||
|
|
||||||
|
options:
|
||||||
|
-i, --id <id>
|
||||||
|
filter by event ID
|
||||||
|
-r, --request_id <request_id>
|
||||||
|
filter by Request ID
|
||||||
|
-s, --start <start_datetime>
|
||||||
|
starting datetime range
|
||||||
|
-e, --end <end_datetime>
|
||||||
|
ending datetime range
|
||||||
|
|
||||||
|
notes:
|
||||||
|
-r isn't needed if -i is supplied.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
import base
|
||||||
|
|
||||||
from docopt import docopt
|
from docopt import docopt
|
||||||
|
|
||||||
|
|
||||||
class V2(object):
|
class V2(object):
|
||||||
pass
|
def __init__(self, base_url, base_args):
|
||||||
|
self.base_url = base_url
|
||||||
|
self.base_args = base_args
|
||||||
|
|
||||||
|
def dispatch(self, cmdline):
|
||||||
|
self.arguments = docopt(__doc__, argv=cmdline)
|
||||||
|
print self.arguments
|
||||||
|
|
||||||
|
if self.arguments['events']:
|
||||||
|
response = self.do_events()
|
||||||
|
# handle cmdline output here.
|
||||||
|
|
||||||
|
def do_events(self):
|
||||||
|
eid = self.arguments.get('--id')
|
||||||
|
rid = self.arguments.get('--request_id')
|
||||||
|
start = self.arguments.get('--start')
|
||||||
|
end = self.arguments.get('--end')
|
||||||
|
|
||||||
|
cmd = "/events"
|
||||||
|
if eid:
|
||||||
|
cmd = "/events/%d" % eid
|
||||||
|
params = base._remove_empty({'request_id': rid,
|
||||||
|
'start_ts': start,
|
||||||
|
'end_ts': end})
|
||||||
|
|
||||||
|
print "Params:", params
|
||||||
|
return base.get(self.base_url, cmd, params)
|
||||||
|
@ -1 +1,3 @@
|
|||||||
docopt
|
docopt
|
||||||
|
prettytable
|
||||||
|
requests
|
||||||
|
Loading…
x
Reference in New Issue
Block a user