示例#1
0
    def get_my_profile(self,
                       callback=None,
                       force_update=False) -> Union[User, None]:
        """
        Get my profile info and return as a <User>
        :return my_profile: <User>
        """
        if self.__profile and not force_update:
            return self.__profile

        # Prepare the request
        resource_path = '/account'
        nested_response = ['user']
        wrapped_callback = wrap_callback(callback=callback,
                                         data_type=User,
                                         nested_response=nested_response)
        # Make the request
        response = self.__api_client.call_api(resource_path=resource_path,
                                              method='GET',
                                              callback=wrapped_callback)
        # Return None if threaded
        if callback:
            return

        self.__profile = deserialize(response=response,
                                     data_type=User,
                                     nested_response=nested_response)
        return self.__profile
示例#2
0
    def search_for_users(self, query: str, callback=None,
                         offset: int = 0, limit: int = 50, username=False) -> Union[List[User], None]:
        """
        search for [query] in users
        :param query:
        :param callback:
        :param offset:
        :param limit:
        :param username: default: False; Pass True if search is by username
        :return users_list: <list> A list of <User> objects or empty
        """

        resource_path = '/users'
        wrapped_callback = wrap_callback(callback=callback,
                                         data_type=User)

        params = {'query': query, 'limit': limit, 'offset': offset}
        # update params for querying by username
        if username or '@' in query:
            params.update({'query': query.replace('@', ''), 'type': 'username'})

        response = self.__api_client.call_api(resource_path=resource_path, params=params,
                                              method='GET', callback=wrapped_callback)
        # Return None if threaded
        if callback:
            return

        return deserialize(response=response,
                           data_type=User).set_method(method=self.search_for_users,
                                                      kwargs={"query": query, "limit": limit},
                                                      current_offset=offset
                                                      )
示例#3
0
    def get_user_friends_list(self,
                              user_id: str = None,
                              user: User = None,
                              callback=None,
                              page: int = 1,
                              count: int = 1337) -> Union[User, None]:
        """
        Get ([user_id]'s or [user]'s) friends list as a list of <User>s
        :return users_list: <list> A list of <User> objects or empty
        """
        user_id = get_user_id(user, user_id)
        params = self.__prepare_offset_limit_params(
            page_number=page,
            max_number_per_page=1337,
            max_offset=9999999999999999999,
            count=count)

        # Prepare the request
        resource_path = f'/users/{user_id}/friends'
        wrapped_callback = wrap_callback(callback=callback, data_type=User)
        # Make the request
        response = self.__api_client.call_api(resource_path=resource_path,
                                              method='GET',
                                              params=params,
                                              callback=wrapped_callback)
        # Return None if threaded
        if callback:
            return

        return deserialize(response=response, data_type=User)
示例#4
0
    def get_user_transactions(self, user_id: str = None, user: User = None,
                              callback=None,
                              limit: int = 50,
                              before_id=None) -> Union[Page, None]:
        """
        Get ([user_id]'s or [user]'s) transactions visible to yourself as a list of <Transaction>s
        :param user_id:
        :param user:
        :param callback:
        :param limit:
        :param before_id:
        :return:
        """
        user_id = get_user_id(user, user_id)

        params = {'limit': limit}
        if before_id:
            params['before_id'] = before_id

        # Prepare the request
        resource_path = f'/stories/target-or-actor/{user_id}'

        wrapped_callback = wrap_callback(callback=callback,
                                         data_type=Transaction)
        # Make the request
        response = self.__api_client.call_api(resource_path=resource_path,
                                              method='GET', params=params,
                                              callback=wrapped_callback)
        # Return None if threaded
        if callback:
            return

        return deserialize(response=response,
                           data_type=Transaction).set_method(method=self.get_user_transactions,
                                                             kwargs={"user_id": user_id})
示例#5
0
    def get_user_friends_list(self, user_id: str = None,
                              user: User = None,
                              callback=None,
                              offset: int = 0,
                              limit: int = 3337) -> Union[Page, None]:
        """
        Get ([user_id]'s or [user]'s) friends list as a list of <User>s
        :return users_list: <list> A list of <User> objects or empty
        """
        user_id = get_user_id(user, user_id)
        params = {"limit": limit, "offset": offset}

        # Prepare the request
        resource_path = f'/users/{user_id}/friends'
        wrapped_callback = wrap_callback(callback=callback,
                                         data_type=User)
        # Make the request
        response = self.__api_client.call_api(resource_path=resource_path,
                                              method='GET', params=params,
                                              callback=wrapped_callback)
        # Return None if threaded
        if callback:
            return

        return deserialize(
            response=response,
            data_type=User).set_method(method=self.get_user_friends_list,
                                       kwargs={"user_id": user_id, "limit": limit},
                                       current_offset=offset
                                       )
