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

Output as generator with lazy-loading pagination #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kevhill
Copy link

@kevhill kevhill commented Jul 19, 2017

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 using response['additional_data'] then that is now obscured.

tldr, you can now do this:

pd = Pipedrive(PIPEDRIVE_API_TOKEN)

for person in pd.persons()
    # each person object is a dict representing the data on that person
    func(person)

@@ -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'})
Copy link
Author

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/#/

Copy link

@bieli bieli Jun 19, 2024

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):

  1. When using requests Python library, I can see HTML instead of JSON the same with curl
  2. 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 :-)

@jscott1989
Copy link
Owner

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? :)

@Dunedan
Copy link

Dunedan commented Jan 15, 2018

Using it with this PR and it works fine. 👍

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.

4 participants