splitwise_api 1.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • new64

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

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
|           |       |-- SingleUserEntity.dart
|           |       |-- categories_entity.dart
|           |       |-- comments_entity.dart
|           |       | (6 more...)
|           |       |-- post_response.dart
|           |       |-- postexpense.dart
|           |       '-- single_group_entity.dart
|           '-- helper
|               '-- TokensHelper.dart
'-- pubspec.yaml


Usage

  • Import the package
dependencies:
  splitwise_api: ^1.0.2
  • 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(String text) async {
    final prefs = await SharedPreferences.getInstance();
    prefs.setString('tokens', text);
  }

  getTokens() async {
    final prefs = await SharedPreferences.getInstance();
    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

[0.0.1] - June 29 2k20 #

  • Added all methods
  • No data classes as of now
  • Some bugs that need to be fixed

[0.0.2 ] - June 29 2k20 #

  • BugFix and README update

[0.0.3] - June 30 2k20 #

  • BugFix and added Comments

[1.0.0] - July 03 2k20 #

  • Fixed Comments and first Release

[1.0.1] - July 09 2k20 #

  • Added Data Class
  • Added Token Helper

[1.0.2] - July 09 2k20 #

  • Minor BugFix

example/example.dart

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);
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  splitwise_api: ^1.0.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:splitwise_api/splitwise_api.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
29
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
64
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14

Health suggestions

Fix lib/src/util/data/model/current_user_entity.dart. (-0.50 points)

Analysis of lib/src/util/data/model/current_user_entity.dart reported 1 hint:

line 2 col 8: Unused import: 'friends_entity.dart'.

Fix lib/src/util/data/model/postexpense.dart. (-0.50 points)

Analysis of lib/src/util/data/model/postexpense.dart reported 1 hint:

line 10 col 12: Unnecessary new keyword.

Format lib/src/util/data/model/SingleUserEntity.dart.

Run dartfmt to format lib/src/util/data/model/SingleUserEntity.dart.

Fix additional 5 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/util/data/model/categories_entity.dart (Run dartfmt to format lib/src/util/data/model/categories_entity.dart.)
  • lib/src/util/data/model/comments_entity.dart (Run dartfmt to format lib/src/util/data/model/comments_entity.dart.)
  • lib/src/util/data/model/friends_entity.dart (Run dartfmt to format lib/src/util/data/model/friends_entity.dart.)
  • lib/src/util/data/model/notifications_entity.dart (Run dartfmt to format lib/src/util/data/model/notifications_entity.dart.)
  • lib/src/util/data/model/post_response.dart (Run dartfmt to format lib/src/util/data/model/post_response.dart.)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
oauth1 ^1.0.4 1.0.4
Transitive dependencies
charcode 1.1.3
collection 1.14.13 1.15.0-nullsafety
convert 2.1.1
crypto 2.1.5
http 0.12.1
http_parser 3.1.4
meta 1.2.2 1.3.0-nullsafety
path 1.7.0
pedantic 1.9.2
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.2.0 1.3.0-nullsafety