Prevent comment spam using Akismet service, in Dart. https://dev.belin.io/akismet.dart
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Cédric Belin b14eb8fbf2 Disabled the container-based builds 1 week ago
.vscode Added VSCode editor settings 1 month ago
doc Updated the documentation 1 week ago
example Updated the Coveralls dependency 1 week ago
lib Fixed regressions 1 month ago
test Fixed the unit tests 1 month ago
tool Updated the Coveralls dependency 1 week ago
var Initial commit 2 years ago
.editorconfig Updated a link 3 months ago
.gitattributes Code optimization 9 months ago
.gitignore Code formatting 1 month ago
.travis.yml Disabled the container-based builds 1 week ago
AUTHORS.txt Added the legal files 2 years ago
CHANGELOG.md Updated a link 3 weeks ago
LICENSE.md Updated the license 10 months ago
README.md Updated the documentation 1 week ago
analysis_options.yaml Updated the dependencies 3 weeks ago
dart_test.yaml Updated the test browser 3 months ago
mkdocs.yml Disabled the edit link 3 weeks ago
pubspec.yaml Updated the Coveralls dependency 1 week ago

README.md

Akismet for Dart

Runtime Release License Coverage Build

Prevent comment spam using the Akismet service, in Dart.

Documentation

Development

Features

  • Key verification: checks an Akismet API key and gets a value indicating whether it is valid.
  • Comment check: checks a comment and gets a value indicating whether it is spam.
  • Submit spam: submits a comment that was not marked as spam but should have been.
  • Submit ham: submits a comment that was incorrectly marked as spam but should not have been.

Usage

Key verification

try {
  final client = Client('123YourAPIKey', Blog(Uri.https('www.yourblog.com', '/')));
  final isValid = await client.verifyKey();
  print(isValid ? 'The API key is valid' : 'The API key is invalid');
}

on ClientException catch (err) {
  print('An error occurred: ${err.message}');
}

Comment check

try {
  final comment = Comment(
    Author('127.0.0.1', 'Mozilla/5.0'),
    content: 'A user comment',
    date: DateTime.now()
  );

  final isSpam = await client.checkComment(comment);
  print(isSpam ? 'The comment is spam' : 'The comment is ham');
}

on ClientException catch (err) {
  print('An error occurred: ${err.message}');
}

Submit spam / ham

try {
  await client.submitSpam(comment);
  print('Spam submitted');

  await client.submitHam(comment);
  print('Ham submitted');
}

on ClientException catch (err) {
  print('An error occurred: ${err.message}');
}

Events

The Client class triggers some events during its life cycle:

  • request : emitted every time a request is made to the remote service.
  • response : emitted every time a response is received from the remote service.

These events are exposed as Stream<RequestEvent>, you can listen to them using the on<EventName> properties:

client.onRequest.listen(
  (event) => print('Client request: ${event.request.url}')
);

client.onResponse.listen(
  (event) => print('Server response: ${event.response.statusCode}')
);

Unit tests

In order to run the tests, you must set the AKISMET_API_KEY environment variable to the value of your Akismet API key:

export AKISMET_API_KEY="<123YourAPIKey>"

Then, you can run the test script from the command prompt:

pub run test

License

Akismet for Dart is distributed under the MIT License.