-
Notifications
You must be signed in to change notification settings - Fork 43
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
Output as generator with lazy-loading pagination #12
base: master
Are you sure you want to change the base?
Conversation
@@ -35,7 +35,7 @@ def _request(self, endpoint, data, method='POST'): | |||
response, data = self.http.request(uri, method=method, headers={'Content-Type': 'application/x-www-form-urlencoded'}) | |||
else: | |||
uri = PIPEDRIVE_API_URL + endpoint + '?api_token=' + str(self.api_token) | |||
response, data = self.http.request(uri, method=method, body=urlencode(data), headers={'Content-Type': 'application/x-www-form-urlencoded'}) | |||
response, data = self.http.request(uri, method=method, body=json.dumps(data), headers={'Content-Type': 'application/json'}) |
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.
"We recommend using JSON body format when performing API requests" https://developers.pipedrive.com/docs/api/v1/#/
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.
We can see general issues with Pipedrive API server implementation (wrong specification of API server - they rely on "Content-Type" header instead of "Accept" - look to RFC: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept):
- When using
requests
Python library, I can see HTML instead of JSON the same with curl - Documentation doesn't follow HTTP RFC in case of headers request specification, what is wrong today (maybe 20 years ago it would have been fine, but not in 2024!) -> https://pipedrive.readme.io/docs/core-api-concepts-requests
Sometimes junior developers needs to listen critical comments carefully :-)
This is not comment to you @kevhill - this is for Pipedrive API server developers :-)
Looks good to me - but I don't use the library any more so I'll wait and see if there's more feedback on it either way okay? :) |
Using it with this PR and it works fine. 👍 |
This is a backward incompatible change to the way you use the pipedrive client, but I found it useful so I'm putting it up here for discussion.
Basically, I ended up writing a bunch of management code to get more than 100 things to handle pipedrive's pagination. Instead I really just wanted to write simple
for
loops over the results. So, I decided to change the wrapper into something that returned a python-style generator. The interface is quite nice for basic things, but if you rely on usingresponse['additional_data']
then that is now obscured.tldr, you can now do this: