本文整理汇总了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;
}