dynamic_call 1.0.7

  • Readme
  • Changelog
  • Installing
  • 70

Dynamic Call #

Dynamic Call framework, including API calls integration (HTTP,REST).

Usage #

A simple usage example:

import 'package:dynamic_call/dynamic_call.dart';
import 'dart:async' ;

// Entity for logged user:

class UserLogin {

  static UserLogin parse(dynamic json) {
    if ( json is Map ) {
      var username = json['username'] ;

      if (username != null) {
        try {
          String id = json['id'].toString() ;
          String name = json['name'] ;
          return UserLogin(id, username) ;
        }
        catch (e) {
          print(e);
        }
      }
    }

    return null ;
  }

  String _id ;
  String get id => _id ;

  String _username ;
  String get username => _username ;

  UserLogin(this._id, this._username);

}

// A generic AppSystem that can be used in many projects:

class AppSystem {

  final DynCall<dynamic,UserLogin> callLogin = DynCall<dynamic,UserLogin>( ['username','pass'] , DynCallType.JSON , (dynamic userJson) => UserLogin.parse(userJson) , true ) ;

  Future<UserLogin> login(String username, String pass, void Function(UserLogin user) onUserLogin) {
    return callLogin.call( {'username': username, 'pass': pass} , onUserLogin)  ;
  }

  final DynCall<bool,bool> callLogout = DynCall<bool,bool>( [] , DynCallType.BOOL , null, true ) ;

  Future<bool> logout() {
    return callLogout.call() ;
  }

  final DynCall<dynamic,UserLogin> callRegister = DynCall<dynamic,UserLogin>( ['name', 'email', 'username', 'password'] , DynCallType.JSON , (dynamic userJson) => UserLogin.parse(userJson) ) ;

  Future<UserLogin> register(String name, String email, String username, String pass, void Function(UserLogin user) onRegisteredUser) {
    return callRegister.call( {'name': name, 'email': email, 'username': username, 'password': pass} , onRegisteredUser) ;
  }

  final DynCall<bool,bool> callChangePassword = DynCall( ['username','currentPass','newPass'] , DynCallType.BOOL) ;

  Future<bool> changePassword(String username, String currentPass, String newPass) {
    return callChangePassword.call( {'username': username, 'currentPass': currentPass, 'newPass': newPass} )  ;
  }

}

// Example of usage of the system and integrate with an WS API:

main() async {
  
  var appSystem = AppSystem() ;

  ///////////////////////////////////////////
  ////// Configure Dynamic Call Executors:

  var httpClient = DynCallHttpClient('https://your.domain') ;

  // DynCallExecutor with HttpClient with base URL: https://your.domain/path/to/api-1
  DynCallHttpExecutorFactory executorFactory = DynCallHttpExecutorFactory( httpClient , "path/to/api-1" ) ;

  // POST https://your.domain/path/to/api-1/login
  // Authorization: Basic BASE64($username:$pass)
  executorFactory.call( appSystem.callLogin ).executor( HttpMethod.POST, path: "login", authorizationFields: ['username', 'pass'] ) ;

  // GET https://your.domain/path/to/api-1/logout
  executorFactory.call( appSystem.callLogout ).executor( HttpMethod.GET, path: "logout" ) ;

  // POST https://your.domain/path/to/api-1/register
  // Content-Type: application/x-www-form-urlencoded; charset=UTF-8
  // name=$name&email=$email&username=$username&password=$password
  executorFactory.call( appSystem.callRegister ).executor( HttpMethod.POST, path: "register", parametersMap: {'*': '*'} ) ;

  // POST https://your.domain/path/to/api-1/changePassword
  // Content-Type: application/x-www-form-urlencoded; charset=UTF-8
  // username=$username&current_password=$currentPass&password=$newPass
  executorFactory.call(  appSystem.callChangePassword ).executor( HttpMethod.POST, path: "changePassword",
      parametersMap: {'*': '*', 'currentPass': 'current_password', 'newPass': 'password'},
      errorResponse: false
  ) ;
  
  ///////////////////////////////////////////
  ////// Usage of AppSystem:

  UserLogin loggedUser = await appSystem.login('joe', 'pass123', (user) => notifyLogin(user) ) ;

  // ... Or register a new user (back-end automatically logins with register user):

  UserLogin loggedUser = await appSystem.register('Joe Smith', 'joe@email.com', 'joe', 'pass123', (user) => notifyLogin(user) ) ;

  //... Change some user password:

  bool changePassOK = await appSystem.changePassword('joe','pass123','pass456') ;
  
  //... Logout current user:
 
  bool logoutOK = await appSystem.logout() ;

}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Author #

Graciliano M. Passos: gmpassos@GitHub.

License #

Dart free & open-source license.

1.0.7 #

  • DynCallHttpExecutor.outputFilterPattern now accepts variables from request response JSON ( if dynCall.outputType == DynCallType.JSON ).
  • mercury_client: ^1.1.4
  • swiss_knife: ^2.3.9

1.0.6 #

  • mercury_client: ^1.1.2

1.0.5 #

  • mercury_client: ^1.1.1

1.0.4 #

  • DynCallHttpExecutor: dynamic body, dynamic bodyPattern (String or Function), fullPath, outputInterceptor, setCredential(), authorizationFields
  • DynCallHttpExecutorFactory: authorizationExecutor(...)
  • Update dependencies:
    • mercury_client: 1.0.9

1.0.3 #

  • DynCallHttpExecutor: body, bodyPattern, bodyType, outputValidator, outputFilter, outputFilterPattern

1.0.2 #

  • Update dependencies:
    • Remove swiss_knife and enum_to_string.

1.0.1 #

  • Add Author and License to README.

1.0.0 #

  • Initial version, created by Stagehand

Use this package as a library

1. Depend on it

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


dependencies:
  dynamic_call: ^1.0.7

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:dynamic_call/dynamic_call.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
44
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
70
Learn more about scoring.

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

  • Dart: 2.8.1
  • pana: 0.13.8-dev

Health issues and suggestions

Document public APIs. (-0.76 points)

122 out of 123 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/src/dynamic_call_base.dart.

Run dartfmt to format lib/src/dynamic_call_base.dart.

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and dynamic_call.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
mercury_client ^1.1.4 1.1.5
swiss_knife ^2.3.9 2.4.0
Transitive dependencies
enum_to_string 1.0.9
intl 0.16.1
path 1.7.0
resource_portable 2.1.7
typed_data 1.1.6
Dev dependencies
pedantic ^1.8.0
test ^1.6.0