Skip to content

Commit

Permalink
Fix for class methods
Browse files Browse the repository at this point in the history
  • Loading branch information
philipithomas committed Apr 2, 2016
1 parent a75fcbe commit db606c3
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions staffjoy/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@


class Resource:
# Seconds to sleep between requests (bc of rate limits)
REQUEST_SLEEP = 0.5

PATH = "" # URL path added to base, including route variables
ID_NAME = None # What is this ID called in the route of children?
META_ENVELOPES = [] # Metadata keys for what to unpack from response
Expand Down Expand Up @@ -71,7 +74,7 @@ def get_all(cls, parent=None, **params):
r = requests.get(base_obj._url(),
auth=(base_obj.key, ""),
params=params)
time.sleep(self.config.REQUEST_SLEEP)
time.sleep(self.REQUEST_SLEEP)

if r.status_code not in cls.TRUTHY_CODES:
return base_obj._handle_request_exception(r)
Expand Down Expand Up @@ -119,7 +122,7 @@ def _handle_request_exception(request):
def fetch(self):
"""Perform a read request against the resource"""
r = requests.get(self._url(), auth=(self.key, ""))
time.sleep(self.config.REQUEST_SLEEP)
time.sleep(self.REQUEST_SLEEP)

if r.status_code not in self.TRUTHY_CODES:
return self._handle_request_exception(r)
Expand All @@ -142,15 +145,15 @@ def delete(self):
"""Delete the object"""

r = requests.delete(self._url(), auth=(self.key, ""))
time.sleep(self.config.REQUEST_SLEEP)
time.sleep(self.REQUEST_SLEEP)

if r.status_code not in self.TRUTHY_CODES:
return self._handle_request_exception(r)

def patch(self, **kwargs):
"""Change attributes of the item"""
r = requests.patch(self._url(), auth=(self.key, ""), data=kwargs)
time.sleep(self.config.REQUEST_SLEEP)
time.sleep(self.REQUEST_SLEEP)

if r.status_code not in self.TRUTHY_CODES:
return self._handle_request_exception(r)
Expand All @@ -173,7 +176,7 @@ def create(cls, parent=None, **kwargs):
obj = cls(key=parent.key, route=route, config=parent.config)

response = requests.post(obj._url(), auth=(obj.key, ""), data=kwargs)
time.sleep(self.config.REQUEST_SLEEP)
time.sleep(self.REQUEST_SLEEP)

if response.status_code not in cls.TRUTHY_CODES:
return cls._handle_request_exception(response)
Expand Down

0 comments on commit db606c3

Please sign in to comment.