1414from bandwidth .http .auth .messaging_basic_auth import MessagingBasicAuth
1515from bandwidth .messaging .models .media import Media
1616from bandwidth .messaging .models .bandwidth_message import BandwidthMessage
17- from bandwidth .messaging .exceptions .generic_client_exception import GenericClientException
18- from bandwidth .messaging .exceptions .path_client_exception import PathClientException
17+ from bandwidth .messaging .exceptions .messaging_exception import MessagingException
1918
2019
2120class APIController (BaseController ):
@@ -25,50 +24,6 @@ class APIController(BaseController):
2524 def __init__ (self , config , call_back = None ):
2625 super (APIController , self ).__init__ (config , call_back )
2726
28- def get_message (self ):
29- """Does a GET request to /ping.
30-
31- getMessage
32-
33- Returns:
34- void: Response from the API.
35-
36- Raises:
37- APIException: When an error occurs while fetching the data from
38- the remote API. This exception includes the HTTP Response
39- code, an error message, and the HTTP body that was received in
40- the request.
41-
42- """
43-
44- # Prepare query URL
45- _url_path = '/ping'
46- _query_builder = self .config .get_base_uri (Server .MESSAGINGDEFAULT )
47- _query_builder += _url_path
48- _query_url = APIHelper .clean_url (_query_builder )
49-
50- # Prepare and execute request
51- _request = self .config .http_client .get (_query_url )
52- MessagingBasicAuth .apply (self .config , _request )
53- _response = self .execute_request (_request )
54-
55- # Endpoint and global error handling using HTTP status codes.
56- if _response .status_code == 400 :
57- raise GenericClientException ('400 Request is malformed or invalid' , _response )
58- elif _response .status_code == 401 :
59- raise PathClientException ('401 The specified user does not have access to the account' , _response )
60- elif _response .status_code == 403 :
61- raise PathClientException ('403 The user does not have access to this API' , _response )
62- elif _response .status_code == 404 :
63- raise PathClientException ('404 Path not found' , _response )
64- elif _response .status_code == 415 :
65- raise GenericClientException ('415 The content-type of the request is incorrect' , _response )
66- elif _response .status_code == 429 :
67- raise GenericClientException ('429 The rate limit has been reached' , _response )
68- self .validate_response (_response )
69-
70- # Return appropriate type
71- ApiResponse (_response )
7227 def list_media (self ,
7328 user_id ,
7429 continuation_token = None ):
@@ -114,17 +69,17 @@ def list_media(self,
11469
11570 # Endpoint and global error handling using HTTP status codes.
11671 if _response .status_code == 400 :
117- raise GenericClientException ('400 Request is malformed or invalid' , _response )
72+ raise MessagingException ('400 Request is malformed or invalid' , _response )
11873 elif _response .status_code == 401 :
119- raise PathClientException ('401 The specified user does not have access to the account' , _response )
74+ raise MessagingException ('401 The specified user does not have access to the account' , _response )
12075 elif _response .status_code == 403 :
121- raise PathClientException ('403 The user does not have access to this API' , _response )
76+ raise MessagingException ('403 The user does not have access to this API' , _response )
12277 elif _response .status_code == 404 :
123- raise PathClientException ('404 Path not found' , _response )
78+ raise MessagingException ('404 Path not found' , _response )
12479 elif _response .status_code == 415 :
125- raise GenericClientException ('415 The content-type of the request is incorrect' , _response )
80+ raise MessagingException ('415 The content-type of the request is incorrect' , _response )
12681 elif _response .status_code == 429 :
127- raise GenericClientException ('429 The rate limit has been reached' , _response )
82+ raise MessagingException ('429 The rate limit has been reached' , _response )
12883 self .validate_response (_response )
12984
13085 decoded = APIHelper .json_deserialize (_response .text , Media .from_dictionary )
@@ -170,17 +125,17 @@ def get_media(self,
170125
171126 # Endpoint and global error handling using HTTP status codes.
172127 if _response .status_code == 400 :
173- raise GenericClientException ('400 Request is malformed or invalid' , _response )
128+ raise MessagingException ('400 Request is malformed or invalid' , _response )
174129 elif _response .status_code == 401 :
175- raise PathClientException ('401 The specified user does not have access to the account' , _response )
130+ raise MessagingException ('401 The specified user does not have access to the account' , _response )
176131 elif _response .status_code == 403 :
177- raise PathClientException ('403 The user does not have access to this API' , _response )
132+ raise MessagingException ('403 The user does not have access to this API' , _response )
178133 elif _response .status_code == 404 :
179- raise PathClientException ('404 Path not found' , _response )
134+ raise MessagingException ('404 Path not found' , _response )
180135 elif _response .status_code == 415 :
181- raise GenericClientException ('415 The content-type of the request is incorrect' , _response )
136+ raise MessagingException ('415 The content-type of the request is incorrect' , _response )
182137 elif _response .status_code == 429 :
183- raise GenericClientException ('429 The rate limit has been reached' , _response )
138+ raise MessagingException ('429 The rate limit has been reached' , _response )
184139 self .validate_response (_response )
185140
186141 decoded = _response .text
@@ -249,17 +204,17 @@ def upload_media(self,
249204
250205 # Endpoint and global error handling using HTTP status codes.
251206 if _response .status_code == 400 :
252- raise GenericClientException ('400 Request is malformed or invalid' , _response )
207+ raise MessagingException ('400 Request is malformed or invalid' , _response )
253208 elif _response .status_code == 401 :
254- raise PathClientException ('401 The specified user does not have access to the account' , _response )
209+ raise MessagingException ('401 The specified user does not have access to the account' , _response )
255210 elif _response .status_code == 403 :
256- raise PathClientException ('403 The user does not have access to this API' , _response )
211+ raise MessagingException ('403 The user does not have access to this API' , _response )
257212 elif _response .status_code == 404 :
258- raise PathClientException ('404 Path not found' , _response )
213+ raise MessagingException ('404 Path not found' , _response )
259214 elif _response .status_code == 415 :
260- raise GenericClientException ('415 The content-type of the request is incorrect' , _response )
215+ raise MessagingException ('415 The content-type of the request is incorrect' , _response )
261216 elif _response .status_code == 429 :
262- raise GenericClientException ('429 The rate limit has been reached' , _response )
217+ raise MessagingException ('429 The rate limit has been reached' , _response )
263218 self .validate_response (_response )
264219
265220 # Return appropriate type
@@ -303,17 +258,17 @@ def delete_media(self,
303258
304259 # Endpoint and global error handling using HTTP status codes.
305260 if _response .status_code == 400 :
306- raise GenericClientException ('400 Request is malformed or invalid' , _response )
261+ raise MessagingException ('400 Request is malformed or invalid' , _response )
307262 elif _response .status_code == 401 :
308- raise PathClientException ('401 The specified user does not have access to the account' , _response )
263+ raise MessagingException ('401 The specified user does not have access to the account' , _response )
309264 elif _response .status_code == 403 :
310- raise PathClientException ('403 The user does not have access to this API' , _response )
265+ raise MessagingException ('403 The user does not have access to this API' , _response )
311266 elif _response .status_code == 404 :
312- raise PathClientException ('404 Path not found' , _response )
267+ raise MessagingException ('404 Path not found' , _response )
313268 elif _response .status_code == 415 :
314- raise GenericClientException ('415 The content-type of the request is incorrect' , _response )
269+ raise MessagingException ('415 The content-type of the request is incorrect' , _response )
315270 elif _response .status_code == 429 :
316- raise GenericClientException ('429 The rate limit has been reached' , _response )
271+ raise MessagingException ('429 The rate limit has been reached' , _response )
317272 self .validate_response (_response )
318273
319274 # Return appropriate type
@@ -362,17 +317,17 @@ def create_message(self,
362317
363318 # Endpoint and global error handling using HTTP status codes.
364319 if _response .status_code == 400 :
365- raise GenericClientException ('400 Request is malformed or invalid' , _response )
320+ raise MessagingException ('400 Request is malformed or invalid' , _response )
366321 elif _response .status_code == 401 :
367- raise PathClientException ('401 The specified user does not have access to the account' , _response )
322+ raise MessagingException ('401 The specified user does not have access to the account' , _response )
368323 elif _response .status_code == 403 :
369- raise PathClientException ('403 The user does not have access to this API' , _response )
324+ raise MessagingException ('403 The user does not have access to this API' , _response )
370325 elif _response .status_code == 404 :
371- raise PathClientException ('404 Path not found' , _response )
326+ raise MessagingException ('404 Path not found' , _response )
372327 elif _response .status_code == 415 :
373- raise GenericClientException ('415 The content-type of the request is incorrect' , _response )
328+ raise MessagingException ('415 The content-type of the request is incorrect' , _response )
374329 elif _response .status_code == 429 :
375- raise GenericClientException ('429 The rate limit has been reached' , _response )
330+ raise MessagingException ('429 The rate limit has been reached' , _response )
376331 self .validate_response (_response )
377332
378333 decoded = APIHelper .json_deserialize (_response .text , BandwidthMessage .from_dictionary )
0 commit comments