示例#6
0
    def search_for_users(self, query: str, callback=None,
                         page: int = 1, count: int = 50) -> Union[List[User], None]:
        """
        search for [query] in users
        :param query: <str>
        :param callback: <function>
        :param count: <int>
        :param page: <int>
        :return users_list: <list> A list of <User> objects or empty
        """

        resource_path = '/users'
        wrapped_callback = wrap_callback(callback=callback,
                                         data_type=User)

        offset_limit_params = self.__prepare_offset_limit_params(page_number=page,
                                                                 max_number_per_page=50,
                                                                 max_offset=9900,
                                                                 count=count)
        params = {'query': query}
        params.update(offset_limit_params)

        response = self.__api_client.call_api(resource_path=resource_path, params=params,
                                              method='GET', callback=wrapped_callback)
        # Return None if threaded
        if callback:
            return

        return deserialize(response=response, data_type=User)
示例#7
0
    def get_transaction_between_two_users(
            self,
            user_id_one: str = None,
            user_id_two: str = None,
            user_one: User = None,
            user_two: User = None,
            callback=None,
            count: int = 50,
            before_id=None) -> Union[Transaction, None]:
        """
        Get the transactions between two users. Note that user_one must be the owner of the access token.
        Otherwise it raises an unauthorized error.
        :param user_id_one:
        :param user_id_two:
        :param user_one:
        :param user_two:
        :param callback:
        :param count:
        :param before_id:
        :return:
        """
        user_id_one = get_user_id(user_one, user_id_one)
        user_id_two = get_user_id(user_two, user_id_two)

        params = {'limit': count}
        if before_id:
            params['before_id'] = before_id

        # Prepare the request
        resource_path = f'/stories/target-or-actor/{user_id_one}/target-or-actor/{user_id_two}'

        wrapped_callback = wrap_callback(callback=callback,
                                         data_type=Transaction)
        # Make the request
        response = self.__api_client.call_api(resource_path=resource_path,
                                              method='GET',
                                              params=params,
                                              callback=wrapped_callback)
        # Return None if threaded
        if callback:
            return

        return deserialize(response=response, data_type=Transaction)
示例#8
0
    def get_payment_methods(self, callback=None) -> Union[List[PaymentMethod], None]:
        """
        Get a list of available payment_methods
        :param callback:
        :return:
        """

        wrapped_callback = wrap_callback(callback=callback,
                                         data_type=PaymentMethod)

        resource_path = '/payment-methods'
        response = self.__api_client.call_api(resource_path=resource_path,
                                              method='GET',
                                              callback=wrapped_callback)
        # return the thread
        if callback:
            return

        return deserialize(response=response, data_type=PaymentMethod)
示例#9
0
    def get_user(self, user_id: str, callback=None) -> Union[User, None]:
        """
        Get the user profile with [user_id]
        :param user_id: <str>, example: '2859950549165568970'
        :param callback: <function>
        :return user: <User> <NoneType>
        """

        # Prepare the request
        resource_path = f'/users/{user_id}'
        wrapped_callback = wrap_callback(callback=callback, data_type=User)
        # Make the request
        response = self.__api_client.call_api(resource_path=resource_path,
                                              method='GET',
                                              callback=wrapped_callback)
        # Return None if threaded
        if callback:
            return

        return deserialize(response=response, data_type=User)
示例#10
0
    def __get_payments(self, action, limit, callback=None):
        """
        Get a list of ongoing payments with the given action
        :return:
        """
        wrapped_callback = wrap_callback(callback=callback, data_type=Payment)

        resource_path = '/payments'
        parameters = {
            "action": action,
            "actor": self.__profile.id,
            "limit": limit
        }
        response = self.__api_client.call_api(resource_path=resource_path,
                                              params=parameters,
                                              method='GET',
                                              callback=wrapped_callback)
        if callback:
            return

        return deserialize(response=response, data_type=Payment)
示例#11
0
    def search_for_users(self,
                         query: str,
                         callback=None,
                         page: int = 1,
                         count: int = 50,
                         username=False) -> Union[List[User], None]:
        """
        search for [query] in users
        :param query:
        :param callback:
        :param page:
        :param count:
        :param username: default: False; Pass True if search is by username
        :return users_list: <list> A list of <User> objects or empty
        """

        resource_path = '/users'
        wrapped_callback = wrap_callback(callback=callback, data_type=User)

        offset_limit_params = self.__prepare_offset_limit_params(
            page_number=page,
            max_number_per_page=50,
            max_offset=9900,
            count=count)
        params = {'query': query}
        if username or '@' in query:
            params = {'query': query.replace('@', ''), 'type': 'username'}
        params.update(offset_limit_params)

        response = self.__api_client.call_api(resource_path=resource_path,
                                              params=params,
                                              method='GET',
                                              callback=wrapped_callback)
        # Return None if threaded
        if callback:
            return

        return deserialize(response=response, data_type=User)