This is great. Let's take advantage of this capability by doing the following:
Change data={...} to json={...} and drop the header assignment wherever possible. (But do not touch nailgun.client!)
Drop all references to nailgun.client from the other modules.
Deprecate module nailgun.client, and eventually drop it.
Points 2 and 3 are worth some extra discussion. The purpose of module nailgun.client is to do the following:
automatically encode JSON
automatically set headers
log requests and responses
Most of the automatic JSON encoding and header twiddling can now be done by Requests itself. We'll still need to explicitly set headers in cases where we're uploading files, but that's rare enough that I think it'll be easy to find and fix those few locations.
Logging requests and responses is a tougher nut to crack. Adding logging statements to every single *_raw mixin method and all of the helper methods is a repetitive and fragile solution. It may be worth spending some time reading up on what Python's standard framework provides. It may be that it's easy to just log out information using logging tools built in to Requests.
Requests now offers a
json
argument. Consider this sample code:The same code can now be simplified to this:
References:
This is great. Let's take advantage of this capability by doing the following:
data={...}
tojson={...}
and drop the header assignment wherever possible. (But do not touchnailgun.client
!)nailgun.client
from the other modules.nailgun.client
, and eventually drop it.Points 2 and 3 are worth some extra discussion. The purpose of module
nailgun.client
is to do the following:Most of the automatic JSON encoding and header twiddling can now be done by Requests itself. We'll still need to explicitly set headers in cases where we're uploading files, but that's rare enough that I think it'll be easy to find and fix those few locations.
Logging requests and responses is a tougher nut to crack. Adding logging statements to every single
*_raw
mixin method and all of the helper methods is a repetitive and fragile solution. It may be worth spending some time reading up on what Python's standard framework provides. It may be that it's easy to just log out information using logging tools built in to Requests.