1717__author__ = 'Spot Media Solutions Sdn. Bhd.'
1818__copyright__ = 'Copyright 2015 Spot Media Solutions Sdn. Bhd.'
1919
20- API_ENDPOINT = 'https://api.atomx.com/{}/ ' .format (API_VERSION )
20+ API_ENDPOINT = 'https://api.atomx.com/{}' .format (API_VERSION )
2121
2222
2323class Atomx (object ):
2424 def __init__ (self , email , password , api_endpoint = API_ENDPOINT ):
2525 self .email = email
2626 self .password = password
27- self .api_endpoint = api_endpoint
27+ self .api_endpoint = api_endpoint . rstrip ( '/' ) + '/'
2828 self .session = requests .Session ()
2929 self .login ()
3030
@@ -96,7 +96,7 @@ def report_get(self, report):
9696 return r .content .decode ()
9797
9898 def get (self , resource , ** kwargs ):
99- r = self .session .get (self .api_endpoint + resource , params = kwargs )
99+ r = self .session .get (self .api_endpoint + resource . strip ( '/' ) , params = kwargs )
100100 if not r .ok :
101101 raise APIError (r .json ()['error' ])
102102
@@ -111,21 +111,24 @@ def get(self, resource, **kwargs):
111111 return res
112112
113113 def post (self , model , json , ** kwargs ):
114- r = self .session .post (self .api_endpoint + model , json = json , params = kwargs )
114+ r = self .session .post (self .api_endpoint + model .strip ('/' ),
115+ json = json , params = kwargs )
115116 r_json = r .json ()
116117 if not r .ok :
117118 raise APIError (r_json ['error' ])
118119 return r_json [r_json ['resource' ]]
119120
120121 def put (self , model , id , json , ** kwargs ):
121- r = self .session .put (self .api_endpoint + model + '/' + str (id ), json = json , params = kwargs )
122+ r = self .session .put (self .api_endpoint + model .strip ('/' ) + '/' + str (id ),
123+ json = json , params = kwargs )
122124 r_json = r .json ()
123125 if not r .ok :
124126 raise APIError (r_json ['error' ])
125127 return r_json [r_json ['resource' ]]
126128
127129 def delete (self , model , id , json , ** kwargs ):
128- return self .session .put (self .api_endpoint + model + '/' + str (id ), json = json , params = kwargs )
130+ return self .session .put (self .api_endpoint + model .strip ('/' ) + '/' + str (id ),
131+ json = json , params = kwargs )
129132
130133 def save (self , model ):
131134 return model .save (self )
0 commit comments