Skip to content

Commit

Permalink
Version 2.0.0 (#42)
Browse files Browse the repository at this point in the history
Version 2 of Splitwise
- Added OAuth2 
- Fixed Error handling
- Added docs
- Added tests
- Added exceptions
  • Loading branch information
namaggarwal authored Jun 30, 2020
1 parent 870348a commit f0a09e9
Show file tree
Hide file tree
Showing 50 changed files with 4,073 additions and 265 deletions.
7 changes: 7 additions & 0 deletions .github/release-issue-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Release {{env.VERSION}}
assignees: namaggarwal
labels: ready-to-release
---

A new version of Splitwise is ready to be released.
34 changes: 34 additions & 0 deletions .github/workflows/end_to_end_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: End to End Tests

on:
pull_request:
types: [opened, reopened]

jobs:
build:
if: github.actor == 'namaggarwal'
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [2.7, 3.7]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest mock
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Install current package
run: pip install .
- name: Test with pytest
env:
CONSUMER_KEY: ${{ secrets.CONSUMER_KEY }}
CONSUMER_SECRET: ${{ secrets.CONSUMER_KEY_SECRET }}
OAUTH_TOKEN: ${{ secrets.OAUTH_TOKEN }}
OAUTH_TOKEN_SECRET: ${{ secrets.OAUTH_TOKEN_SECRET }}
run: |
pytest e2e-tests
31 changes: 31 additions & 0 deletions .github/workflows/lint_and_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Lint and Test

on: [push,pull_request]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [2.7, 3.5, 3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest mock
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --max-complexity=10 --statistics
- name: Test with pytest
run: |
pytest tests
54 changes: 54 additions & 0 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Pre release package

on:
push:
tags:
- 'v*'
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body: |
Changes in this Release
draft: false
prerelease: true
deploy:
needs: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload --repository testpypi dist/*
- name: Create issue
uses: JasonEtco/create-an-issue@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ github.ref }}
with:
filename: .github/release-issue-template.md


59 changes: 59 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Release to python pip

on:
issue_comment:
types: [created]

jobs:
build:
if: github.actor == 'namaggarwal' && startsWith(github.event.issue.title, 'Release ') && github.event.comment.body == 'release'
runs-on: ubuntu-latest
steps:
- uses: actions-ecosystem/action-regex-match@v2
id: check-release
with:
text: ${{ github.event.issue.title }}
regex: '^Release refs/tags/(v\d\.\d\.\d)$'
- name: Notify user starting the release
if: ${{ steps.check-release.outputs.group1 != ''}}
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ github.event.comment.id }}
reactions: '+1'
- name: Checkout version ${{ steps.check-release.outputs.group1 }}
if: ${{ steps.check-release.outputs.group1 != ''}}
uses: actions/checkout@v2
with:
ref: ${{ steps.check-release.outputs.group1 }}
- name: Set up Python
if: ${{ steps.check-release.outputs.group1 != ''}}
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
if: ${{ steps.check-release.outputs.group1 != ''}}
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
if: ${{ steps.check-release.outputs.group1 != ''}}
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD_PRD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
- name: Notify user of successful release
if: ${{ steps.check-release.outputs.group1 != ''}}
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ github.event.comment.id }}
reactions: hooray
- name: Close Issue
if: ${{ steps.check-release.outputs.group1 != ''}}
uses: peter-evans/close-issue@v1
with:
issue-number: ${{ github.event.issue.number }}
comment: Release done


2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,5 @@ ENV/

.DS_Store
.pypirc
.vscode
/test.py
96 changes: 84 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
# Splitwise Python SDK

This is the python sdk for Splitwise APIs. At this point only GET requests and a single POST request ```createExpense``` is supported. Pull requests and bug reports are welcomed.
![](https://pepy.tech/badge/splitwise)
![](https://img.shields.io/pypi/l/splitwise.svg)
![](https://img.shields.io/pypi/wheel/splitwise.svg)
![](https://img.shields.io/pypi/pyversions/splitwise.svg)

This is the python sdk for Splitwise APIs. Pull requests and bug reports are welcomed.

## Latest Version

The latest version of splitwise SDK is Splitwise-1.3.0
The latest version of splitwise SDK is Splitwise-2.0.0

## Docs

The detailed docs are hosted at [readthedocs.org](https://readthedocs.org/projects/splitwise/)

## Installation

Expand Down Expand Up @@ -35,16 +44,19 @@ sObj = Splitwise("<consumer key>","<consumer secret>")
To get the debug logs use

```python
Splitwise.setDebug(True)
import logging
logging.basicConfig(level=logging.DEBUG)
```

## Usage

### Authorize splitwise

Before you can make call to splitwise, you need to get access token of the user on whose behalf you will be making call. Think of it as login with splitwise. Its based on OAuth2 and its a 2 step process.
Before you can make call to splitwise, you need to get access token of the user on whose behalf you will be making call. Think of it as login with splitwise. Its based on OAuth and its a 2 step process.


#### OAuth1

1. Get the Authorize URL and Secret. Redirect the user to the Authorize url and store the secret in somewhere for eg in session.

```python
Expand All @@ -66,6 +78,10 @@ Before you can make call to splitwise, you need to get access token of the user
session['access_token'] = access_token
```

#### OAuth2

It is now possible to use OAuth2 with Splitwise. For details you can refer to [readthedocs.org](https://readthedocs.org/projects/splitwise/)

### Get data from splitwise

Once you have the access token you can make the calls to splitwise. Get the splitwise instance and set the access token and then make authorized calls.
Expand Down Expand Up @@ -205,7 +221,7 @@ users.append(user2)

expense.setUsers(users)

expense = sObj.createExpense(expense)
expense, errors = sObj.createExpense(expense)
print expense.getId()
```

Expand Down Expand Up @@ -240,10 +256,44 @@ users.append(user2)

group.setMembers(users)

group = sObj.createGroup(group)
group, errors = sObj.createGroup(group)
print group.getId()
```

### Add user to group
You can use ```addUserToGroup(User, group_id)``` to add user to group. It takes in a `splitwise.user.User`
object that has either `id` or `firstName` and `email` set and a `group_id`.

```python
from splitwise.group import Group
from splitwise.user import User

sObj = Splitwise(Config.consumer_key,Config.consumer_secret)
sObj.setAccessToken(session['access_token'])

user = User()
user.setId(1223)

success, user, errors = sObj.addUserToGroup(user, 4456)

print(success)
```


### Delete group
You can use ```deleteGroup(group_id)``` to delete an existing group.

```python

sObj = Splitwise(Config.consumer_key,Config.consumer_secret)
sObj.setAccessToken(session['access_token'])

success, errors = sObj.deleteGroup(4456)

print(success)
```


## Objects

### User
Expand All @@ -256,6 +306,10 @@ Methods:
4. getEmail() - Returns the email of the user
5. getRegistrationStatus() - Returns the registraion status of the user
6. getPicture() - Returns a ```Picture``` object containing picture details
7. setId(id) - Sets the id of the user
8. setFirstName(first_name) - Sets the first name of user
9. setLastName(last_name) - Sets the last name of user
10. setEmail(email) - Sets the email of the user

### CurrentUser

Expand All @@ -281,12 +335,13 @@ Methods:
### Expense User
ExpenseUser is inherited from ```User```. All the methods of user are available for Expense User.


Methods:

1. getPaidShare() - Returns the Paid Share
2. getOwedShare() - Returns the Owed Share
3. getNetBalance() - Returns the Net Balance
4. setPaidShare(paid_share) - Sets the Paid Share
5. setOwedShare(owed_share) - Sets the Owed Share

### Group

Expand All @@ -300,17 +355,25 @@ Methods:
6. getMembers() - Returns a list of ```Friend``` objects
7. getOriginalDebts() - Returns a list of ```Debt``` objects
8. getType() - Returns the type of group
9. getSimplifiedDebts() - Returns a list of ```Debt``` objects
10. getInviteLink() - Returns the invite link
9. getGroupType() - Returns the type of group
10. getSimplifiedDebts() - Returns a list of ```Debt``` objects
11. getInviteLink() - Returns the invite link
12. setName(name) - Sets the name of the group
13. setCountryCode(code) - Sets the country code of the group
14. setWhiteBoard(text) - Sets the whiteboard contents of this group
15. isSimplifiedByDefault(bool) - Sets if group is simplified by default or not
16. setMembers(users) - Sets a list of ```Friend``` objects
17. addMember(user) - Add to a list of ```Friend``` objects
18. setType(type) - Sets the type of group
19. setGroupType(type) - Sets the type of group

### FriendGroup

Methods:

1. getId() - Returns the id of the group
2. getBalances() - Returns a list of ```Balance``` object


3. setId(id) - sets the id of the group

### Balance

Expand Down Expand Up @@ -377,7 +440,16 @@ Methods:
27. getExpenseBundleId() - Returns Expense Bundle ID
28. getFriendshipId() - Returns the Friendship ID
29. getRepayments() - Returns a list of ```Debt``` objects

30. setGroupId(id) - Sets the id of the group expense belongs to
31. setDescription(description) - Sets the description of expense
31. setRepeatInterval(interval) - Sets the repeat interval of expense
33. setCost(cost) - Sets the cost of transaction
34. setCurrencyCode(code) - Sets the currency code of transaction
35. setSplitEqually(is_split_equally) - Sets if expense is to be split equally
36. setReceipt(receipt) - Sets a ```Receipt``` object for receipt
37. setCategory(category) - Sets a ```Category``` object for category
38. setUsers(users) - Sets a list of ```ExpenseUser``` objects
39. addUser(user) - Adds to a list of ```ExpenseUser``` objects

### Picture

Expand Down
Loading

0 comments on commit f0a09e9

Please sign in to comment.