-
Notifications
You must be signed in to change notification settings - Fork 1
Tickets #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Tickets #2
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,7 +38,7 @@ def delete(self, id): | |
| return self.client.req( | ||
| requests.delete, self.api_endpoint(id), self.wrapper_name) | ||
|
|
||
| def get(self, id): | ||
| def get(self, id=None, args=None): | ||
| return self.client.req( | ||
| requests.get, self.api_endpoint(id), self.wrapper_name) | ||
|
|
||
|
|
@@ -160,6 +160,7 @@ def __init__(self, url, key): | |
| # Resources types | ||
| self.customers = FreshDeskCustomers(self) | ||
| self.contacts = FreshDeskContacts(self) | ||
| self.tickets = FreshDeskTickets(self) | ||
|
|
||
| def req(self, func, path, resource_type, params={}, **kwargs): | ||
| abs_url = urlparse.urljoin(self.url, path) | ||
|
|
@@ -186,7 +187,11 @@ def req(self, func, path, resource_type, params={}, **kwargs): | |
| # Either we get a list or a single object | ||
| json_obj = resp.json() | ||
| if isinstance(json_obj, (list, tuple)): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would better see this implemented as :
|
||
| return [i[resource_type] for i in json_obj] | ||
| try: | ||
| return [i[resource_type] for i in json_obj] | ||
| # Tickets are not wrapped in a dic like others objects | ||
| except KeyError: | ||
| return json_obj | ||
| else: | ||
| return json_obj[resource_type] | ||
| else: | ||
|
|
@@ -212,3 +217,19 @@ def api_endpoint(self, id): | |
|
|
||
| def create(self, id, **kwargs): | ||
| return self.client.req(requests.post, self.api_endpoint(id), self.wrapper_name, **kwargs) | ||
|
|
||
| class FreshDeskTickets(FreshDeskObjects): | ||
| api_name = 'ticket' | ||
| wrapper_name = 'helpdesk_ticket' | ||
|
|
||
| def api_endpoint(self, id=None, args=None): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default arg would lead to some url with |
||
| if id: | ||
| return '/helpdesk/{}s/{}.json'.format(self.api_name, id) | ||
| else: | ||
| if args: | ||
| # Add search params in the end of the URL | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Search params are already handled here (although the docstring don't explain what params do, I admit). Does it fit your need ? |
||
| text_args = self.convert_args_from_dic(args) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does not exist |
||
| return '/helpdesk/{}s.json{}'.format(self.api_name, text_args) | ||
| else: | ||
| return '/helpdesk/{}s.json'.format(self.api_name) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why ?