Rest api ẅith python » History » Revision 11
Revision 10 (Alex Lourie, 2013-03-04 12:10) → Revision 11/18 (Mischa The Evil, 2013-03-07 03:42)
h1. Using the REST API with Python Here is the two well-known options for using REST API with python. # "Python library":https://github.com/ianepperson/pyredminews # "PyActiveResource":http://code.google.com/p/pyactiveresource/ # "PyRed python library":https://github.com/alourie/pyred h2. *Python library* example: Suppose Eric fell ill and was out for several days. You need to crawl through the project called Parrot and move any due date for issues assigned to Eric out by two more weeks. The dateutil library contains a handy method called reativedelta for calculating relative dates. <pre><code <pre> <code class="python"> # Import the Redmine class from redmine import Redmine from dateutil.relativedelta import relativedelta server = Redmine('http://my-server.com', username='Me', password='seakrit') project = server.projects['parrot'] # Find Eric in the user data for u in server.users: if u.firstname == 'Eric' and u.lastname == 'Idle': user = u break else: raise Exception("Didn't find Eric Idle in the user dateabase") # Extend issues in project assigned to user by two weeks for issue in project.issues(assigned_to_id=user.id): if issue.due_date is not None: issue.due_date += relativedelta(weeks=+2) issue.save('Giving Eric more time to complete - he was out ill') </code></pre> </pre> h2. *PyActiveResource* example: <pre><code class="python"> <pre> # Importing pyactiveresource from pyactiveresource.activeresource import ActiveResource class Issue(ActiveResource): _site = 'http://redmine.foo.org' _user = 'username' _password = 'password' # Get issues issues = Issue.find() # Get a specific issue, from its id issue = Issue.find(1345) # Issue attributes # Updating an attribute </code></pre> </pre> h2. *Pyred* example: TBD