clik
Version:
139 lines (81 loc) • 2.86 kB
Markdown
# clik [](https://github.com/lukeed/clik/actions) [](https://codecov.io/gh/lukeed/clik)
> WIP
## Install
```
$ npm install --save clik
```
## Usage
```js
import * as clik from 'clik';
// setup client
const client = clik.setup('<insert apikey secret>', 'ApiKey');
// interact w/ API, passing client
await clik.exists(client, 'foobar');
//=> true | false
await clik.create(client, 'https://...');
//=> { uid: "<generated>", href: "https://...", ... }
await clik.create(client, 'https://...', 'desired');
//=> { uid: "desired", href: "https://...", ... }
await clik.update(client, 'desired', 'https://<new link>');
//=> { uid: "desired", href: "https://<new link>", ... }
const links = await clik.list(client);
//=> [{ uid: "desired", ...}, { uid: "<generated>", ...}]
```
## API
### clik.setup(token, type?)
Returns: `ClikIO.Client`
The HTTP client prepared to interact with the Clik.io API.
#### token
Type: `string`
The value of your `Bearer` or `ApiKey` token.
> **Important:** Keep this value secret!
#### type
Type: `Enum`<br>
Default: `Bearer`<br>
Values: `Bearer` or `ApiKey`
The kind of `token` you are providing.
Please note that `Bearer` tokens have an expiration date, thus making them more secure.<br>
You should use an `ApiKey` token for long-lived — albeit less secure — access.
### clik.exists(client, uid)
Returns: `Promise<boolean>`
Checks if a `ClikIO.Link` already exists using the `uid` value.
#### client
Type: `ClikIO.Client`
The prepared client via [`clik.setup`](#cliksetuptoken-type).
#### uid
Type: `string`
The desired `uid` value to check.
### clik.list(client)
Returns: `Promise<ClikIO.Link[]>`
Returns a list of `ClikIO.Link`s that belong to the authenticated user.
#### client
Type: `ClikIO.Client`
The prepared client via [`clik.setup`](#cliksetuptoken-type).
### clik.create(client, href, uid?)
Returns: `Promise<ClikIO.Link>`
Creates a new `ClikIO.Link` with the target `href` destination.
#### client
Type: `ClikIO.Client`
The prepared client via [`clik.setup`](#cliksetuptoken-type).
#### href
Type: `string`
The target destination.
#### uid
Type: `string`<br>
Optional: `true`
The desired `uid` value to reserve.
> **Note:** When an undefined, a unique `uid` value will be generated.
### clik.update(client, uid, href)
Returns: `Promise<ClikIO.Link>`
Updates the `href` property of an existing `ClikIO.Link` – but *only* if the authenticated user owns it!
#### client
Type: `ClikIO.Client`
The prepared client via [`clik.setup`](#cliksetuptoken-type).
#### uid
Type: `string`
The `uid` value of an existing `ClikIO.Link`.
#### href
Type: `string`
The updated target destination.
## License
MIT © [Luke Edwards](https://lukeed.com)