How to use the splitwise.__init__.Splitwise 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 / splitwise / __init__.py View on Github external
def getGroups(self):
        """ Gets the list of groups a user is part of.

        Returns:
            :obj:`list` of :obj:`splitwise.group.Group`: List of Groups
        """
        content = self.__makeRequest(Splitwise.GET_GROUPS_URL)
        content = json.loads(content)

        groups = []
        if "groups" in content:
            for g in content["groups"]:
                groups.append(Group(g))

        return groups
github namaggarwal / splitwise / splitwise / __init__.py View on Github external
Returns:
            dict: dict containing:
              oauth_token(str): The OAuth 1.0 token

              oauth_token_secret(str): The OAuth 1.0 token secret
        """
        oauth1 = OAuth1(
            self.consumer_key,
            client_secret=self.consumer_secret,
            resource_owner_key=oauth_token,
            resource_owner_secret=oauth_token_secret,
            verifier=oauth_verifier
        )

        try:
            content = self.__makeRequest(Splitwise.ACCESS_TOKEN_URL, 'POST', auth=oauth1)
        except SplitwiseUnauthorizedException as e:
            e.setMessage("Your oauth token could be expired or check your consumer id and secret")
            raise

        credentials = parse_qs(content)
        return {
            "oauth_token": credentials.get("oauth_token")[0],
            "oauth_token_secret": credentials.get("oauth_token_secret")[0],
        }
github namaggarwal / splitwise / splitwise / __init__.py View on Github external
def getFriends(self):
        """ Gets the list of users friends.

        Returns:
            :obj:`list` of :obj:`splitwise.user.Friend`: List of Friends
        """
        content = self.__makeRequest(Splitwise.GET_FRIENDS_URL)
        content = json.loads(content)

        friends = []
        if "friends" in content:
            for f in content["friends"]:
                friends.append(Friend(f))

        return friends
github namaggarwal / splitwise / splitwise / __init__.py View on Github external
def getAuthorizeURL(self):
        """ Provides the Authorize URL for end user's authentication

        Returns:
            tuple: tuple containing:
              auth_url(str): URL that user should be redirected to for authorization

              oauth_token_secret(str): Token secret that should be saved to redeem token
        """
        oauth1 = OAuth1(
            self.consumer_key,
            client_secret=self.consumer_secret
        )

        content = self.__makeRequest(Splitwise.REQUEST_TOKEN_URL, method='POST', auth=oauth1)
        credentials = parse_qs(content)

        return "%s?oauth_token=%s" % (
            Splitwise.AUTHORIZE_URL, credentials.get('oauth_token')[0]
        ), credentials.get('oauth_token_secret')[0]
github namaggarwal / splitwise / splitwise / __init__.py View on Github external
Args:
            group(:obj:`splitwise.group.Group`): Splitwise Group Object.

        Returns:
            tuple: tuple containing:
              group(:obj:`splitwise.group.Group`): Object with Group detail

              errors(:obj:`splitwise.error.SplitwiseError`): Object representing errors
        """
        # create group
        group_info = group.__dict__

        if "members" in group_info:
            group_members = group.getMembers()
            del group_info["members"]
            Splitwise.setUserArray(group_members, group_info)

        content = self.__makeRequest(
            Splitwise.CREATE_GROUP_URL, "POST", group_info)
        content = json.loads(content)
        group_detail = None
        errors = None
        if "group" in content:
            group_detail = Group(content["group"])
            if "errors" in content["group"]:
                if len(content["group"]['errors']) != 0:
                    errors = SplitwiseError(content["group"]["errors"])

        return group_detail, errors
github namaggarwal / splitwise / splitwise / __init__.py View on Github external
""" Deletes the group with given id.

        Args:
            id(long): ID of the group to be deleted.

        Returns:
            tuple: tuple containing:
              success(bool): True if group deleted, False otherwise

              errors(:obj:`splitwise.error.SplitwiseError`): Object representing errors
        """
        errors = None
        success = False
        try:
            content = self.__makeRequest(
                Splitwise.DELETE_GROUP_URL+"/"+str(id), "POST")
        except SplitwiseNotAllowedException as e:
            e.setMessage("You are not allowed to access group with id %d" % id)
            raise
        except SplitwiseNotFoundException as e:
            e.setMessage("Group with id %d does not exist" % id)
            raise

        content = json.loads(content)
        if 'success' in content:
            success = content["success"]

        if 'errors' in content:
            if len(content['errors']) != 0:
                errors = SplitwiseError(content['errors'])

        return success, errors
github namaggarwal / splitwise / splitwise / __init__.py View on Github external
def getOAuth2AuthorizeURL(self, redirect_uri, state=None):
        """ Provides the Authorize URL for end user's authentication

        Returns:
            tuple: tuple containing:
              auth_url(str): URL that user should be redirected to for authorization

              oauth_token_secret(str): Token secret that should be saved to redeem token
        """
        oauth = OAuth2Session(self.consumer_key, redirect_uri=redirect_uri, state=state)
        authorization_url, state = oauth.authorization_url(Splitwise.OAUTH_AUTHORIZE_URL)

        return authorization_url, state
github namaggarwal / splitwise / splitwise / __init__.py View on Github external
Returns:
            tuple: tuple containing:
              group(:obj:`splitwise.group.Group`): Object with Group detail

              errors(:obj:`splitwise.error.SplitwiseError`): Object representing errors
        """
        # create group
        group_info = group.__dict__

        if "members" in group_info:
            group_members = group.getMembers()
            del group_info["members"]
            Splitwise.setUserArray(group_members, group_info)

        content = self.__makeRequest(
            Splitwise.CREATE_GROUP_URL, "POST", group_info)
        content = json.loads(content)
        group_detail = None
        errors = None
        if "group" in content:
            group_detail = Group(content["group"])
            if "errors" in content["group"]:
                if len(content["group"]['errors']) != 0:
                    errors = SplitwiseError(content["group"]["errors"])

        return group_detail, errors
github namaggarwal / splitwise / splitwise / __init__.py View on Github external
def getCategories(self):
        """ Gets the list of categories in Splitwise.

        Returns:
            :obj:`list` of :obj:`splitwise.category.Category`: List of Category
        """
        content = self.__makeRequest(Splitwise.GET_CATEGORY_URL)
        content = json.loads(content)
        categories = []

        if "categories" in content:
            for c in content["categories"]:
                categories.append(Category(c))

        return categories
github namaggarwal / splitwise / splitwise / __init__.py View on Github external
def getCurrentUser(self):
        """ Gets the current authorized user's data

        Returns:
            :obj:`splitwise.user.CurrentUser`: CurrentUser object containing user data
        """
        content = self.__makeRequest(Splitwise.GET_CURRENT_USER_URL)
        content = json.loads(content)
        return CurrentUser(content["user"])