Skip to content

Commit

Permalink
If no endpoint is specified ( we add it automatically )
Browse files Browse the repository at this point in the history
  • Loading branch information
koalalorenzo committed Aug 11, 2014
1 parent 2b6ae6d commit c89f9e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions digitalocean/baseapi.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import requests
from urlparse import urljoin

class BaseAPI(object):
"""
Basic api class for
"""
token = ""
call_response = None
end_point = "https://api.digitalocean.com/v2/"

def __init__(self):
super(BaseAPI, self).__init__()
self.token = ""
self.call_response = None
self.end_point = "https://api.digitalocean.com/v2/"

def __perform_get(self, url, headers=dict(), params=dict()):
return requests.get(url, headers=headers, params=params)
Expand All @@ -35,6 +40,9 @@ def __perform_request(self, url, type='GET', params=dict()):
if not self.token:
raise Exception("No token provied. Please use a valid token")

if not "https" not in url:
url = urljoin(self.end_point, url)

headers = {'Authorization':'Bearer ' + self.token}
if type == 'POST':
r = self.__perform_request(url, headers=headers, params=params)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
requests>=2.0.0
urlparse

0 comments on commit c89f9e5

Please sign in to comment.