splitwise_api 2.0.1 copy "splitwise_api: ^2.0.1" to clipboard
splitwise_api: ^2.0.1 copied to clipboard

outdated

A Wrapper over SplitWise API. * Uses OAuth 1 as Authentication. * Includes all methods stated on SplitWise DEV website.

SplitWise API for Dart Say Thanks! License GitHub stars #

A wrapper based on SplitWise

  • Feel free to open a PR or Issue
  • Uses OAuth 1
  • Data Classes Included
  • Based on null-safety

Steps #

  • Get the consumerKey and consumerSecret from Splitwise Register App
  • Check the example.dart located in example/example.dart

Project Structure #

|-- .gitignore
|-- .metadata
|-- CHANGELOG.md
|-- LICENSE
|-- README.md
|-- example
|   '-- example.dart
|-- lib
|   |-- splitwise_api.dart
|   '-- src
|       '-- util
|           |-- auth
|           |   '-- splitwise_main.dart
|           |-- data
|           |   '-- model
|           |       |-- CategoriesEntity
|           |       |   |-- CategoriesEntity.dart
|           |       |   |-- categories.dart
|           |       |   |-- icon_types.dart
|           |       |   |-- slim.dart
|           |       |   |-- square.dart
|           |       |   '-- subcategories.dart
|           |       |-- CommentsEntity
|           |       |   |-- CommentsEntity.dart
|           |       |   '-- comments.dart
|           |       |-- CurrentUserEntity
|           |       |   |-- CurrentUserEntity.dart
|           |       |   |-- notifications.dart
|           |       |   '-- picture.dart
|           |       |-- ExpensesEntity
|           |       |   |-- ExpensesEntity.dart
|           |       |   |-- category.dart
|           |       |   |-- comments.dart
|           |       |   | (6 more...)
|           |       |   |-- updated_by.dart
|           |       |   |-- user.dart
|           |       |   '-- users.dart
|           |       |-- FriendsEntity
|           |       |   |-- FriendsEntity.dart
|           |       |   |-- balance.dart
|           |       |   |-- friends.dart
|           |       |   |-- groups.dart
|           |       |   '-- picture.dart
|           |       |-- GroupsEntity
|           |       |   |-- GroupsEntity.dart
|           |       |   |-- avatar.dart
|           |       |   |-- balance.dart
|           |       |   |-- cover_photo.dart
|           |       |   |-- groups.dart
|           |       |   |-- members.dart
|           |       |   |-- original_debts.dart
|           |       |   |-- picture.dart
|           |       |   '-- simplified_debts.dart
|           |       |-- NotificationsEntity
|           |       |   |-- NotificationsEntity.dart
|           |       |   |-- notifications.dart
|           |       |   '-- source.dart
|           |       |-- PostExpense
|           |       |   |-- PostExpense.dart
|           |       |   |-- category.dart
|           |       |   |-- comments.dart
|           |       |   | (7 more...)
|           |       |   |-- updated_by.dart
|           |       |   |-- user.dart
|           |       |   '-- users.dart
|           |       |-- PostResponse
|           |       |   |-- post_response.dart
|           |       |   '-- post_response.g.dart
|           |       '-- SingleUserEntity
|           |           |-- SingleUserEntity.dart
|           |           '-- picture.dart
|           '-- helper
|               '-- TokensHelper.dart
'-- pubspec.yaml

Usage

  • Import the package
dependencies:
  splitwise_api: ^2.0.1
  • Import in the file
import 'package:splitwise_api/splitwise_api.dart';
  • Setup SharedPreferences or any other system to save the token and tokenSecret to keep user logged in.
    • For Example :-
import 'package:shared_preferences/shared_preferences.dart';

class SplitWiseHelper {
  saveTokens(TokensHelper tokens) async {
    final prefs = await SharedPreferences.getInstance();
    prefs.setStringList('tokens',[tokens.token,tokens.tokenSecret]);
  }

  getTokens() async {
    final prefs = await SharedPreferences.getInstance();
   return prefs.getString('tokens');
  }
}
  • Now Use the Wrapper and save the tokens.
    • ForExample :-
import 'package:splitwise_api/splitwise_api.dart';
import 'package:splitwise_api/src/util/data/model/current_user_entity.dart';


void main() async {
  SplitWiseService splitWiseService =
  SplitWiseService.initialize(_consumerKey, _consumerSecret);

  /// SplitWiseHelper is for saving and retrieving from shared storage
  SplitWiseHelper splitWiseHelper = SplitWiseHelper();
  if (splitWiseHelper.getTokens() == null) {
    var authURL = splitWiseService.validateClient();
    print(authURL);
    //This Will print the token and also return them save them to Shared Prefs
    TokensHelper tokens = await splitWiseService.validateClient(
        verifier: 'theTokenYouGetAfterAuthorization');
    await splitWiseHelper.saveTokens(tokens);

    splitWiseService.validateClient(tokens: tokens);
  } else {
    splitWiseService.validateClient(
        tokens: /* tokens from saved */);
    //Example
    CurrentUserEntity currentUserEntity = await splitWiseService
        .getCurrentUser();
    print(currentUserEntity.user.firstName);
  }
}

Hit like if it helped

1
likes
0
pub points
16%
popularity

Publisher

unverified uploader

A Wrapper over SplitWise API. * Uses OAuth 1 as Authentication. * Includes all methods stated on SplitWise DEV website.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

json_annotation, json_serializable, oauth1

More

Packages that depend on splitwise_api