View all files | ||||
Java SDK for Splitwise
This library contains implementation of Splitwise SDK in Java. Currently the following splitwise API calls are supported,
get_current_user get_user/:id update_user/:id get_groups get_group/:id create_group delete_group/:id add_user_to_group remove_user_from_group get_friends get_friend/:id create_friend delete_friend/:id get_expenses get_expense/:id delete_expense/:id get_comments?expense_id= get_notifications get_currencies get_categories
Other API implementations are expected to follow as future updates. Pull requests and bugs are welcomed.
Maven
Add the following lines in pom.xml of the maven project to use the library,
Gradle
Add the following line in Gradle projects to use the library,
Authentication
Currently the authentication is performed using ScribeJava library which supports both OAuth1.0 and OAuth2.0. In this library, OAuth1.0 is included at this point of time. Authentication using OAuth2.0 is expected in the future updates.
Registration
The library expects consumer key and consumer secret of Splitwise and can be fetched after registering your application here.
Using the library
Authorization
As already mentioned, the library expects consumer key and consumer secret from Splitwise. As splitwise uses OAuth authentication for access, the user should also fetch token verifier from the authorization url. This is done in two steps,
To skip the process of authenticating every time, the token details fetched above can be used to set the token without actually going into authorizationURL.
However, the user must authorize at least once to get the token verifier.
Access data from splitwise
Once the authorization if performed and token details are fetched, they can be used to instantiate Splitwise class and set the access token as shown above.
The complete list of methods the library supports are as follows,
Get Current User
getCurrentUser() can be used to fetch current user. It returns the user details in a JSON string.
Get User
getUser(userId) can be used to fetch user details. It returns user details in a JSON String.
Update User
updateUser(userId, userDetails) can be used to update the details of the splitwise user. The user fields that can be updated can be seen here.
Get Groups
getGroups() can be used to fetch all the splitwise groups of the current user. It returns a JSON string of the group details.
Get Group
getGroup(groupId) can be used to fetch details of a specific splitwise group. It returns a JSON string of the group details.
Create Group
createGroup(groupDetails) can be used to create splitwise group. groupDetails can contain all the item shown here.
Delete Group
deleteGroup(groupId) can be used to delete a splitwise group.
Add User to Group
addUserToGroup(userDetails) can be used to add a user to a group.
Remove User from Group
removeUserFromGroup(groupId, userId) can be used to remove a splitwise user from a splitwise group.
Get Friends
getFriends() can be used to fetch all the splitwise friends of the current user. It returns a JSON string containing all the friend details.
Get Friend
getFriend(userId) can be used to fetch details of a splitwise friend. It returns a JSON string containing all the friend details.
Create a friend
createFriend(firstName, lastName, email) can be used to add a friend into Splitwise.
Delete a friend
deleteFriend(friendId) can be used to delete a friend from Splitwise.
Get Expenses
getExpenses() can be used to get all the expenses of the current user. It returns a JSON string containing all the expenses.
Get Expense
getExpense(expenseId) can be used to get details of a splitwise expense. It returns a JSON string containing the expense details.
Delete Expense
deleteExpense(expenseId) can be used to delete a splitwise expense.
Get Comments on an Expense
getComments(expenseId) can be used to get comments on a splitwise expense. It returns a JSON string containing the expense details.
Get Notifications
getNotifications() can be used to get unseen notifications of the current user. It returns a JSON string containing all the unseen notifications.
Get Currencies
getCurrencies() can be used to fetch the currencies supported by Splitwise. It returns a JSON string containing all the currencies.
Get Categories
getCategories() can be used to fetch the categories in Splitwise. It returns a JSON string containing all the categories.
Testing
The library includes test cases for some of the methods. It uses Mockito framework to mock the methods needed in unit test cases.
Test cases for two vital classes Splitwise and OAuthUtl are included in the library, SplitwiseTest and OAuthUtilTest.
License