Skip to content

Commit

Permalink
Updated the documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
cedx committed Sep 7, 2017
1 parent b1d0f99 commit af9ed7c
Showing 1 changed file with 33 additions and 20 deletions.
53 changes: 33 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,57 @@ $ npm install --save @cedx/akismet
```

## Usage
This package has an API based on [Observables](http://reactivex.io/intro.html).

### Key verification

```javascript
const {Client} = require('@cedx/akismet');

let client = new Client('YourAPIKey', 'http://your.blog.url');
client.verifyKey().subscribe(isValid =>
console.log(isValid ? 'Your API key is valid.' : 'Your API key is invalid.')
);
try {
let client = new Client('YourAPIKey', 'http://your.blog.url');
let isValid = await client.verifyKey();
console.log(isValid ? 'Your API key is valid.' : 'Your API key is invalid.');
}

catch (error) {
console.log(`An error occurred: ${error}`);
}
```

### Comment check

```javascript
const {Author, Comment} = require('@cedx/akismet');

let comment = new Comment(
new Author('127.0.0.1', 'Mozilla/5.0'),
'A comment.'
);

client.checkComment(comment).subscribe(isSpam =>
console.log(isSpam ? 'The comment is marked as spam.' : 'The comment is marked as ham.')
);
try {
let comment = new Comment(
new Author('127.0.0.1', 'Mozilla/5.0'),
'A comment.'
);

let isSpam = await client.checkComment(comment);
console.log(isSpam ? 'The comment is marked as spam.' : 'The comment is marked as ham.');
}

catch (error) {
console.log(`An error occurred: ${error}`);
}
```

### Submit spam/ham

```javascript
client.submitSpam(comment).subscribe(() =>
console.log('Spam submitted.')
);

client.submitHam(comment).subscribe(() =>
console.log('Ham submitted.')
);
try {
await client.submitSpam(comment);
console.log('Spam submitted.');

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

catch (error) {
console.log(`An error occurred: ${error}`);
}
```

## Events
Expand Down

0 comments on commit af9ed7c

Please sign in to comment.