python-rtkit icon indicating copy to clipboard operation
python-rtkit copied to clipboard

Feature: RTResponse should be more pythonic

Open lkarsten opened this issue 12 years ago • 3 comments

It should be possible to get a response in dictionary form. List of tuples is a good starting point, but you usually want to access just one field real quick.

Dates returned in an RTResponse should be pre-parsed to datetime objects, instead of returned as strings. (There might be some locale issues here)

This will simplify use of the library.

Implementation wise it should be an easy fix in rtkit/resource.py's RTResponse object, but I'm not sure how it best is made visible interface wise.

I'm happy to provide a patches if these changes sound acceptable.

lkarsten avatar Jan 28 '13 11:01 lkarsten

Hi Lasse, thanks for your interest. You do quite right, but my idea was a set of high-level API that should solve the unpythonic.

The basic idea can be found in tracker.py and entities.py.

let me know what do you think about it.

z4r avatar Jan 28 '13 12:01 z4r

Had a quick look at tracker.py ?

How am I supposed to use it ?

eg tracker = Tracker('http://rt.foo.com/REST/1.0/', 'webmaster', 'secret', CookieAuthenticator)

But it look like the kinda thing i want..

Pete

daffodil avatar Feb 01 '13 12:02 daffodil

Easy workaround. Use the documented method for creating a ticket along with a quick and dirty regular expression:

import re

re_ticket_id = re.compile(r'Ticket (?P<ticket_id>\d+) created\.', re.MULTILINE)

resource = RTResource('https://example.com/rt/REST/1.0', 'user', 'pass')

content = {
    'content': {
        'Queue': 'General',
        'Subject': 'My Summary',
        'Text': 'This is my test ticket',
        'Requestors': '[email protected]',
    }
}

response = resource.post(path='ticket/new', payload=content,)
match = re_ticket_id.search(response.body)
print 'Ticket ID: %s' % (match.group('ticket_id'))

darkpixel avatar Jun 02 '15 02:06 darkpixel