本文整理匯總了TypeScript中typed-rest-client/RestClient.RestClient類的典型用法代碼示例。如果您正苦於以下問題:TypeScript RestClient類的具體用法?TypeScript RestClient怎麽用?TypeScript RestClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了RestClient類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: queryLatestMatch
async function queryLatestMatch(versionSpec: string): Promise<string> {
// node offers a json list of versions
let dataFileName: string;
switch (osPlat) {
case "linux": dataFileName = "linux-" + osArch; break;
case "darwin": dataFileName = "osx-" + osArch + '-tar'; break;
case "win32": dataFileName = "win-" + osArch + '-exe'; break;
default: throw new Error(`Unexpected OS '${osPlat}'`);
}
let versions: string[] = [];
let dataUrl = "https://nodejs.org/dist/index.json";
let rest: restm.RestClient = new restm.RestClient('vsts-node-tool');
let nodeVersions: INodeVersion[] = (await rest.get<INodeVersion[]>(dataUrl)).result;
nodeVersions.forEach((nodeVersion:INodeVersion) => {
// ensure this version supports your os and platform
if (nodeVersion.files.indexOf(dataFileName) >= 0) {
versions.push(nodeVersion.version);
}
});
// get the latest version that matches the version spec
let version: string = toolLib.evaluateVersions(versions, versionSpec);
return version;
}
示例2: fetchProjectName
export function fetchProjectName(details: OctoServerConnectionDetails, projectId: string){
console.log("Ignore SSL: " + details.ignoreSslErrors);
const client = new RestClient(
"OctoTFS",
details.url,
[new OctoApiKeyHandler(details.apiKey)],
{ignoreSslError: details.ignoreSslErrors});
return client.get<{Name: string}>(`api/projects/${projectId}`)
.then(x => {
if(x.result){
return either.right<string, string>(x.result.Name);
}
return either.left<string,string>(`Could not resolve project name given id "${projectId}". Server returned status code: ${x.statusCode}`);
}
).catch(error => either.left<string,string>(error))
}
示例3: getAzureRmAlertRule
public async getAzureRmAlertRule(
resourceGroupName: string,
alertRuleName: string) : Promise<any> {
let deferred: Q.Deferred<any> = Q.defer<any>();
tl.debug(`Getting AzureRm alert rule - '${alertRuleName}' in resource group '${resourceGroupName}'`);
let accessToken: string = await this._authorizationClient.getBearerToken();
let apiVersion: string = "2016-03-01";
let restUrl: string = `${this._endpoint.url}subscriptions/${this._endpoint.subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.insights/alertrules/${alertRuleName}?api-version=${apiVersion}`;
let restOptions: IRequestOptions = {
additionalHeaders: {
"Authorization": "Bearer " + accessToken
}
};
tl.debug(`Requesting : ${restUrl}`);
this._restClient.get(restUrl, restOptions)
.then((response: IRestResponse<any>) => {
if(response.statusCode === 200) {
deferred.resolve(response.result);
}
else {
tl.debug(`Getting AzureRm alert '${alertRuleName}' failed. Response : \n${JSON.stringify(response, null, 2)}`);
deferred.reject(response.statusCode);
}
}, (error) => {
deferred.reject(error);
}
);
return deferred.promise;
}
示例4: addOrUpdateAzureMetricAlertRule
public async addOrUpdateAzureMetricAlertRule(
resourceGroupName: string,
resourceUri: string,
rule: IAzureMetricAlertRule,
notifyServiceOwners: boolean,
notifyEmails: string) : Promise<IRestResponse<any>> {
let deferred: Q.Deferred<IRestResponse<any>> = Q.defer<IRestResponse<any>>();
let requestBody: IAzureMetricAlertRequestBody = await this._getRequestBodyForAddingAlertRule(resourceGroupName, resourceUri, rule, notifyServiceOwners, notifyEmails);
tl.debug(`Sending PUT request with request body \n${JSON.stringify(requestBody, null, 2)}`);
let accessToken: string = await this._authorizationClient.getBearerToken();
let apiVersion = "2016-03-01";
let restUrl = `${this._endpoint.url}subscriptions/${this._endpoint.subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.insights/alertrules/${rule.alertName}?api-version=${apiVersion}`;
let restOptions: IRequestOptions = {
additionalHeaders: {
"Authorization": "Bearer " + accessToken
}
};
tl.debug(`Requesting : ${restUrl}`);
this._restClient.replace(restUrl, requestBody, restOptions)
.then((response: IRestResponse<any>) => {
if(response.statusCode === 200 || response.statusCode === 201) {
deferred.resolve(response);
}
else {
tl.debug(`Updating the rule ${rule.alertName} failed. Response: \n${JSON.stringify(response, null, 2)}`);
deferred.reject(response.statusCode);
}
}, (error) => {
deferred.reject(error);
}
);
return deferred.promise;
}
示例5: getAzureRmResourceDetails
public async getAzureRmResourceDetails(
resourceUri: string) : Promise<any> {
let deferred: Q.Deferred<any> = Q.defer<any>();
let splittedResourceUri: string[] = resourceUri.split("/");
let resourceGroupName: string = splittedResourceUri[4];
let resourceType: string = splittedResourceUri[6] + "/" + splittedResourceUri[7];
let resourceName: string = splittedResourceUri[8];
tl.debug(`Getting AzureRm resource details - '${resourceName}' in resource group '${resourceGroupName}'`);
let accessToken: string = await this._authorizationClient.getBearerToken();
let apiVersion = "2017-05-10";
let restUrl = `${this._endpoint.url}subscriptions/${this._endpoint.subscriptionId}/resourceGroups/${resourceGroupName}/resources?$filter=resourceType EQ '${resourceType}' AND name EQ '${resourceName}'&api-version=${apiVersion}`;
let restOptions: IRequestOptions = {
additionalHeaders: {
"Authorization": "Bearer " + accessToken
}
};
tl.debug(`Requesting : ${restUrl}`);
this._restClient.get(restUrl, restOptions)
.then((response: IRestResponse<any>) => {
if(response.statusCode === 200) {
deferred.resolve(response.result["value"][0]);
}
else {
tl.debug(`Getting AzureRm resource '${resourceName}' failed. Response: ${JSON.stringify(response, null, 2)}`);
deferred.reject(response.statusCode);
}
}, (error) => {
deferred.reject(error);
}
);
return deferred.promise;
}
示例6: initializeAzureStackData
export async function initializeAzureStackData(endpoint): Promise<any>
{
var deferred = Q.defer<any>();
var headers = {
'Content-Type': 'application/json'
};
var azureStackDependencyDataUrl = endpoint.url + "/metadata/endpoints?api-version=2015-01-01"
let options: rm.IRequestOptions = {};
options.additionalHeaders = headers;
let promise: Promise<any> = rc.get(azureStackDependencyDataUrl, options);
promise.then((response) => {
if(response.statusCode === 200) {
let result = response.result;
var authenticationData = result.authentication;
if(authenticationData) {
var loginEndpoint = authenticationData.loginEndpoint;
if(loginEndpoint) {
loginEndpoint += (loginEndpoint.lastIndexOf("/") == loginEndpoint.length - 1) ? "" : "/";
endpoint['activeDirectoryAuthority'] = loginEndpoint;
endpoint['environmentAuthorityUrl'] = loginEndpoint;
}
var audiences = authenticationData.audiences;
if(audiences) {
if(audiences.length > 0) {
endpoint['activeDirectoryServiceEndpointResourceId'] = audiences[0];
}
}
}
if(result.graphEndpoint) {
endpoint['graphUrl'] = result.graphEndpoint;
}
if(result.galleryUrl) {
endpoint['galleryUrl'] = result.galleryUrl;
}
if(result.portalEndpoint) {
endpoint['portalEndpoint'] = result.portalEndpoint;
}
var endpointUrl = endpoint.url;
endpointUrl += (endpointUrl.lastIndexOf("/") == endpointUrl.length-1) ? "":"/";
var domain = "";
try {
var index = endpointUrl.indexOf('.');
domain = endpointUrl.substring(index+1);
domain = (domain.lastIndexOf("/") == domain.length-1) ? domain.substring(0, domain.length-1): domain;
} catch(error) {
deferred.reject(tl.loc("SpecifiedAzureRmEndpointIsInvalid", endpointUrl));
}
endpoint['azureKeyVaultDnsSuffix'] = ("vault." + domain).toLowerCase();
endpoint['azureKeyVaultServiceEndpointResourceId'] = ("https://vault." + domain).toLowerCase();
deferred.resolve(endpoint);
}
else {
tl.debug("Action: initializeAzureStackData, Response: " + JSON.stringify(response));
deferred.reject(tl.loc("FailedToFetchAzureStackDependencyData", response.statusCode));
}
},
(error) => {
deferred.reject(error);
});
return deferred.promise;
}