Skip to content

Commit

Permalink
finish docs
Browse files Browse the repository at this point in the history
  • Loading branch information
regevbr committed May 31, 2019
1 parent cfd4d05 commit 88013e1
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 9 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## Development
- nothing yet

## v0.0.4
## v0.1.0

[diff](https://github.com/PruvoNet/squiss-ts/compare/v0.0.3...v0.0.4)
[diff](https://github.com/PruvoNet/squiss-ts/compare/v0.0.3...v0.1.0)

### Fixed

- Reduced `request-promise` min version
- Finished documentation
- Finished unit tests

### Added

- More strict typings for the timing object
- Helper methods to easily reference plugin names

## v0.0.3

Expand Down
123 changes: 117 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ npm install cronicle-client
`request-promise` is a peer dependency and must be installed by you (>=1.0.0)

--NOTICE--
If you want to use the timing objects helpers, you must also install `moment`
If you want to use the timing utils, you must also install `moment`

## Quick example

Expand Down Expand Up @@ -74,12 +74,12 @@ scheduler.createEvent({
import { CronicleClient, IHttpPluginData, IShellPluginData, ITestPluginData, NumberedBoolean,
getUtcTiming, IPluginNames } from 'cronicle-client';

export interface ICustomPluginData {
interface ICustomPluginData {
duration: string;
action: string;
}

export interface Plugins {
interface Plugins {
// Default plugins
urlplug: IHttpPluginData;
shellplug: IShellPluginData;
Expand All @@ -88,15 +88,15 @@ export interface Plugins {
mycustomplug: ICustomPluginData;
}

export enum Categories {
enum Categories {
// Default category
GENERAL = 'general',
// Custom categories...
TEST_CATEGORY = 'cjw6g085901',
TEST_CATEGORY2 = 'cjw6l8mnb02',
}

export enum Targets {
enum Targets {
// Default targets...
ALL = 'allgrp',
MAIN = 'maingrp',
Expand Down Expand Up @@ -143,7 +143,118 @@ scheduler.createEvent({

For all api endpoints documentations, please refer to [Cronicle api reference](https://github.com/jhuckaby/Cronicle#api-reference)

TBD
### createEvent

When creating an event, there is no unique restriction on the title.
While searching for an event using `getEvent`, the
api allows you to search by title, which is great, bus as of now (cronicle v0.89) it will return a single result.
This imposes an issue when you don't enforce a unique title since you will get a random result (see [#186](https://github.com/jhuckaby/Cronicle/issues/186))
Until this behaviour is fixed, you can tell the `createEvent` method to enforce title uniquness and it will fail if an event with the provided title already exists.

### Constructor

#### Options

| Parameter Name | Description |
|----------------|-------------|
| `masterUrl` | The full url to the master Cronicle server
| `apiKey` | The api key to use (make sure it has relevant permissions enabled)
| `apiVersion` | (Optional) override the default api version (`v1`)

#### Typings

The client can enforce the proper usage of categories, targets and plugins (with their required parameters).
This is done using optional generics:

| Generics Parameter Name | Description |
|--------------------------|-------------|
| `Categories` | Enum containing the ids of the categories available at you Cronicle server (Defaults to `BaseCategories`)
| `Targets` | Enum containing the ids of the targets available at you Cronicle server (Defaults to `BaseTargets`)
| `Plugins` | Interface containing mapping between plugin ids and the interface representing their required event params (Defaults to `IBasePlugins`)

#### Examples

Example constructor with defaults:
```typescript
const scheduler = new CronicleClient({
masterUrl: 'http://localhost:3012',
apiKey: '<your api key>',
});
```

Example for setting the categories your server supports:
```typescript
enum Categories {
// Default category
GENERAL = 'general',
// Custom categories...
TEST_CATEGORY = 'cjw6g085901',
TEST_CATEGORY2 = 'cjw6l8mnb02',
}
```

Example for setting the targets your server supports:
```typescript
enum Targets {
// Default targets...
ALL = 'allgrp',
MAIN = 'maingrp',
// Custom targets...
AWS = 'awsgrp',
GCP = 'gcpgrp',
}
```

Example for setting the plugins your server supports:
```typescript
interface ICustomPluginData {
duration: string;
action: string;
}

interface Plugins {
// Default plugins
urlplug: IHttpPluginData;
shellplug: IShellPluginData;
testplug: ITestPluginData;
// Custom plugins
mycustomplug: ICustomPluginData;
}
```

Example constructor with overrides:
```typescript
const scheduler = new CronicleClient<Categories, Targets, Plugins>({
masterUrl: 'http://localhost:3012',
apiKey: '<your api key>',
});
```

### Timing utils

To support a wide variety of scheduling, the [timing object](https://github.com/jhuckaby/Cronicle#event-timing-object)
an be very cumbersome...
To make life easier (at least when you just want to schedule an event for a single future run) you can use the
`getTiming` and `getUtcTiming` methods:

--NOTICE--
If you want to use the timing utils, you MUST `npm install --save moment`

Running:
```typescript
getUtcTiming(moment.utc('2016-05-26T14:50:50.900Z');
```
Will produce:
```json
{
years: [ 2016 ],
months: [ 5 ],
days: [ 26 ],
hours: [ 14 ],
minutes: [ 50 ],
}
```
## Versions
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cronicle-client",
"version": "0.0.4",
"version": "0.1.0",
"description": "Light Cronicle node client with full TypeScript support",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down

0 comments on commit 88013e1

Please sign in to comment.