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 WriteInPublic API client #2344

Merged
merged 1 commit into from
Feb 7, 2018
Merged

Conversation

chrismytton
Copy link
Member

This is a very simple wrapper around the WriteInPublic API. Currently it only implements the features that we need for integrating it into Pombola.

I've added some tests for the basic functionality, but in the interests of time I've skipped writing tests for the .people() and .answers() methods, so will need to revisit that at some point in the future.

Extracted from #2329
Part of #1682

@coveralls
Copy link

coveralls commented Feb 6, 2018

Coverage Status

Coverage increased (+0.2%) to 54.352% when pulling 6fdab17 on writeinpublic-api-client into edbb136 on master.

@chrismytton chrismytton requested a review from mhl February 6, 2018 13:42
Copy link
Contributor

@mhl mhl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor things I've commented on inline but otherwise this looks good 👍

try:
return requests.post(url, json=payload, params=params)
except requests.exceptions.RequestException as err:
raise self.WriteInPublicException(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The argument to this exceptions constructor is expected to be a string, I think, so perhaps this should be:

raise self.WriteInPublicException(unicode(err))

'api_key': self.api_key,
'person__popolo_uri': person_popolo_uri,
}
response = requests.get(url, params=params)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that all calls to requests.get or requests.post should be followed by response.raise_for_status() afterwards, or you won't get an exception for 4xx and 5xx responses, and will get a less helpful error later...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good shout, I didn't know about that method, added that in de1f549.

@chrismytton
Copy link
Member Author

@mhl I've made those changes now, so I think this is ready for another review.

@chrismytton chrismytton requested a review from mhl February 7, 2018 11:46
This is a very simple wrapper around the WriteInPublic API. Currently it
only implements the features that we need for integrating it into
Pombola.

I've added some tests for the basic functionality, but in the interests
of time I've skipped writing tests for the .people() and .answers()
methods, so will need to revisit that at some point in the future.
@mysociety-pusher mysociety-pusher force-pushed the writeinpublic-api-client branch from de1f549 to 6fdab17 Compare February 7, 2018 12:27
@mysociety-pusher mysociety-pusher merged commit 6fdab17 into master Feb 7, 2018
@chrismytton chrismytton deleted the writeinpublic-api-client branch June 10, 2019 11:39
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