Exemplo n.º 1
0
	def wait_code(self, timeout=1200, callback=None, not_end=False, *args, **kwargs):
		"""
		:param wrapper: obj for work with sms-activate
		:param timeout: timeout waiting of code from sms in secs. 1200 - 20 min, this is max time of a live session.
		:param callback: function for eval before getting code
		:param not_end:
		:return: str
		"""
		counter = 0
		while True:
			time.sleep(1)
			counter += 1
			if counter >= timeout:
				raise ('Timeout error')
			response = smsactivateru.GetStatus(id=self.id).request(self.wrapper)
			if not response['code'] and response['status'] == "STATUS_OK":
				response = smsactivateru.GetFullSms(id=self.id).request(self.wrapper)
			if response['code'] and not not_end and response['code'] != self.last_code:
				self.__last_code = response['code']
				smsactivateru.SetStatus(
					id=self.id,
					status=smsactivateru.SmsTypes.Status.End
				).request(self.wrapper)
				break
			elif response['code'] and not_end and response['code'] != self.last_code:
				self.__last_code = response['code']
				smsactivateru.SetStatus(
					id=self.id,
					status=smsactivateru.SmsTypes.Status.OneMoreCode
				).request(self.wrapper)
				break
		if callback:
			callback(self.last_code.strip())
		else:
			return self.last_code.strip()
Exemplo n.º 2
0
	def was_sent(self):
		set_status = smsactivateru.SetStatus(
			id=self.__id,
			status=smsactivateru.SmsTypes.Status.SmsSent
		)
		if self.wrapper:
			return set_status.request(self.wrapper)
		return set_status
Exemplo n.º 3
0
	def mark_as_used(self):
		set_status = smsactivateru.SetStatus(
			id=self.__id,
			status=smsactivateru.SmsTypes.Status.AlreadyUsed
		)
		if self.wrapper:
			return set_status.request(self.wrapper)
		return set_status
Exemplo n.º 4
0
	def cancel(self):
		set_status = smsactivateru.SetStatus(
			id=self.__id,
			status=smsactivateru.SmsTypes.Status.Cancel
		)
		if self.wrapper:
			return set_status.request(self.wrapper)
		return set_status
 def wait_code(self, wrapper, callback=None):
     code = ''
     while True:
         time.sleep(1)
         response = smsactivateru.GetStatus(id=self.__id).request(wrapper)
         logging.debug("Response from sms-activate: %s", str(response))
         if response['code']:
             code = response['code']
             smsactivateru.SetStatus(
                 id=self.__id,
                 status=smsactivateru.SmsTypes.Status.End).request(wrapper)
             break
     if callback:
         callback(code)
     else:
         return code
 def was_sent(self):
     return smsactivateru.SetStatus(
         id=self.__id, status=smsactivateru.SmsTypes.Status.SmsSent)
 def cancel(self):
     return smsactivateru.SetStatus(
         id=self.__id, status=smsactivateru.SmsTypes.Status.Cancel)