当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript RestClient.get方法代码示例

本文整理汇总了TypeScript中typed-rest-client/RestClient.RestClient.get方法的典型用法代码示例。如果您正苦于以下问题:TypeScript RestClient.get方法的具体用法?TypeScript RestClient.get怎么用?TypeScript RestClient.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在typed-rest-client/RestClient.RestClient的用法示例。


在下文中一共展示了RestClient.get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
开发者ID:Microsoft,项目名称:vsts-tasks,代码行数:25,代码来源:installer.ts

示例2: 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;
	}
开发者ID:bleissem,项目名称:vsts-tasks,代码行数:35,代码来源:azurermalertrulesrestclient.ts

示例3: 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))
}
开发者ID:OctopusDeploy,项目名称:OctoTFS,代码行数:17,代码来源:connection.ts

示例4: 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;
	}
开发者ID:bleissem,项目名称:vsts-tasks,代码行数:39,代码来源:azurermalertrulesrestclient.ts

示例5: 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;
}
开发者ID:grawcho,项目名称:vso-agent-tasks,代码行数:69,代码来源:azurestackrestutility.ts


注:本文中的typed-rest-client/RestClient.RestClient.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。