How to use the splitwise.user.User function in splitwise

To help you get started, we’ve selected a few splitwise examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github namaggarwal / splitwise / tests / test_addUserToGroup.py View on Github external
def test_createGroup_exception(self, mockMakeRequest):
        mockMakeRequest.side_effect = Exception(
            "Invalid response %s. Please check your consumer key and secret." % 404)
        user = User()
        user.setId(281236)
        with self.assertRaises(Exception):
            success, userRes, errors = self.sObj.addUserToGroup(user, 19481273)
        mockMakeRequest.assert_called_with(
            "https://secure.splitwise.com/api/v3.0/add_user_to_group", "POST",
            {'group_id': 19481273, 'user_id': 281236})
github namaggarwal / splitwise / tests / test_addUserToGroup.py View on Github external
def test_addUserToGroup_withid_success(self, mockMakeRequest):
        mockMakeRequest.return_value = '{"success":true,"user":{"id":281236,"first_name":"Siddharth","last_name":"Goel","picture":{"small":"https://splitwise.s3.amazonaws.com/uploads/user/avatar/281236/small_f5fccc37-0a88-4519-9398-59c8c19b92aa.jpeg","medium":"https://splitwise.s3.amazonaws.com/uploads/user/avatar/281236/medium_f5fccc37-0a88-4519-9398-59c8c19b92aa.jpeg","large":"https://splitwise.s3.amazonaws.com/uploads/user/avatar/281236/large_f5fccc37-0a88-4519-9398-59c8c19b92aa.jpeg"},"custom_picture":true,"email":"siddharth98391@gmail.com","registration_status":"confirmed","balance":[]},"errors":{}}'  # noqa: E501
        user = User()
        user.setId(281236)
        success, userRes, errors = self.sObj.addUserToGroup(user, 19481273)
        mockMakeRequest.assert_called_with(
            "https://secure.splitwise.com/api/v3.0/add_user_to_group", "POST",
            {'group_id': 19481273, 'user_id': 281236})
        self.assertTrue(success)
        self.assertIsNone(errors)
        self.assertEqual(userRes.getId(), 281236)
        self.assertEqual(userRes.getFirstName(), "Siddharth")
        self.assertEqual(userRes.getLastName(), "Goel")
        self.assertEqual(userRes.getPicture().getSmall(
        ), "https://splitwise.s3.amazonaws.com/uploads/user/avatar/281236/small_f5fccc37-0a88-4519-9398-59c8c19b92aa.jpeg")
        self.assertEqual(userRes.getPicture().getMedium(
        ), "https://splitwise.s3.amazonaws.com/uploads/user/avatar/281236/medium_f5fccc37-0a88-4519-9398-59c8c19b92aa.jpeg")
        self.assertEqual(userRes.getPicture().getLarge(
        ), "https://splitwise.s3.amazonaws.com/uploads/user/avatar/281236/large_f5fccc37-0a88-4519-9398-59c8c19b92aa.jpeg")
github namaggarwal / splitwise / tests / test_addUserToGroup.py View on Github external
def test_addUserToGroup_error(self, mockMakeRequest):
        mockMakeRequest.return_value = '{"success":false,"user":null,"errors":{"memberships.user.first_name":["can\'t be blank"]}}'  # noqa: E501
        user = User()
        success, userRes, errors = self.sObj.addUserToGroup(user, 19481273)
        mockMakeRequest.assert_called_with(
            "https://secure.splitwise.com/api/v3.0/add_user_to_group", "POST",
            {
                'group_id': 19481273
            })
        self.assertIsNone(userRes)
        self.assertFalse(success)
        self.assertEqual(errors.getErrors(), {'memberships.user.first_name': ["can't be blank"]})
github namaggarwal / splitwise / tests / test_addUserToGroup.py View on Github external
def test_addUserToGroup_with_email_success(self, mockMakeRequest):
        mockMakeRequest.return_value = '{"success":true,"user":{"id":62,"first_name":"Testes","last_name":null,"picture":{"small":"https://s3.amazonaws.com/splitwise/uploads/user/default_avatars/avatar-orange16-50px.png","medium":"https://s3.amazonaws.com/splitwise/uploads/user/default_avatars/avatar-orange16-100px.png","large":"https://s3.amazonaws.com/splitwise/uploads/user/default_avatars/avatar-orange16-200px.png"},"custom_picture":false,"email":"test@test.com","registration_status":"confirmed","balance":[]},"errors":{}}'  # noqa: E501
        user = User()
        user.setFirstName("testFirst")
        user.setLastName("testLast")
        user.setEmail("test@test.com")
        success, userRes, errors = self.sObj.addUserToGroup(user, 19481273)
        mockMakeRequest.assert_called_with(
            "https://secure.splitwise.com/api/v3.0/add_user_to_group", "POST",
            {'first_name': 'testFirst',
             'last_name': 'testLast',
             'email': 'test@test.com',
             'group_id': 19481273
             })
        self.assertTrue(success)
        self.assertIsNone(errors)
        self.assertEqual(userRes.getId(), 62)
        self.assertEqual(userRes.getFirstName(), "Testes")
        self.assertEqual(userRes.getLastName(), None)
