-
Notifications
You must be signed in to change notification settings - Fork 7
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
Refactor endpoints #32
Conversation
To avoid collisions with the endpoint names and avoid using super().delete(...) because that is just confusing.
To avoid brutal code duplication. This still allows passing custom headers, to the child endpoint methods if required.
as_json (bool) optional argument specifies that
I dislike the |
Taken me a while to get to this sorry! Was on holiday and when I got back by bathroom ceiling had collapsed due to a leak upstairs...
Fine by me.
I'd be happy to wait a bit longer be refactoring this but this is fine ^^
I agree with this. Also think that returning the response itself could work, but I think 95% of the time you just want to the json response, so handling the response each time would lead to a lot of duplication. |
Yeah, the I am wondering whether this class Endpoint:
def _get(self, url, params, **kwargs):
r = requests.get(url, params, **kwargs)
try:
r.raise_for_status()
except requests.HTTPError:
# Handle different error codes
raise
else:
return r
def _get_json(self, *args, **kwargs):
return self._get(*args,**kwargs).json() brings any real benefit. It's more or less the same amount of characters typed and you have one more method to worry about. I think returning the |
if you are talking about this http://docs.keboola.apiary.io/#introduction/http-response-codes then i'd imagine it would be handled in the |
remove the as_json parameter
I'm dropping this PR as this one is close to impossible to merge (probably due to the unification of line endings from dos to unix + since there are some new commits in the master. Now I see it was too early for such refactoring, lesson learned! |
I still think that something like this
is far better than having |
Sorry about the merge conflict >< |
Endpoint
get
,put
,delete
methods to "private" (_get
,_put
,_post
)This is because there were some naming collisions in
Buckets.delete()
and thesuper()
was being abused.Endpoint
class. This new style still allows passing of custom headers (exactly the same way as you'd expect).In the example above, the request headers will contain both
X-custom-header1
andX-storage-token
. In case ofPOST
requests, thecontent-type: application/x-www-form-urlencoded
is added automatically (more on this in #25 soon)as_json
argument toEndpoint._get
method.This is because the
Tables.preview()
endpoint doesn't return json. The default behavior is still to return json, though.Now I am thinking we might try something like this (which I favor the least):
Or maybe we can always return the
Response
object and let the child endpoint methods handle the decoding?This last one seems pretty flexible and now when I am thinking about it I like it the most. What do you think?
Travis was passing, so I think it should be OK.