Created
January 13, 2020 20:41
-
-
Save blade2005/13e0d5d2e1f42b1efdfdd7cf0f860f34 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hammock | |
class Hammock(hammock.Hammock): | |
def __init__(self, name=None, parent=None, append_slash=False, **kwargs): | |
import requests | |
self.request_kwargs = {} | |
for k in list(kwargs.keys()): | |
if k not in requests.Session.__attrs__: | |
self.request_kwargs[k] = kwargs[k] | |
del kwargs[k] | |
super(Hammock, self).__init__(name, parent, append_slash, **kwargs) | |
def bind_method(method): | |
"""Bind `requests` module HTTP verbs to `Hammock` class as | |
static methods.""" | |
def aux(hammock, *args, **kwargs): | |
kwargs.update(**hammock.request_kwargs) | |
return hammock._request(method, *args, **kwargs) | |
return aux | |
for method in Hammock.HTTP_METHODS: | |
setattr(Hammock, method.upper(), bind_method(method)) | |
github = Hammock('https://api.github.com', timeout=10) | |
resp = github.repos('kadirpekel', 'hammock').watchers.GET() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment