22# -*- coding: utf8 -*-
33
44import sys
5+ import platform
56sys .path .insert (0 , "../../" )
67
78from sdk .coolsms import Coolsms
8- from sdk import exceptions
9+ from sdk . exceptions import CoolsmsSDKException
910
1011#import sdk.coolsms
1112
@@ -18,11 +19,7 @@ def __init__(self, api_key, api_secret):
1819 Coolsms (api_key , api_secret )
1920
2021 # access to send resource
21- def send (params ):
22- if type (params ) is not str :
23- print ("ERROR" )
24- #raise Exception("ERROR", "TT")
25-
22+ def send (self , params ):
2623 """Request to REST API server to send SMS messages
2724
2825 Arguments:
@@ -42,25 +39,35 @@ def send(params):
4239 Returns:
4340 A JSON type string will be returned. On failure, thorw Exception
4441 """
42+
43+ print ("GG" )
44+ print (type (params ))
45+ if type (params ) is not dict :
46+ raise CoolsmsSDKException ("params type is no dictionary" )
47+
48+ for key , val in params .items ():
49+ print ("Code : {0}, Value : {1}" .format (key , val ))
50+ if key == "text" and sys .version_info [0 ] == 2 :
51+ t_temp = text .decode ('utf-8' )
52+ text = t_temp .encode ('utf-8' )
53+ text = unicode (text , encoding = 'utf-8' )
54+ params ['text' ] = text
55+
56+ if key == "to" and type (to ) == list :
57+ to = ',' .join (to )
4558
46- # convert list to a comma seperated string
47- if sys .version_info [0 ] == 2 :
48- t_temp = text .decode ('utf-8' )
49- text = t_temp .encode ('utf-8' )
50- text = unicode (text , encoding = 'utf-8' )
51- if type (to ) == list :
52- to = ',' .join (to )
53-
54- if type :
55- if type .lower () not in ['sms' , 'lms' , 'mms' ]:
56- self .__set_error__ ('invalid message type' )
57- return False
58- else :
59- type = self .get_type ()
6059
61- os_platform = platform .system ()
62- dev_lang = "Python %s" % platform .python_version ()
63- sdk_version = "sms-python %s" % __version__
60+ params ['os_platform' ] = platform .system ()
61+ params ['dev_lang' ] = "Python %s" % platform .python_version ()
62+ params ['sdk_version' ] = "sms-python %s" % Coolsms .sdk_version
63+
64+ for key , val in params .items ():
65+ print ("Code : {0}, Value : {1}" .format (key , val ))
66+
67+
68+ # convert list to a comma seperated string
69+ """
70+
6471 if app_version:
6572 self.app_version = app_version
6673
@@ -135,6 +142,7 @@ def send(params):
135142 self.__set_error__("%s:%s" % (err['code'], reason))
136143 return False
137144 return json.loads(response)
145+ """
138146
139147 # access to sent resource
140148 def status (self , page = 1 , count = 20 , s_rcpt = None , s_start = None , s_end = None , mid = None ):
0 commit comments