Skip to content

Commit

Permalink
Implementing the method to get attributes and properties from the arg…
Browse files Browse the repository at this point in the history
…s & kwargs in all the __init__ methods
  • Loading branch information
koalalorenzo committed Aug 12, 2014
1 parent 00214f8 commit abc6948
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 20 deletions.
6 changes: 5 additions & 1 deletion digitalocean/Action.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ class Action(BaseAPI):
resource_type = None
region = None

def __init__(self, action_id=""):
def __init__(self, action_id="", *args, **kwargs):
super(Action, self).__init__()
if action_id:
self.id = action_id

#Setting the attribute values
for attr in kwargs.keys():
setattr(self,attr,kwargs[attr])

def load(self):
action = self.get_data("actions/%s" % self.id)
if action:
Expand Down
1 change: 1 addition & 0 deletions digitalocean/Domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Domain(BaseAPI):

def __init__(self, *args, **kwargs):
super(Domain, self).__init__()

#Setting the attribute values
for attr in kwargs.keys():
setattr(self,attr,kwargs[attr])
Expand Down
8 changes: 5 additions & 3 deletions digitalocean/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ class Image(BaseAPI):
regions = []
created_at = None

def __init__(self, token=""):
def __init__(self, *args, **kwargs):
super(Image, self).__init__()
if token:
self.token = token

#Setting the attribute values
for attr in kwargs.keys():
setattr(self,attr,kwargs[attr])

def destroy(self):
"""
Expand Down
5 changes: 4 additions & 1 deletion digitalocean/Manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@


class Manager(BaseAPI):
def __init__(self, token=""):
def __init__(self, token="", *args, **kwargs):
super(Manager, self).__init__()
if token:
self.token = token

for attr in kwargs.keys():
setattr(self,attr,kwargs[attr])

def get_data(self, *args, **kwargs):
"""
Customized version of get_data to perform __check_actions_in_data
Expand Down
10 changes: 5 additions & 5 deletions digitalocean/Record.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class Record(BaseAPI):
port = None
weight = None

def __init__(self, domain_name, id="", token=""):
def __init__(self, domain_name, *args, **kwargs):
super(Record, self).__init__()
self.domain = domain_name
if id:
self.id = id
if token:
self.token = token

#Setting the attribute values
for attr in kwargs.keys():
setattr(self,attr,kwargs[attr])

def create(self):
"""
Expand Down
8 changes: 5 additions & 3 deletions digitalocean/Region.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class Region(BaseAPI):
available = None
features = []

def __init__(self, token=""):
def __init__(self, *args, **kwargs):
super(Region, self).__init__()
if token:
self.token = token

#Setting the attribute values
for attr in kwargs.keys():
setattr(self,attr,kwargs[attr])
4 changes: 1 addition & 3 deletions digitalocean/SSHKey.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ class SSHKey(BaseAPI):
public_key = None
fingerprint = None

def __init__(self, token="", *args, **kwargs):
def __init__(self, *args, **kwargs):
super(SSHKey, self).__init__()
if token:
self.token = token

#Setting the attribute values
for attr in kwargs.keys():
Expand Down
8 changes: 5 additions & 3 deletions digitalocean/Size.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ class Size(BaseAPI):
price_hourly = None
regions = []

def __init__(self, token=""):
def __init__(self, *args, **kwargs):
super(Size, self).__init__()
if token:
self.token = token

#Setting the attribute values
for attr in kwargs.keys():
setattr(self,attr,kwargs[attr])
5 changes: 4 additions & 1 deletion digitalocean/baseapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ class BaseAPI(object):
call_response = None
end_point = "https://api.digitalocean.com/v2/"

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

for attr in kwargs.keys():
setattr(self,attr,kwargs[attr])

def __perform_get(self, url, headers=dict(), params=dict()):
return requests.get(url, headers=headers, params=params)

Expand Down

0 comments on commit abc6948

Please sign in to comment.