Skip to content

Commit

Permalink
Some enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
ardalanamini committed Jan 8, 2019
1 parent 9166dbb commit c16b6a2
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 67 deletions.
100 changes: 50 additions & 50 deletions package-lock.json

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

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kutt",
"version": "1.0.1",
"version": "1.0.2",
"description": "Node.js client for Kutt.it url shortener",
"author": "Ardalan Amini <ardalanamini22@gmail.com> [https://github.com/ardalanamini]",
"license": "MIT",
Expand All @@ -19,18 +19,18 @@
],
"main": "dist/index.js",
"scripts": {
"prepublishOnly": "npm run lint && npm run build",
"build": "tsc",
"lint": "tslint -p tsconfig.json -c tslint.json --exclude '**/*.d.ts'"
"lint": "tslint -p tsconfig.json -c tslint.json --exclude '**/*.d.ts'",
"prepublishOnly": "npm run lint && npm run build"
},
"dependencies": {
"axios": "^0.18.0"
},
"devDependencies": {
"@types/axios": "^0.14.0",
"@types/node": "^10.12.6",
"tslint": "^5.11.0",
"tslint-config-airbnb": "^5.11.0",
"typescript": "^3.1.6"
"@types/node": "^10.12.18",
"tslint": "^5.12.0",
"tslint-config-airbnb": "^5.11.1",
"typescript": "^3.2.2"
}
}
20 changes: 10 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Kutt {
*/
public static setDomain = (domain?: string) => CONFIG.DOMAIN = domain;

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

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

const { API, KEY } = this._config;

const request = axios({
method,
data,
baseURL: this._config.API,
baseURL: `${API}/api/url`,
url: path,
headers: {
"X-API-Key": this._config.KEY,
"X-API-Key": KEY,
},
});

if (!callback) {
return request.then(response => response.data);
}
if (!callback) return request.then(response => response.data);

request
.then(response => (callback as any)(null, response.data))
Expand Down Expand Up @@ -147,7 +147,7 @@ class Kutt {
public list(): Promise<Kutt.ListResult>;
public list(callback: Kutt.Callback<Kutt.ListResult>): void;
public list(callback?: Kutt.Callback<Kutt.ListResult>) {
return this._request("get", "/api/url/geturls", callback as any) as any;
return this._request("get", "/geturls", callback as any) as any;
}

/**
Expand All @@ -156,7 +156,7 @@ class Kutt {
public submit(data: Kutt.NewUrl): Promise<Kutt.Url>;
public submit(data: Kutt.NewUrl, callback: Kutt.Callback<Kutt.Url>): void;
public submit(data: Kutt.NewUrl, callback?: Kutt.Callback<Kutt.Url>) {
return this._request("post", "/api/url/submit", data, callback as any) as any;
return this._request("post", "/submit", data, callback as any) as any;
}

/**
Expand All @@ -167,7 +167,7 @@ class Kutt {
public delete(id: string, callback?: Kutt.Callback<Kutt.Url>) {
return this._request(
"post",
"/api/url/deleteurl",
"/deleteurl",
{
id,
domain: this._config.DOMAIN,
Expand All @@ -184,7 +184,7 @@ class Kutt {
public stats(id: string, callback?: Kutt.Callback<Kutt.StatResult>) {
const domain = this._config.DOMAIN;

return this._request("get", `/api/url/stats?id=${id}${domain ? `&domain=${domain}` : ""}`, callback as any) as any;
return this._request("get", `/stats?id=${id}${domain ? `&domain=${domain}` : ""}`, callback as any) as any;
}
}

Expand Down

0 comments on commit c16b6a2

Please sign in to comment.