Ejemplo n.º 1
0
 def forgot_password(self, send_to_email=True):
     # forgotPassword api method wrapper
     request_handler = MobilyApiJsonRequestHandler(self.auth)
     request_type = 2 if send_to_email else 1
     request_handler.set_api_method('forgetPassword')
     request_handler.add_parameter('type', request_type)
     return request_handler.handle()
Ejemplo n.º 2
0
 def delete(self):
     # send sms api method wrapper
     if self.delete_key is None:
         return
     request_handler = MobilyApiJsonRequestHandler(self.auth)
     request_handler.set_api_method('deleteMsg')
     request_handler.add_parameter('deleteKey', self.delete_key)
     return request_handler.handle()
Ejemplo n.º 3
0
 def is_mobile_number_license_active(self, sender_id):
     request_handler = MobilyApiJsonRequestHandler(self.auth)
     request_handler.set_api_method('checkSender')
     request_handler.add_parameter('senderId', sender_id.strip('#'))
     try:
         response = request_handler.handle()
     except MobilyApiError:
         return False
     else:
         return response.get('result') == '1'
Ejemplo n.º 4
0
 def can_send():
     # send status api method wrapper, doesn't need authentication
     request_handler = MobilyApiJsonRequestHandler()
     request_handler.set_api_method('sendStatus')
     try:
         response = request_handler.handle()
     except MobilyApiError:
         return False
     else:
         return response.get('result') == '1'
 def test_json_building(self):
     expected_json = '{"Data": {"Method": "balance", "Auth": {"mobile": "test", "password": "******"}}}'
     request = MobilyApiJsonRequestHandler(MobilyApiAuth('test', 'test'))
     request.set_api_method('balance')
     self.assertEqual(expected_json, request.get_request_data())
Ejemplo n.º 6
0
 def get_activation_status_for_all_senders(self):
     request_handler = MobilyApiJsonRequestHandler(self.auth)
     request_handler.set_api_method('checkAlphasSender')
     return request_handler.handle().data
Ejemplo n.º 7
0
 def request_alphabetical_license(self, sender):
     request_handler = MobilyApiJsonRequestHandler(self.auth)
     request_handler.set_api_method('addAlphaSender')
     request_handler.add_parameter('sender', sender)
     return request_handler.handle()
Ejemplo n.º 8
0
 def activate_mobile_number_license(self, sender_id, activation_code):
     request_handler = MobilyApiJsonRequestHandler(self.auth)
     request_handler.set_api_method('activeSender')
     request_handler.add_parameter('senderId', sender_id.strip('#'))
     request_handler.add_parameter('activeKey', activation_code)
     return request_handler.handle()
Ejemplo n.º 9
0
 def request_mobile_number_license(self, mobile_number):
     request_handler = MobilyApiJsonRequestHandler(self.auth)
     request_handler.set_api_method('addSender')
     request_handler.add_parameter('sender', mobile_number)
     response = request_handler.handle()
     return response.get('senderId')
Ejemplo n.º 10
0
class MobilySMS(object):
    def __init__(self, auth, numbers=None, sender='', msg='', delete_key=None, msg_id=None,
                 domain_name=None, application_type='24'):
        self.numbers = numbers
        if numbers is None:
            self.numbers = []
        self.auth = auth
        self.sender = sender
        self.msg = msg
        self.date_send = 0
        self.time_send = 0
        self.delete_key = delete_key
        self.msg_id = msg_id
        self.domain_name = domain_name
        self.application_type = application_type
        self.api_method_name = 'msgSend'
        self.request_handler = MobilyApiJsonRequestHandler(self.auth)

    def add_number(self, number):
        self.numbers.append(number)

    def get_numbers_as_csv(self):
        return ','.join(self.numbers)

    @staticmethod
    def can_send():
        # send status api method wrapper, doesn't need authentication
        request_handler = MobilyApiJsonRequestHandler()
        request_handler.set_api_method('sendStatus')
        try:
            response = request_handler.handle()
        except MobilyApiError:
            return False
        else:
            return response.get('result') == '1'

    def send(self):
        # send sms api method wrapper
        self._prepare_to_send()
        return self.request_handler.handle()

    def delete(self):
        # send sms api method wrapper
        if self.delete_key is None:
            return
        request_handler = MobilyApiJsonRequestHandler(self.auth)
        request_handler.set_api_method('deleteMsg')
        request_handler.add_parameter('deleteKey', self.delete_key)
        return request_handler.handle()

    def schedule_to_send_on(self, day, month, year, hour=0, minute=0, sec=0):
        self.time_send = '{:02d}:{:02d}:{:02d}'.format(hour, minute, sec)
        self.date_send = '{:02d}/{:02d}/{:04d}'.format(month, day, year)

    def _prepare_to_send(self):
        self.request_handler.set_api_method(self.api_method_name)
        self.request_handler.add_parameter('sender', self.sender)
        self.request_handler.add_parameter('msg', MobilyApiUnicodeConverter.convert(self.msg))
        self.request_handler.add_parameter('numbers', self.get_numbers_as_csv())
        self.request_handler.add_parameter('dateSend', self.date_send)
        self.request_handler.add_parameter('timeSend', self.time_send)
        self.request_handler.add_parameter('deleteKey', self.delete_key)
        self.request_handler.add_parameter('msgId', self.msg_id)
        self.request_handler.add_parameter('applicationType', self.application_type)
        self.request_handler.add_parameter('domainName', self.domain_name)
Ejemplo n.º 11
0
 def check_balance(self):
     # balance api method wrapper
     request_handler = MobilyApiJsonRequestHandler(self.auth)
     request_handler.set_api_method('balance')
     return request_handler.handle().get('balance')
Ejemplo n.º 12
0
 def change_password(self, new_password):
     # changePassword api method wrapper
     request_handler = MobilyApiJsonRequestHandler(self.auth)
     request_handler.set_api_method('changePassword')
     request_handler.add_parameter('newPassword', new_password)
     return request_handler.handle()