Beispiel #1
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)
Beispiel #2
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})
Beispiel #3
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
                                       )
Beispiel #4
0
    def __send_or_request_money(self, amount: float,
                                note: str,
                                is_send_money,
                                funding_source_id: str = None,
                                privacy_setting: str = PaymentPrivacy.PRIVATE.value,
                                target_user_id: int = None, target_user: User = None,
                                callback=None) -> Union[bool, None]:
        """
        Generic method for sending and requesting money
        :param amount:
        :param note:
        :param is_send_money:
        :param funding_source_id:
        :param privacy_setting:
        :param target_user_id:
        :param target_user:
        :param callback:
        :return:
        """
        target_user_id = str(get_user_id(target_user, target_user_id))

        amount = abs(amount)
        if not is_send_money:
            amount = -amount

        body = {
            "user_id": target_user_id,
            "audience": privacy_setting,
            "amount": amount,
            "note": note
        }

        if is_send_money:
            if not funding_source_id:
                funding_source_id = self.get_default_payment_method().id
            body.update({"funding_source_id": funding_source_id})

        resource_path = '/payments'

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

        result = self.__api_client.call_api(resource_path=resource_path,
                                            method='POST',
                                            body=body,
                                            callback=wrapped_callback)
        # handle 200 status code errors
        error_code = result['body']['data'].get('error_code')
        if error_code:
            if error_code == self.__payment_error_codes['not_enough_balance_error']:
                raise NotEnoughBalanceError(amount, target_user_id)

            error = result['body']['data']
            raise GeneralPaymentError(f"{error.get('title')}\n{error.get('error_msg')}")

        if callback:
            return
        # if no exception raises, then it was successful
        return True
Beispiel #5
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)
Beispiel #6
0
    def __send_or_request_money(
            self,
            amount: float,
            note: str,
            is_send_money,
            funding_source_id: str = None,
            privacy_setting: str = PaymentPrivacy.PRIVATE.value,
            target_user_id: int = None,
            target_user: User = None,
            callback=None) -> Union[bool, None]:
        """
        Generic method for sending and requesting money
        :param amount:
        :param note:
        :param is_send_money:
        :param funding_source_id:
        :param privacy_setting:
        :param target_user_id:
        :param target_user:
        :param callback:
        :return:
        """
        target_user_id = str(get_user_id(target_user, target_user_id))

        amount = abs(amount)
        if not is_send_money:
            amount = -amount

        body = {
            "user_id": target_user_id,
            "audience": privacy_setting,
            "amount": amount,
            "note": note
        }

        if is_send_money:
            if not funding_source_id:
                funding_source_id = self.get_default_payment_method().id
            body.update({"funding_source_id": funding_source_id})

        resource_path = '/payments'

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

        self.__api_client.call_api(resource_path=resource_path,
                                   method='POST',
                                   body=body,
                                   callback=wrapped_callback)
        if callback:
            return
        # if no exception raises, then it was successful
        return True