Skip to content

Commit

Permalink
feat(advanced-http): duplicate methods sync to be able to abort reque…
Browse files Browse the repository at this point in the history
…sts (#3575)

* initial

* finish http-changes
  • Loading branch information
EinfachHans authored Jan 23, 2021
1 parent 182b403 commit 0efa33f
Show file tree
Hide file tree
Showing 2 changed files with 267 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/@ionic-native/core/decorators/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export interface CordovaOptions {
* If the method-name of the cordova plugin is different from the wrappers one, it can be defined here
*/
methodName?: string;

/**
* Set to true if the wrapped method is a sync function
*/
Expand Down
267 changes: 267 additions & 0 deletions src/@ionic-native/plugins/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export interface HTTPResponse {
error?: string;
}

interface AbortedResponse {
aborted: boolean;
}

/**
* @name HTTP
* @description
Expand Down Expand Up @@ -84,6 +88,7 @@ export class HTTP extends IonicNativePlugin {
UNSUPPORTED_URL: number;
NOT_CONNECTED: number;
POST_PROCESSING_FAILED: number;
ABORTED: number;
};

/**
Expand Down Expand Up @@ -230,6 +235,29 @@ export class HTTP extends IonicNativePlugin {
return;
}

/**
* Make a sync POST request
* @param url {string} The url to send the request to
* @param body {Object} The body of the request
* @param headers {Object} The headers to set for this request
* @param success {function} A callback that is called when the request succeed
* @param failure {function} A callback that is called when the request failed
* @returns {string} returns a string that represents the requestId
*/
@Cordova({
methodName: 'post',
sync: true,
})
postSync(
url: string,
body: any,
headers: any,
success: (result: HTTPResponse) => void,
failure: (error: any) => void
): string {
return;
}

/**
* Make a GET request
* @param url {string} The url to send the request to
Expand All @@ -242,6 +270,29 @@ export class HTTP extends IonicNativePlugin {
return;
}

/**
* Make a sync GET request
* @param url {string} The url to send the request to
* @param parameters {Object} Parameters to send with the request
* @param headers {Object} The headers to set for this request
* @param success {function} A callback that is called when the request succeed
* @param failure {function} A callback that is called when the request failed
* @returns {string} returns a string that represents the requestId
*/
@Cordova({
methodName: 'get',
sync: true,
})
getSync(
url: string,
parameters: any,
headers: any,
success: (result: HTTPResponse) => void,
failure: (error: any) => void
): string {
return;
}

/**
* Make a PUT request
* @param url {string} The url to send the request to
Expand All @@ -254,6 +305,29 @@ export class HTTP extends IonicNativePlugin {
return;
}

/**
* Make a sync PUT request
* @param url {string} The url to send the request to
* @param body {Object} The body of the request
* @param headers {Object} The headers to set for this request
* @param success {function} A callback that is called when the request succeed
* @param failure {function} A callback that is called when the request failed
* @returns {string} returns a string that represents the requestId
*/
@Cordova({
methodName: 'put',
sync: true,
})
putSync(
url: string,
body: any,
headers: any,
success: (result: HTTPResponse) => void,
failure: (error: any) => void
): string {
return;
}

/**
* Make a PATCH request
* @param url {string} The url to send the request to
Expand All @@ -266,6 +340,29 @@ export class HTTP extends IonicNativePlugin {
return;
}

/**
* Make a sync PATCH request
* @param url {string} The url to send the request to
* @param body {Object} The body of the request
* @param headers {Object} The headers to set for this request
* @param success {function} A callback that is called when the request succeed
* @param failure {function} A callback that is called when the request failed
* @returns {string} returns a string that represents the requestId
*/
@Cordova({
methodName: 'patch',
sync: true,
})
patchSync(
url: string,
body: any,
headers: any,
success: (result: HTTPResponse) => void,
failure: (error: any) => void
): string {
return;
}

/**
* Make a DELETE request
* @param url {string} The url to send the request to
Expand All @@ -278,6 +375,29 @@ export class HTTP extends IonicNativePlugin {
return;
}

/**
* Make a sync DELETE request
* @param url {string} The url to send the request to
* @param parameters {Object} Parameters to send with the request
* @param headers {Object} The headers to set for this request
* @param success {function} A callback that is called when the request succeed
* @param failure {function} A callback that is called when the request failed
* @returns {string} returns a string that represents the requestId
*/
@Cordova({
methodName: 'delete',
sync: true,
})
deleteSync(
url: string,
parameters: any,
headers: any,
success: (result: HTTPResponse) => void,
failure: (error: any) => void
): string {
return;
}

/**
* Make a HEAD request
* @param url {string} The url to send the request to
Expand All @@ -290,6 +410,29 @@ export class HTTP extends IonicNativePlugin {
return;
}

/**
* Make a sync HEAD request
* @param url {string} The url to send the request to
* @param parameters {Object} Parameters to send with the request
* @param headers {Object} The headers to set for this request
* @param success {function} A callback that is called when the request succeed
* @param failure {function} A callback that is called when the request failed
* @returns {string} returns a string that represents the requestId
*/
@Cordova({
methodName: 'head',
sync: true,
})
headSync(
url: string,
parameters: any,
headers: any,
success: (result: HTTPResponse) => void,
failure: (error: any) => void
): string {
return;
}

/**
* Make an OPTIONS request
* @param url {string} The url to send the request to
Expand All @@ -302,6 +445,29 @@ export class HTTP extends IonicNativePlugin {
return;
}

/**
* Make an sync OPTIONS request
* @param url {string} The url to send the request to
* @param parameters {Object} Parameters to send with the request
* @param headers {Object} The headers to set for this request
* @param success {function} A callback that is called when the request succeed
* @param failure {function} A callback that is called when the request failed
* @returns {string} returns a string that represents the requestId
*/
@Cordova({
methodName: 'options',
sync: true,
})
optionsSync(
url: string,
parameters: any,
headers: any,
success: (result: HTTPResponse) => void,
failure: (error: any) => void
): string {
return;
}

/**
*
* @param url {string} The url to send the request to
Expand All @@ -316,6 +482,33 @@ export class HTTP extends IonicNativePlugin {
return;
}

/**
*
* @param url {string} The url to send the request to
* @param body {Object} The body of the request
* @param headers {Object} The headers to set for this request
* @param filePath {string} The local path(s) of the file(s) to upload
* @param name {string} The name(s) of the parameter to pass the file(s) along as
* @param success {function} A callback that is called when the request succeed
* @param failure {function} A callback that is called when the request failed
* @returns {string} returns a string that represents the requestId
*/
@Cordova({
methodName: 'uploadFile',
sync: true,
})
uploadFileSync(
url: string,
body: any,
headers: any,
filePath: string | string[],
name: string | string[],
success: (result: any) => void,
failure: (error: any) => void
): string {
return;
}

/**
*
* @param url {string} The url to send the request to
Expand All @@ -329,6 +522,31 @@ export class HTTP extends IonicNativePlugin {
return;
}

/**
*
* @param url {string} The url to send the request to
* @param body {Object} The body of the request
* @param headers {Object} The headers to set for this request
* @param filePath {string} The path to download the file to, including the file name.
* @param success {function} A callback that is called when the request succeed
* @param failure {function} A callback that is called when the request failed
* @returns {string} returns a string that represents the requestId
*/
@Cordova({
methodName: 'downloadFile',
sync: true,
})
downloadFileSync(
url: string,
body: any,
headers: any,
filePath: string,
success: (result: any) => void,
failure: (error: any) => void
): string {
return;
}

/**
*
* @param url {string} The url to send the request to
Expand Down Expand Up @@ -362,4 +580,53 @@ export class HTTP extends IonicNativePlugin {
): Promise<HTTPResponse> {
return;
}

/**
*
* @param url {string} The url to send the request to
* @param options {Object} options for individual request
* @param options.method {string} request method
* @param options.data {Object} payload to be send to the server (only applicable on post, put or patch methods)
* @param options.params {Object} query params to be appended to the URL (only applicable on get, head, delete, upload or download methods)
* @param options.serializer {string} data serializer to be used (only applicable on post, put or patch methods), defaults to global serializer value, see setDataSerializer for supported values
* @param options.timeout {number} timeout value for the request in seconds, defaults to global timeout value
* @param options.headers {Object} headers object (key value pair), will be merged with global values
* @param options.filePath {string} file path(s) to be used during upload and download see uploadFile and downloadFile for detailed information
* @param options.name {string} name(s) to be used during upload see uploadFile for detailed information
* @param options.responseType {string} response type, defaults to text
* @param success {function} A callback that is called when the request succeed
* @param failure {function} A callback that is called when the request failed
*
* @returns {string} returns a string that represents the requestId
*/
@Cordova({
methodName: 'sendRequest',
sync: true,
})
sendRequestSync(
url: string,
options: {
method: 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete' | 'options' | 'upload' | 'download';
data?: { [index: string]: any };
params?: { [index: string]: string | number };
serializer?: 'json' | 'urlencoded' | 'utf8' | 'multipart';
timeout?: number;
headers?: { [index: string]: string };
filePath?: string | string[];
name?: string | string[];
responseType?: 'text' | 'arraybuffer' | 'blob' | 'json';
},
success: (result: HTTPResponse) => void,
failure: (error: any) => void
): string {
return;
}

/**
* @param requestId {string} The RequestId of the request to abort
*/
@Cordova()
abort(requestId: string): Promise<AbortedResponse> {
return;
}
}

0 comments on commit 0efa33f

Please sign in to comment.