示例#1
0
 def do_profile(self, name: str):
     if self.client is None:
         self.info('login first')
         return
     profile = None
     if name is None:
         identifier = g_facebook.current_user.identifier
     elif name.startswith('{') and name.endswith('}'):
         identifier = g_facebook.current_user.identifier
         profile = json.loads(name)
     else:
         identifier = g_facebook.identifier(name)
         if identifier is None:
             self.info('I don\'t understand.')
             return
     if profile:
         private_key = g_facebook.private_key_for_signature(
             identifier=g_facebook.current_user.identifier)
         assert private_key is not None, 'failed to get private key for client: %s' % self.client
         # create new profile and set all properties
         tai = Profile.new(identifier=identifier)
         for key in profile:
             tai.set_property(key, profile.get(key))
         tai.sign(private_key=private_key)
         cmd = ProfileCommand.response(identifier=identifier, profile=tai)
     else:
         cmd = ProfileCommand.query(identifier=identifier)
     self.client.send_command(cmd=cmd)
示例#2
0
 def __response_meta(self) -> MetaCommand:
     gid = self.__group.identifier
     meta = self.__group.meta
     profile = self.__group.profile
     if profile is None:
         cmd = MetaCommand.response(identifier=gid, meta=meta)
     else:
         cmd = ProfileCommand.response(identifier=gid,
                                       profile=profile,
                                       meta=meta)
     return cmd
示例#3
0
 def query_profile(self, identifier: str) -> (int, Optional[Content]):
     # check ID
     identifier = self.identifier(identifier)
     if identifier is None:
         return 400, None  # Bad Request
     # get profile
     profile = self.profile(identifier)
     if profile is None:
         return 404, None  # Not Found
     # get meta
     meta = self.meta(identifier)
     # OK
     return 200, ProfileCommand.new(identifier=identifier,
                                    meta=meta,
                                    profile=profile)
示例#4
0
 def query_profile(self, identifier: ID) -> bool:
     cmd = ProfileCommand.new(identifier=identifier)
     return self.send_command(cmd=cmd)