Skip to content

Commit

Permalink
Renamed __call_api into __get_data to make a KISS method that will ge…
Browse files Browse the repository at this point in the history
…t the data from a URL. This is a big improvement because will help to understand what URL is called in a specific method.
  • Loading branch information
koalalorenzo committed Aug 11, 2014
1 parent 5056bcc commit 2803aec
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions digitalocean/baseapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ def __perform_request(self, url, type='GET', params=dict()):
r = self.__perform_get(url, headers=headers, params=params)
return r

def __call_api(self, path, action, type="GET" params=dict()):
def __get_data(self, url, type="GET", params=dict()):
"""
Basic "call_api" method. It should not work.
This method is a basic implementation of __call_api that checks
errors too.
"""
url = "https://api.digitalocean.com/v2/%s/%s" % (path, action)
req = self.__perform_request(url, type)
self.call_response = req.json() # raise an error in case of problems.
return self.call_response
req = self.__perform_request(url, type, params)
if req.status_code != requests.codes.ok:
msg = [data[m] for m in ("id", "message") if m in data][1]
raise Exception(msg)
return req

def call_api(self, *args, **kargs):
"""
Expand Down

0 comments on commit 2803aec

Please sign in to comment.