mautic_api 1.0.7

Dart Mautic API #

Mautic API Wrapper for Dart and Flutter

Installing #

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

dependencies:
  mautic_api: any

Run flutter pub get on terminal to download and install packages and import on your files:

import 'package:mautic_api/mautic_api.dart';

Basic Usage #

You can create a new instance of class MauticAPI with 3 arguments: base_url, username and password:

  final api = MauticAPI('https://yourmauticaddress.com', 'username', 'password');

To test your credentials you can call getCurrentUser() to get your MauticUser. If the credentials fail the method return null.

  var user = await api.getCurrentUser();

Here a complete example to get current user info:

import 'package:mautic_api/mautic_api.dart';

void main() async {
  ///
  final api =
      MauticAPI('https://yourmauticaddress.com', 'username', 'password');

  var user = await api.getCurrentUser();

  print(user.id);
  print(user.firstName);
  print(user.lastName);
  print(user.email);
  print(user.onlineStatus);
}

Available Endpoints #

MauticAPI #

The class MauticAPI provides a constructor with 3 arguments:

Sample usage:

var api = MauticAPI('https://yourmauticaddress.com', 'username', 'password');

There are also two optional arguments to handle cache:

  • localPath: The Path for cache directory (default: ./tmp)
  • localExpiresMinutes: Time to Expire cache in minutes (default: 5)

On Flutter you can use the path_provider package to get default app cache directory.

The class MauticAPI has following attributes:

  /// Request Has Success?
  bool hasSuccess = false;

  /// Current Mautic Version?
  String mauticVersion;

  /// Is Data Read from Cache?
  bool isCachedData = false;

The class MauticAPI has following methods:

/// Return Current User
Future<MauticUser> getCurrentUser();

/// Return User by ID
Future<MauticUser> getUserByID(int _id);

/// Return All Users
Future<List<MauticUser>> getUsers();

/// Return Contact by ID
Future<MauticContact> getContactByID(int _id);

/// Return All Contacts
Future<List<MauticContact>> getContacts({ int page = 0, String s = 'email:%@%', String ob = 'last_active', String od = 'desc', int limit = 5});

/// Return the number of identified contacts
Future<int> getTotalContacts();

/// Return the number of pagination of contacts
Future<int> getContactsPagination({int limit = 30});

/// Return All Emails
Future<List<MauticEmail>> getEmails({ int page = 0, String s = '', String ob = 'id', String od = 'desc', int limit = 30});

/// Return Contact by ID
Future<MauticEmail> getEmailByID(int _id);

/// Return the number of emails
Future<int> getTotalEmails();

/// Return the number of pagination of emails
Future<int> getEmailsPagination({int limit = 30});

MauticUser #

Class MauticUser has the following attributes:

  /// User ID
  final int id;

  /// User First Name
  final String firstName;

  /// User Last Name
  final String lastName;

  /// User Email
  final String email;

  /// User Online Status
  final String onlineStatus;

MauticContact #

Class MauticContact has the following attributes:

  /// Contact ID
  final int id;

  /// Contact First Name
  final String firstName;

  /// Contact Last Name
  final String lastName;

  /// Contact Email
  final String email;

  /// Contact Points
  final int points;

  /// Contact Date Added
  final DateTime dateAdded;

  /// Contact Date Last Active
  final DateTime dateLastActive;

  /// Contact Date Identified
  final DateTime dateIdentified;

  /// Return if Contact is Identified
  bool get isIdentified;

Class MauticContact has the following methods:

  /// Return Gravatar URL
  String gravatarUrl({int size = 96});

MauticEmail #

Class MauticEmail has the following attributes:

  final int id;

  final bool isPublished;

  final String name;

  final String subject;

  final String fromAddress;

  final String fromName;

  final String replyToAddress;

  final String customHtml;

  final String plainText;

  final String template;

  final String emailType;

  final String language;

  final DateTime publishUp;

  final DateTime publishDown;

  final int readCount;

  final int sentCount;

  double readRate;

  bool hasTextPlain;

Changelog #

1.0.7 #

  • README

1.0.6 #

  • Class MauticEmail
  • Update README

1.0.5 #

  • Update README
  • Contacts New Methods
  • Fix Cached Filenames

1.0.4 #

  • Fix Dart Analysis
  • Add Cached Requests
  • Updated README

1.0.3 #

  • Fix Dart Analysis
  • Updated README

1.0.2 #

  • Fix Dart Analysis

1.0.1 #

  • Fix Dart Analysis

1.0.0 #

  • Initial version, created by luizeof
  • Mautic API Connection Class
  • Support for Basic Authentication
  • Class MauticUser
    • List All Users
    • Get Current User
    • Get User by ID
  • Class MauticContact
    • List All Contacts
    • Get Contact by ID

example/example.dart

import 'package:mautic_api/mautic_api.dart';

void main() async {
  ///
  final api =
      MauticAPI('https://yourmauticaddress.com', 'username', 'password');

  var user = await api.getCurrentUser();

  print(user.id);
  print(user.firstName);
  print(user.lastName);
  print(user.email);
  print(user.onlineStatus);

  print('cached request?: ' + api.isCachedData.toString());
}

Use this package as a library

1. Depend on it

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


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

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

  • Dart: 2.7.1
  • pana: 0.13.5

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
convert ^2.1.1 2.1.1
crypto ^2.1.4 2.1.4
http ^0.12.0+4 0.12.0+4
meta ^1.1.8 1.1.8
Transitive dependencies
async 2.4.0
charcode 1.1.3
collection 1.14.12
http_parser 3.1.3
path 1.6.4
pedantic 1.9.0
source_span 1.6.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6