コード例 #1
0
 def check_authorization(self):
     """Request to retrieve authorization status from the Freebox OS."""
     if self.track_id:
         uri = self._get_api_uri('login/authorize/%s' % self.track_id)
         content = self._freebox_get(uri)
         if 'status' in content:
             self.status = content['status']
             self.challenge = content['challenge']
             config.save_configuration(self.to_dict())
             if self.status == 'granted':
                 logger.info("Application already granted on the "
                             "FreeboxOS.")
                 #authorized = True
             elif self.status == 'pending':
                 logger.info("Please confirmed the authorization request "
                             "on the FreeboxOS.")
                 #authorized = True
             elif self.status == 'unknown':
                 logger.info("Unknown application from the FreeboxOS. "
                             "Please send authorization again.")
             elif self.status == 'denied':
                 logger.info("This application has been denied by the "
                             "FreeboxOS.")
             elif self.status == 'timeout':
                 logger.info("Confirmation of the authorization has not "
                             "arrived on time.")
             return content
         else:
             raise common.FreeboxOSException("Authorization failed: %s" %
                                             content)
     else:
         raise common.FreeboxOSException("Please send authorization "
                                         "request before.")
コード例 #2
0
 def login(self):
     """Make a request to the FreeboxOS to retrieve a challenge."""
     uri = self._get_api_uri('login')
     content = self._freebox_get(uri)
     if 'challenge' in content:
         self.challenge = content['challenge']
         logger.info("Freebox Login OK")
         config.save_configuration(self.to_dict())
     else:
         logger.info("Freebox Login KO")
         raise common.FreeboxOSException("Login failed: %s" % content)
コード例 #3
0
 def test_save_configuration_on_existing_file(self):
     freeboxclient.CONFIG_FILE = self.random_configuration_file()
     self.creates_configuration_file()
     conf = config.load_configuration()
     conf['app_token'] = 'dyNYgfK0Ya'
     conf['track_id'] = '666'
     conf['status'] = 'granted'
     conf['challenge'] = 'Bj6xMqoe+DCHD44Kq'
     config_file = config.get_configuration_filename()
     config.save_configuration(conf)
     self.assertTrue('dyNYgfK0Ya' in open(config_file).read())
     self.assertTrue('666' in open(config_file).read())
     self.assertTrue('granted' in open(config_file).read())
     self.assertTrue('Bj6xMqoe+DCHD44Kq' in open(config_file).read())
コード例 #4
0
 def close_session(self):
     """Request to the FreeboxOS to close the current session."""
     uri = self._get_api_uri('login/logout')
     params = {'app_id': self.app_id,
               'password': self._creates_password(self.app_token,
                                                  self.challenge)}
     content = self._freebox_post(uri, params)
     if 'success' in content:
         self.session_token = ''
         self.challenge = ''
         logger.info("Freebox Session closed.")
         config.save_configuration(self.to_dict())
     else:
         raise common.FreeboxOSException("Close session failed: %s" %
                                         content)
コード例 #5
0
 def open_session(self):
     """Request the FreeboxOS to retrieve a session token."""
     uri = self._get_api_uri('login/session')
     params = {'app_id': self.app_id,
               'password': self._creates_password(self.app_token,
                                                  self.challenge)}
     content = self._freebox_post(uri, params)
     if 'session_token' in content:
         self.session_token = content['session_token']
         self.challenge = content['challenge']
         logger.info("Freebox Session opened.")
         config.save_configuration(self.to_dict())
     else:
         raise common.FreeboxOSException("Open session failed: %s" %
                                         content)
コード例 #6
0
 def ask_authorization(self):
     """Request authorization to the Freebox OS."""
     params = {'app_id': self.app_id,
               'app_name': self.app_name,
               'app_version': self.app_version,
               'device_name': self.device_name}
     uri = self._get_api_uri('login/authorize')
     content = self._freebox_post(uri, params)
     if 'track_id' in content and 'app_token' in content:
         self.track_id = content['track_id']
         self.app_token = content['app_token']
         logger.info("Accept this application. Look at the LCD screen.")
         config.save_configuration(self.to_dict())
     else:
         raise common.FreeboxOSException("Authorization failed: %s" %
                                         content)