Permalink
Browse files

Zendesk Python API Wrapper v1.0.0

  • Loading branch information...
0 parents commit 4b2c65b9b4ae6c9c295850ed22ebe5a1dc462154 Max Gutman committed Apr 7, 2011
Showing with 815 additions and 0 deletions.
  1. +1 −0 CHANGES.txt
  2. +22 −0 LICENSE.txt
  3. +2 −0 MANIFEST.in
  4. +70 −0 README.txt
  5. +151 −0 examples/__init__.py
  6. +27 −0 setup.py
  7. +2 −0 zendesk/__init__.py
  8. +170 −0 zendesk/dict2xml.py
  9. +185 −0 zendesk/endpoints.py
  10. +185 −0 zendesk/zendesk.py
@@ -0,0 +1 @@
+v1.00, 2011-04-01 -- Initial release.
@@ -0,0 +1,22 @@
+The MIT License
+
+Copyright (c) 2009 - 2010 Ryan McGrath
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
@@ -0,0 +1,2 @@
+include *.txt
+recursive-include examples *
@@ -0,0 +1,70 @@
+Zendesk API Wrapper for Python
+=========================================================================================
+Python Zendesk is wrapper for the Zendesk API. This library provides an
+easy and flexible way for developers to communicate with their Zendesk
+account in their application.
+
+
+Requirements
+-----------------------------------------------------------------------------------------------------
+httplib2 is used for authentication and requests
+
+ (pip install | easy_install) httplib2
+
+dict2xml is used to create XML documents that will be posted to
+Zendesk. This module is included with this distribution, but credit goes to
+Vojtech Rylko: https://github.com/vojtarylko/dict2xml
+
+
+Installation
+-----------------------------------------------------------------------------------------------------
+Zendesk Python Library is available on pypi, so installation should be fairly simple:
+
+ (pip install | easy_install) zendesk
+
+
+Example Use
+-----------------------------------------------------------------------------------------------------
+
+ ################################################################
+ ## NEW CONNECTION CLIENT
+ ################################################################
+ zendesk = Zendesk('https://yourcompany.zendesk.com', 'you@yourcompany.com', 'passwd')
+
+ ################################################################
+ ## TICKETS
+ ################################################################
+
+ # List
+ zendesk.list_tickets(view_id=1) # Must have a view defined
+
+ # Create
+ new_ticket = {
+ 'ticket': {
+ 'requester-name': 'Howard Schultz',
+ 'requester-email': 'howard@starbucks.com',
+ 'subject':'My Starbucks coffee is cold!',
+ 'description': 'please reheat my coffee',
+ 'set-tags': 'coffee drinks',
+ 'ticket-field-entries': {
+ '@type': 'array',
+ 'ticket-field-entry': [
+ {'ticket-field-id': 1, 'value': 'venti'},
+ {'ticket-field-id': 2, 'value': '$10'}
+ ]
+ },
+ }
+ }
+ post_data = Zendesk.dict2xml(new_ticket)
+ ticket_url = zendesk.create_ticket(xml_data=post_data)
+ ticket_id = get_id_from_url(ticket_url)
+
+ # Show
+ zendesk.show_ticket(ticket_id=ticket_id)
+
+ # Delete
+ zendesk.delete_ticket(ticket_id=ticket_id)
+
+ # More examples in `examples` folder!
+
+
@@ -0,0 +1,151 @@
+import re
+from zendesk import Zendesk
+
+def get_id_from_url(url):
+ match = re.match(r".*/(?P<identifier>\d+)\.xml", url)
+ if match and match.group('identifier'):
+ return match.group('identifier')
+
+
+################################################################
+## NEW CONNECTION CLIENT
+################################################################
+zendesk = Zendesk('https://yourcompany.zendesk.com', 'you@yourcompany.com', 'passwd')
+
+################################################################
+## TICKETS
+################################################################
+
+# List
+zendesk.list_tickets(view_id=1) # Must have a view defined
+
+# Create
+new_ticket = {
+ 'ticket': {
+ 'requester-name': 'Howard Schultz',
+ 'requester-email': 'howard@starbucks.com',
+ 'subject':'My Starbucks coffee is cold!',
+ 'description': 'please reheat my coffee',
+ 'set-tags': 'coffee drinks',
+ 'ticket-field-entries': {
+ '@type': 'array',
+ 'ticket-field-entry': [
+ {'ticket-field-id': 1, 'value': 'venti'},
+ {'ticket-field-id': 2, 'value': '$10'}
+ ]
+ },
+ }
+}
+post_data = Zendesk.dict2xml(new_ticket)
+ticket_url = zendesk.create_ticket(xml_data=post_data)
+ticket_id = get_id_from_url(ticket_url)
+
+# Show
+zendesk.show_ticket(ticket_id=ticket_id)
+
+# Delete
+zendesk.delete_ticket(ticket_id=ticket_id)
+
+
+################################################################
+## ORGANIZATIONS
+################################################################
+
+# List
+zendesk.list_organizations()
+
+# Create
+new_org = {
+ 'organization': {
+ 'name': 'Starbucks Corp'
+ }
+}
+post_data = Zendesk.dict2xml(new_org)
+org_url = zendesk.create_organization(xml_data=post_data)
+org_id = get_id_from_url(org_url)
+
+# Show
+zendesk.show_organization(organization_id=org_id)
+
+# Delete
+zendesk.delete_organization(organization_id=org_id)
+
+
+################################################################
+## USERS (AGENTS)
+################################################################
+
+# List
+zendesk.list_users()
+
+# Create
+new_user = {
+ 'user': {
+ 'name': 'Howard Schultz',
+ 'email': 'howard@starbucks.com',
+ 'roles': 4,
+ }
+}
+post_data = Zendesk.dict2xml(new_user)
+user_url = zendesk.create_user(xml_data=post_data)
+user_id = get_id_from_url(user_url)
+
+# Show
+zendesk.show_user(group_id=user_id)
+
+# Delete
+zendesk.delete_user(group_id=user_id)
+
+
+################################################################
+## GROUPS
+################################################################
+
+# List
+zendesk.list_groups()
+
+# Create
+new_group = {
+ 'group': {
+ 'name': 'Starbucks Group',
+ 'agents': {
+ '@type': 'array',
+ 'agent': 123,
+ }
+ }
+}
+post_data = Zendesk.dict2xml(new_group)
+group_url = zendesk.create_group(xml_data=post_data)
+group_id = get_id_from_url(group_url)
+
+# Show
+zendesk.show_group(group_id=group_id)
+
+# Delete
+zendesk.delete_group(group_id=group_id)
+
+
+################################################################
+## TAGS
+################################################################
+
+# List
+zendesk.list_tags()
+
+# Show
+zendesk.list_assets(tag_id=123, asset_type='event') # event | entry
+
+
+################################################################
+## TICKET TYPES
+################################################################
+zendesk.list_ticket_fields()
+
+
+################################################################
+## SEARCH
+################################################################
+
+# http://www.zendesk.com/api/search
+# make sure to url-encode the query
+results = zendesk.search(query='ticket+sort:desc', page=1)
@@ -0,0 +1,27 @@
+#!/usr/bin/python
+
+from distutils.core import setup
+
+setup(
+ # Basic package information.
+ name = 'Zendesk',
+ author = 'Max Gutman',
+ version = '1.0.0',
+ author_email = 'max@eventbrite.com',
+ packages = ['zendesk'],
+ include_package_data = True,
+ install_requires = ['httplib2'],
+ license='LICENSE.txt',
+ url = 'http://github.com/eventbrite/zendesk/tree/master',
+ keywords = 'zendesk api helpdesk',
+ description = 'Python API Wrapper for Zendesk',
+ classifiers = [
+ 'Development Status :: 4 - Beta',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: MIT License',
+ 'Topic :: Software Development :: Libraries :: Python Modules',
+ 'Topic :: Internet'
+ ],
+)
+
+
@@ -0,0 +1,2 @@
+from zendesk import *
+from endpoints import *
Oops, something went wrong.

0 comments on commit 4b2c65b

Please sign in to comment.