github namaggarwal / splitwise / splitwise / expense.py View on Github external
self.currency_code = data["currency_code"]
            self.created_by = User(data["created_by"])
            self.date = data["date"]
            self.created_at = data["created_at"]
            self.updated_at = data["updated_at"]
            self.deleted_at = data["deleted_at"]
            self.receipt = Receipt(data["receipt"])
            self.category = Category(data["category"])

            if data["updated_by"] is not None:
                self.updated_by = User(data["updated_by"])
            else:
                self.updated_by = None

            if data["deleted_by"] is not None:
                self.deleted_by = User(data["deleted_by"])
            else:
                self.deleted_by = None

            if "friendship_id" in data:
                self.friendship_id = data["friendship_id"]
            else:
                self.friendship_id = None

            if "expense_bundle_id" in data:
                self.expense_bundle_id = data["expense_bundle_id"]
            else:
                self.expense_bundle_id = None

            self.repayments = []
            for repayment in data["repayments"]:
                self.repayments.append(Debt(repayment))
github namaggarwal / splitwise / splitwise / __init__.py View on Github external
id (long): ID of the user whose information is needed

        Returns:
            :obj:`splitwise.user.User`: User object containing user data
        """
        try:
            content = self.__makeRequest(Splitwise.GET_USER_URL + "/"+str(id))
        except SplitwiseNotAllowedException as e:
            e.setMessage("You are not allowed to fetch user with id %d" % id)
            raise
        except SplitwiseNotFoundException as e:
            e.setMessage("User with id %d does not exist" % id)
            raise

        content = json.loads(content)
        return User(content["user"])
github namaggarwal / splitwise / splitwise / expense.py View on Github external
self.group_id = data["group_id"]
            self.description = data["description"]
            self.repeats = data["repeats"]
            self.repeat_interval = data["repeat_interval"]
            self.email_reminder = data["email_reminder"]
            self.email_reminder_in_advance = data["email_reminder_in_advance"]
            self.next_repeat = data["next_repeat"]
            self.details = data["details"]
            self.comments_count = data["comments_count"]
            self.payment = data["payment"]
            self.creation_method = data["creation_method"]
            self.transaction_method = data["transaction_method"]
            self.transaction_confirmed = data["transaction_confirmed"]
            self.cost = data["cost"]
            self.currency_code = data["currency_code"]
            self.created_by = User(data["created_by"])
            self.date = data["date"]
            self.created_at = data["created_at"]
            self.updated_at = data["updated_at"]
            self.deleted_at = data["deleted_at"]
            self.receipt = Receipt(data["receipt"])
            self.category = Category(data["category"])

            if data["updated_by"] is not None:
                self.updated_by = User(data["updated_by"])
            else:
                self.updated_by = None

            if data["deleted_by"] is not None:
                self.deleted_by = User(data["deleted_by"])
            else:
                self.deleted_by = None
github namaggarwal / splitwise / splitwise / user.py View on Github external
Returns:
            str: Date format used by the user
        """
        return self.date_format

    def getDefaultGroupId(self):
        """ Returns default group id the user

        Returns:
            long: default group id the user
        """
        return self.default_group_id


class Friend(User):
    """ Represents a friend user.

    Inherits: :class:`splitwise.user.User`

    Attributes:
        balances(:obj:`list` of :obj:`splitwise.balance.Balance`, optional): List of balances
        groups(:obj:`list` of :obj:`splitwise.group.FriendGroup`, optional): List of groups
        updated_at(str, optional): ISO 8601 Date time. The last updated date time of user
    """
    def __init__(self, data=None):
        """
          Args:
              data(:obj:`json`, optional): JSON object representing friend user object
        """
        User.__init__(self, data)
github namaggarwal / splitwise / splitwise / expense.py View on Github external
self.payment = data["payment"]
            self.creation_method = data["creation_method"]
            self.transaction_method = data["transaction_method"]
            self.transaction_confirmed = data["transaction_confirmed"]
            self.cost = data["cost"]
            self.currency_code = data["currency_code"]
            self.created_by = User(data["created_by"])
            self.date = data["date"]
            self.created_at = data["created_at"]
            self.updated_at = data["updated_at"]
            self.deleted_at = data["deleted_at"]
            self.receipt = Receipt(data["receipt"])
            self.category = Category(data["category"])

            if data["updated_by"] is not None:
                self.updated_by = User(data["updated_by"])
            else:
                self.updated_by = None

            if data["deleted_by"] is not None:
                self.deleted_by = User(data["deleted_by"])
            else:
                self.deleted_by = None

            if "friendship_id" in data:
                self.friendship_id = data["friendship_id"]
            else:
                self.friendship_id = None

            if "expense_bundle_id" in data:
                self.expense_bundle_id = data["expense_bundle_id"]
            else: