z4r / python-rtkit

Python Api for Request Tracker's REST interface
http://z4r.github.com/python-rtkit/
Other
68 stars 44 forks source link

Feature: RTResponse should be more pythonic #15

Open lkarsten opened 11 years ago

lkarsten commented 11 years ago

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.

z4r commented 11 years ago

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.

daffodil commented 11 years ago

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

darkpixel commented 9 years ago

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': 'user@example.tld',
    }
}

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