Skip to content

Commit

Permalink
Closes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
ardalanamini committed Feb 9, 2019
1 parent 8226137 commit 1e550d5
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 14 deletions.
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ Node.js client for Kutt.it url shortener
- [setAPI](#setapi)
- [setKey](#setkey)
- [setDomain](#setdomain)
- [setTimeout](#settimeout)
- [Instance](#instance)
- [setAPI](#setapi-1)
- [setKey](#setkey-1)
- [setDomain](#setdomain-1)
- [setTimeout](#settimeout-1)
- [list](#list)
- [submit](#submit)
- [delete](#delete)
Expand Down Expand Up @@ -79,7 +81,15 @@ Kutt.setKey(key: string): string;
Set global custom domain

```typescript
Kutt.setDomain(domain: string): string;
Kutt.setDomain(domain?: string): string;
```

#### setTimeout

Set global timeout

```typescript
Kutt.setTimeout(timeout: number): timeout;
```

### Instance
Expand Down Expand Up @@ -109,7 +119,15 @@ kutt.setKey(key: string): this;
Set instance's custom domain

```typescript
kutt.setDomain(domain: string): this;
kutt.setDomain(domain?: string): this;
```

#### setTimeout

Set instance's timeout

```typescript
kutt.setTimeout(timeout: number): this;
```

#### list
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kutt",
"version": "1.0.3",
"version": "1.1.0",
"description": "Node.js client for Kutt.it url shortener",
"author": "Ardalan Amini <[email protected]> [https://ardalanamini.com]",
"license": "MIT",
Expand Down Expand Up @@ -28,10 +28,10 @@
},
"devDependencies": {
"@types/axios": "^0.14.0",
"@types/node": "^10.12.21",
"@types/node": "^10.12.24",
"axios": "^0.18.0",
"tslint": "^5.12.1",
"tslint-config-airbnb": "^5.11.1",
"typescript": "^3.3.1"
"typescript": "^3.3.3"
}
}
18 changes: 17 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const CONFIG = {
API: "https://kutt.it",
KEY: "",
DOMAIN: undefined as string | undefined,
TIMEOUT: 1E4, // 10 seconds by default
};

namespace Kutt {
Expand Down Expand Up @@ -84,6 +85,11 @@ class Kutt {
*/
public static setDomain = (domain?: string) => CONFIG.DOMAIN = domain;

/**
* Sets global timeout
*/
public static setTimeout = (timeout: number) => CONFIG.TIMEOUT = timeout;

protected _config = Object.assign({}, CONFIG);

protected _request(method: string, path: string, callback: Kutt.Callback<any>): void;
Expand All @@ -95,13 +101,14 @@ class Kutt {
data = undefined;
}

const { API, KEY } = this._config;
const { API, KEY, TIMEOUT } = this._config;

const request = axios({
method,
data,
baseURL: `${API}/api/url`,
url: path,
timeout: TIMEOUT,
headers: {
"X-API-Key": KEY,
},
Expand Down Expand Up @@ -141,6 +148,15 @@ class Kutt {
return this;
}

/**
* Sets instance's timeout
*/
public setTimeout(timeout: number) {
this._config.TIMEOUT = timeout;

return this;
}

/**
* Retrieves the short urls
*/
Expand Down

0 comments on commit 1e550d5

Please sign in to comment.