Skip to content
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

Add incremental calls api #454

Merged
merged 4 commits into from
Jan 30, 2021

Conversation

NiallRees
Copy link
Contributor

@NiallRees NiallRees commented Oct 16, 2020

@NiallRees
Copy link
Contributor Author

@facetoe bit stuck here, I'm testing with the following:

import datetime
from zenpy import Zenpy


creds = {'email': "xxxxx", "token": 'xxxxx', 'subdomain': 'xxxxx'}
zenpy_client = Zenpy(**creds)
yesterday = datetime.datetime.now() - datetime.timedelta(days=1)
result_generator = zenpy_client.talk.calls.incremental(start_time=yesterday)
for result in result_generator:
    print(result)

and getting

Traceback (most recent call last):
  File "zendesk.py", line 8, in <module>
    result_generator = zenpy_client.talk.calls.incremental(start_time=yesterday)
  File "/Users/niallwoodward/dev/venvs/zenpy/lib/python3.7/site-packages/zenpy-2.0.22-py3.7.egg/zenpy/lib/api.py", line 646, in incremental
  File "/Users/niallwoodward/dev/venvs/zenpy/lib/python3.7/site-packages/zenpy-2.0.22-py3.7.egg/zenpy/lib/api.py", line 283, in _query_zendesk
  File "/Users/niallwoodward/dev/venvs/zenpy/lib/python3.7/site-packages/zenpy-2.0.22-py3.7.egg/zenpy/lib/api.py", line 112, in _get
  File "/Users/niallwoodward/dev/venvs/zenpy/lib/python3.7/site-packages/zenpy-2.0.22-py3.7.egg/zenpy/lib/api.py", line 212, in _process_response
  File "/Users/niallwoodward/dev/venvs/zenpy/lib/python3.7/site-packages/zenpy-2.0.22-py3.7.egg/zenpy/lib/response.py", line 103, in build
  File "/Users/niallwoodward/dev/venvs/zenpy/lib/python3.7/site-packages/zenpy-2.0.22-py3.7.egg/zenpy/lib/response.py", line 80, in deserialize
  File "/Users/niallwoodward/dev/venvs/zenpy/lib/python3.7/site-packages/zenpy-2.0.22-py3.7.egg/zenpy/lib/mapping.py", line 136, in object_from_json
  File "/Users/niallwoodward/dev/venvs/zenpy/lib/python3.7/site-packages/zenpy-2.0.22-py3.7.egg/zenpy/lib/api_objects/__init__.py", line 28, in __setattr__
  File "/Users/niallwoodward/dev/venvs/zenpy/lib/python3.7/site-packages/zenpy-2.0.22-py3.7.egg/zenpy/lib/api_objects/talk_objects.py", line 374, in phone_number
AttributeError: 'str' object has no attribute 'id'

https://github.com/facetoe/zenpy/pull/454/files#diff-9a6f0e892ca44f09040db986925cef3c097002c65ff6b6a1e1e72fbbce95b97dR371-R375

I'm struggling to debug as a result of the (very neat) auto generated classes, any ideas?

@NiallRees
Copy link
Contributor Author

NiallRees commented Oct 16, 2020

Removing phone_number_id from the call spec fixes the error, but isn't ideal as that's missing from the result now

@facetoe
Copy link
Owner

facetoe commented Oct 17, 2020

This should fix the phone number issue:

diff --git a/tools/gen_classes.py b/tools/gen_classes.py
index 8666d2f..3a0672c 100755
--- a/tools/gen_classes.py
+++ b/tools/gen_classes.py
@@ -213,7 +213,7 @@ class Attribute(object):
             return attr_name
 
     def get_attr_assignment(self, object_name, object_type, key):
-        if object_type != key and object_type != 'date' and key.endswith('_id'):
+        if object_type != key and object_type != 'date' and object_name != 'phone_number' and key.endswith('_id'):
             return '%s.id' % object_name
         elif key.endswith('_ids'):
             return '[o.id for o in %(object_name)s]' % locals()

@NiallRees
Copy link
Contributor Author

NiallRees commented Oct 18, 2020

Hey @facetoe thanks for looking into this. I think we're getting there, the change you suggested results in:

    @phone_number.setter
    def phone_number(self, phone_number):
        if phone_number:
            self.phone_number_id = phone_number

which results in records returned with 'phone_number_id': '+4420xxxxx448' and a missing phone_number field. If I manually change the method to be

    @phone_number.setter
    def phone_number(self, phone_number):
        if phone_number:
            self._phone_number = phone_number

then I get the correct result of 'phone_number_id': 207xxx65 and 'phone_number': '+4420xxxxx448' in the record. What do you reckon?

@facetoe
Copy link
Owner

facetoe commented Oct 18, 2020

Manually changing the output won't work as next time the script is run it will be clobbered.

@NiallRees
Copy link
Contributor Author

Manually changing the output won't work as next time the script is run it will be clobbered.

Yeah I realise, my question really is how we change the class generator to achieve that result? Does it need a new template or just some additional logic to accommodate the phone number like you previously suggested?

@NiallRees
Copy link
Contributor Author

Ok @facetoe I've got this working with the class generator. The shim I've put in does the job, but not sure if you think it should go somewhere else. Thanks :)

@NiallRees
Copy link
Contributor Author

@facetoe just a bump on this if you have any ideas otherwise could we merge?

@ghost
Copy link

ghost commented Jan 5, 2021

@facetoe Any status update? Would love to see this merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants