Added content type to status report requests.
This commit is contained in:
Родитель
7c4e1bde43
Коммит
87b2ec72f8
|
@ -10,7 +10,8 @@
|
|||
|
||||
"use strict";
|
||||
var HttpRequester = (function () {
|
||||
function HttpRequester() {
|
||||
function HttpRequester(contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
HttpRequester.prototype.request = function (verb, url, callbackOrRequestBody, callback) {
|
||||
var requestBody;
|
||||
|
@ -30,6 +31,9 @@ var HttpRequester = (function () {
|
|||
}
|
||||
};
|
||||
xhr.open(methodName, url, true);
|
||||
if (this.contentType) {
|
||||
xhr.setRequestHeader("Content-Type", this.contentType);
|
||||
}
|
||||
xhr.send(requestBody);
|
||||
};
|
||||
HttpRequester.prototype.getHttpMethodName = function (verb) {
|
||||
|
|
|
@ -14,17 +14,18 @@ var HttpRequester = require("./httpRequester");
|
|||
var Sdk = (function () {
|
||||
function Sdk() {
|
||||
}
|
||||
Sdk.getAcquisitionManager = function (callback, userDeploymentKey) {
|
||||
Sdk.getAcquisitionManager = function (callback, userDeploymentKey, contentType) {
|
||||
var resolveManager = function (defaultInstance) {
|
||||
if (userDeploymentKey) {
|
||||
if (userDeploymentKey || contentType) {
|
||||
var customConfiguration = {
|
||||
deploymentKey: userDeploymentKey,
|
||||
deploymentKey: (userDeploymentKey ? userDeploymentKey : Sdk.DefaultConfiguration.deploymentKey),
|
||||
serverUrl: Sdk.DefaultConfiguration.serverUrl,
|
||||
ignoreAppVersion: Sdk.DefaultConfiguration.ignoreAppVersion,
|
||||
appVersion: Sdk.DefaultConfiguration.appVersion,
|
||||
clientUniqueId: Sdk.DefaultConfiguration.clientUniqueId
|
||||
};
|
||||
var customAcquisitionManager = new AcquisitionManager(new HttpRequester(), customConfiguration);
|
||||
var requester = new HttpRequester(contentType);
|
||||
var customAcquisitionManager = new AcquisitionManager(requester, customConfiguration);
|
||||
callback(null, customAcquisitionManager);
|
||||
}
|
||||
else {
|
||||
|
@ -66,7 +67,7 @@ var Sdk = (function () {
|
|||
else {
|
||||
acquisitionManager.reportStatusDeploy(pkg, status, callback);
|
||||
}
|
||||
}, deploymentKey);
|
||||
}, deploymentKey, "application/json");
|
||||
}
|
||||
catch (e) {
|
||||
callback && callback(new Error("An error occured while reporting the deployment status. " + e), null);
|
||||
|
@ -81,7 +82,7 @@ var Sdk = (function () {
|
|||
else {
|
||||
acquisitionManager.reportStatusDownload(pkg, callback);
|
||||
}
|
||||
}, deploymentKey);
|
||||
}, deploymentKey, "application/json");
|
||||
}
|
||||
catch (e) {
|
||||
callback && callback(new Error("An error occured while reporting the download status. " + e), null);
|
||||
|
|
|
@ -6,6 +6,13 @@
|
|||
* XMLHttpRequest-based implementation of Http.Requester.
|
||||
*/
|
||||
class HttpRequester implements Http.Requester {
|
||||
|
||||
private contentType: string;
|
||||
|
||||
constructor(contentType?: string) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
public request(verb: Http.Verb, url: string, callbackOrRequestBody: Callback<Http.Response> | string, callback?: Callback<Http.Response>): void {
|
||||
var requestBody: string;
|
||||
var requestCallback: Callback<Http.Response> = callback;
|
||||
|
@ -27,6 +34,9 @@ class HttpRequester implements Http.Requester {
|
|||
}
|
||||
};
|
||||
xhr.open(methodName, url, true);
|
||||
if (this.contentType) {
|
||||
xhr.setRequestHeader("Content-Type", this.contentType);
|
||||
}
|
||||
xhr.send(requestBody);
|
||||
}
|
||||
|
||||
|
|
13
www/sdk.ts
13
www/sdk.ts
|
@ -18,18 +18,19 @@ class Sdk {
|
|||
/**
|
||||
* Reads the CodePush configuration and creates an AcquisitionManager instance using it.
|
||||
*/
|
||||
public static getAcquisitionManager(callback: Callback<AcquisitionManager>, userDeploymentKey?: string): void {
|
||||
public static getAcquisitionManager(callback: Callback<AcquisitionManager>, userDeploymentKey?: string, contentType?: string): void {
|
||||
|
||||
var resolveManager = (defaultInstance: AcquisitionManager): void => {
|
||||
if (userDeploymentKey) {
|
||||
if (userDeploymentKey || contentType) {
|
||||
var customConfiguration: Configuration = {
|
||||
deploymentKey: userDeploymentKey,
|
||||
deploymentKey: (userDeploymentKey ? userDeploymentKey : Sdk.DefaultConfiguration.deploymentKey),
|
||||
serverUrl: Sdk.DefaultConfiguration.serverUrl,
|
||||
ignoreAppVersion: Sdk.DefaultConfiguration.ignoreAppVersion,
|
||||
appVersion: Sdk.DefaultConfiguration.appVersion,
|
||||
clientUniqueId: Sdk.DefaultConfiguration.clientUniqueId
|
||||
};
|
||||
var customAcquisitionManager: AcquisitionManager = new AcquisitionManager(new HttpRequester(), customConfiguration);
|
||||
var requester = new HttpRequester(contentType);
|
||||
var customAcquisitionManager: AcquisitionManager = new AcquisitionManager(requester, customConfiguration);
|
||||
callback(null, customAcquisitionManager);
|
||||
} else {
|
||||
callback(null, Sdk.DefaultAcquisitionManager);
|
||||
|
@ -73,7 +74,7 @@ class Sdk {
|
|||
else {
|
||||
acquisitionManager.reportStatusDeploy(pkg, status, callback);
|
||||
}
|
||||
}, deploymentKey);
|
||||
}, deploymentKey, "application/json");
|
||||
} catch (e) {
|
||||
callback && callback(new Error("An error occured while reporting the deployment status. " + e), null);
|
||||
}
|
||||
|
@ -91,7 +92,7 @@ class Sdk {
|
|||
else {
|
||||
acquisitionManager.reportStatusDownload(pkg, callback);
|
||||
}
|
||||
}, deploymentKey);
|
||||
}, deploymentKey, "application/json");
|
||||
} catch (e) {
|
||||
callback && callback(new Error("An error occured while reporting the download status. " + e), null);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче