项目作者: srthkpthk

项目描述 :
Splitwise API for Dart
高级语言: Dart
项目地址: git://github.com/srthkpthk/splitwise_api.git
创建时间: 2020-06-26T03:03:03Z
项目社区:https://github.com/srthkpthk/splitwise_api

开源协议:MIT License

下载


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 Not 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

    1. |-- CHANGELOG.md
    2. |-- LICENSE
    3. |-- README.md
    4. |-- example
    5. | '-- example.dart
    6. |-- lib
    7. | |-- splitwise_api.dart
    8. | '-- src
    9. | '-- util
    10. | |-- auth
    11. | | '-- splitwise_main.dart
    12. | '-- helper
    13. | '-- TokensHelper.dart
    14. '-- pubspec.yaml

    Usage

    • Import the package
      1. dependencies:
      2. splitwise_api: ^2.0.3
    • Import in the file
  1. 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 :-
      ```dart
      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’);
}
}

  1. - Now Use the Wrapper and save the tokens.
  2. - ForExample :-
  3. ```dart
  4. import 'package:splitwise_api/splitwise_api.dart';
  5. void main() async {
  6. SplitWiseService splitWiseService =
  7. SplitWiseService.initialize(_consumerKey, _consumerSecret);
  8. /// SplitWiseHelper is for saving and retrieving from shared storage
  9. SplitWiseHelper splitWiseHelper = SplitWiseHelper();
  10. if (splitWiseHelper.getTokens() == null) {
  11. var authURL = splitWiseService.validateClient();
  12. print(authURL);
  13. //This Will print the token and also return them save them to Shared Prefs
  14. TokensHelper tokens = await splitWiseService.validateClient(
  15. verifier: 'theTokenYouGetAfterAuthorization');
  16. await splitWiseHelper.saveTokens(tokens);
  17. splitWiseService.validateClient(tokens: tokens);
  18. } else {
  19. splitWiseService.validateClient(
  20. tokens: /* tokens from saved */);
  21. print(await splitWiseService.getCurrentUser());
  22. }
  23. }

Hit like if it helped