Comparing version 10.0.0-beta.18 to 10.0.0-beta.19
@@ -12,5 +12,9 @@ import { CategoryCode, EndpointDescription, HistoricalFilter, News, RestResponse, RestResponseError, RestResponseSuccess, SourceDetails } from "./types"; | ||
get<T>(path: string, params?: any, errorHandler?: (apiResponse: RestResponseError<T>) => void): Promise<RestResponse<T>>; | ||
delete<T>(path: string, params?: any, errorHandler?: (apiResponse: RestResponseError<T>) => void): Promise<RestResponse<T>>; | ||
post<T, Z>(path: string, body: T, errorHandler?: (apiResponse: RestResponseError<Z>) => void): Promise<RestResponseSuccess<Z>>; | ||
put<T, Z>(path: string, body: T, errorHandler?: (apiResponse: RestResponseError<Z>) => void): Promise<RestResponseSuccess<Z>>; | ||
request<T>(method: string, path: string, params?: any, errorHandler?: (apiResponse: RestResponseError<T>) => void): Promise<RestResponse<T>>; | ||
private requestWithBody; | ||
handle<T>(res: Response, handleError: (apiResponse: RestResponseError<T>) => void): Promise<RestResponse<T>>; | ||
handleError<T>(apiResponse: RestResponseError<T>): Promise<void>; | ||
} |
@@ -49,2 +49,22 @@ "use strict"; | ||
get(path, params, errorHandler = this.handleError) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.request("GET", path, params, errorHandler); | ||
}); | ||
} | ||
delete(path, params, errorHandler = this.handleError) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.request("DELETE", path, params, errorHandler); | ||
}); | ||
} | ||
post(path, body, errorHandler = this.handleError) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.requestWithBody("POST", path, body, errorHandler); | ||
}); | ||
} | ||
put(path, body, errorHandler = this.handleError) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.requestWithBody("PUT", path, body, errorHandler); | ||
}); | ||
} | ||
request(method, path, params, errorHandler = this.handleError) { | ||
var _a, _b; | ||
@@ -55,3 +75,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
const res = yield (0, isomorphic_fetch_1.default)(endpoint, { | ||
method: "GET", | ||
method: method, | ||
headers: { | ||
@@ -72,3 +92,3 @@ 'content-type': 'application/json', | ||
} | ||
post(path, body, errorHandler = this.handleError) { | ||
requestWithBody(method, path, body, errorHandler = this.handleError) { | ||
var _a, _b; | ||
@@ -78,3 +98,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
const res = yield (0, isomorphic_fetch_1.default)(this.restEndpoint + path, { | ||
method: "POST", | ||
method: method, | ||
body: JSON.stringify(body), | ||
@@ -81,0 +101,0 @@ headers: { |
{ | ||
"name": "newsware", | ||
"version": "10.0.0-beta.18", | ||
"version": "10.0.0-beta.19", | ||
"description": "Typescript client for interacting with the Newsware API", | ||
@@ -5,0 +5,0 @@ "main": "lib/src/index.js", |
@@ -51,6 +51,39 @@ import { | ||
): Promise<RestResponse<T>> { | ||
return await this.request("GET", path, params, errorHandler) | ||
} | ||
async delete<T>( | ||
path: string, | ||
params?: any, | ||
errorHandler: (apiResponse: RestResponseError<T>) => void = this.handleError | ||
): Promise<RestResponse<T>> { | ||
return await this.request("DELETE", path, params, errorHandler) | ||
} | ||
async post<T, Z>( | ||
path: string, | ||
body: T, | ||
errorHandler: (apiResponse: RestResponseError<Z>) => void = this.handleError | ||
): Promise<RestResponseSuccess<Z>> { | ||
return await this.requestWithBody("POST", path, body, errorHandler) | ||
} | ||
async put<T, Z>( | ||
path: string, | ||
body: T, | ||
errorHandler: (apiResponse: RestResponseError<Z>) => void = this.handleError | ||
): Promise<RestResponseSuccess<Z>> { | ||
return await this.requestWithBody("PUT", path, body, errorHandler) | ||
} | ||
async request<T>( | ||
method: string, | ||
path: string, | ||
params?: any, | ||
errorHandler: (apiResponse: RestResponseError<T>) => void = this.handleError | ||
): Promise<RestResponse<T>> { | ||
try { | ||
const endpoint = this.restEndpoint + path + (params ? "?" + new URLSearchParams(params) : '') | ||
const res = await fetch(endpoint, { | ||
method: "GET", | ||
method: method, | ||
headers: { | ||
@@ -71,3 +104,4 @@ 'content-type': 'application/json', | ||
async post<T, Z>( | ||
private async requestWithBody<T, Z>( | ||
method: string, | ||
path: string, | ||
@@ -79,3 +113,3 @@ body: T, | ||
const res = await fetch(this.restEndpoint + path, { | ||
method: "POST", | ||
method: method, | ||
body: JSON.stringify(body), | ||
@@ -82,0 +116,0 @@ headers: { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
98595
1958