Skip to content

Commit b9cecf3

Browse files
delete internal http and rest client
1 parent d42dd40 commit b9cecf3

10 files changed

Lines changed: 66 additions & 1021 deletions

File tree

api/ClientApiBases.ts

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Microsoft. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
import restm = require('./RestClient');
5-
import httpm = require('./HttpClient');
64
import vsom = require('./VsoClient');
75
import VsoBaseInterfaces = require('./interfaces/common/VsoBaseInterfaces');
86
import serm = require('./Serialization');
@@ -15,11 +13,6 @@ export class ClientApiBase {
1513
http: hm.HttpClient;
1614
rest: rm.RestClient;
1715

18-
// TODO: delete these three after regen
19-
httpClient: httpm.HttpCallbackClient;
20-
restCallbackClient: restm.RestCallbackClient;
21-
restClient: restm.RestClient;
22-
2316
vsoClient: vsom.VsoClient;
2417

2518
constructor(baseUrl: string, handlers: VsoBaseInterfaces.IRequestHandler[], userAgent?: string);
@@ -30,36 +23,12 @@ export class ClientApiBase {
3023
this.http = new hm.HttpClient(userAgent, handlers);
3124
this.rest = new rm.RestClient(userAgent, null, handlers);
3225

33-
// TODO: delete these three after regen
34-
this.httpClient = new httpm.HttpCallbackClient(userAgent, handlers);
35-
this.restCallbackClient = new restm.RestCallbackClient(this.httpClient);
36-
this.restClient = new restm.RestClient(userAgent, handlers);
37-
38-
this.vsoClient = new vsom.VsoClient(baseUrl, this.restCallbackClient);
39-
this.userAgent = userAgent;
40-
}
41-
42-
setUserAgent(userAgent: string) {
26+
this.vsoClient = new vsom.VsoClient(baseUrl, this.rest);
4327
this.userAgent = userAgent;
44-
this.httpClient.userAgent = userAgent;
45-
}
46-
47-
public connect(): Promise<any> {
48-
return new Promise((resolve, reject) => {
49-
this.restCallbackClient.get(this.vsoClient.resolveUrl('/_apis/connectionData'), "", (err: any, statusCode: number, obj: any) => {
50-
if (err) {
51-
err.statusCode = statusCode;
52-
reject(err);
53-
}
54-
else {
55-
resolve(obj);
56-
}
57-
}, null);
58-
});
5928
}
6029

6130
public createAcceptHeader(type: string, apiVersion?: string): string {
62-
return this.restCallbackClient.createAcceptHeader(type, apiVersion);
31+
return type + (apiVersion ? (';api-version=' + apiVersion) : '');
6332
}
6433

6534
public createRequestOptions(type: string, apiVersion?: string) {

api/FileContainerApi.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
1212

1313
import stream = require("stream");
14+
import * as restm from 'typed-rest-client/RestClient';
1415
import VsoBaseInterfaces = require('./interfaces/common/VsoBaseInterfaces');
1516
import FileContainerApiBase = require("./FileContainerApiBase");
1617
import FileContainerInterfaces = require("./interfaces/FileContainerInterfaces");
@@ -37,6 +38,7 @@ export class FileContainerApi extends FileContainerApiBase.FileContainerApiBase
3738
});
3839
}
3940

41+
// used by ChunkStream
4042
public _createItem(
4143
customHeaders: VsoBaseInterfaces.IHeaders,
4244
contentStream: NodeJS.ReadableStream,
@@ -56,15 +58,27 @@ export class FileContainerApi extends FileContainerApiBase.FileContainerApiBase
5658
};
5759

5860
customHeaders = customHeaders || {};
59-
customHeaders["Content-Type"] = "application/octet-stream";
61+
customHeaders["Content-Type"] = "";
62+
6063

6164
this.vsoClient.getVersioningData("2.2-preview.3", "Container", "e4f5c81e-e250-447b-9fef-bd48471bea5e", routeValues, queryValues)
6265
.then((versioningData: vsom.ClientVersioningData) => {
6366
var url: string = versioningData.requestUrl;
64-
var apiVersion: string = versioningData.apiVersion;
6567
var serializationData = { responseTypeMetadata: FileContainerInterfaces.TypeInfo.FileContainerItem, responseIsCollection: false };
6668

67-
this.restCallbackClient.uploadStream('PUT', url, apiVersion, contentStream, customHeaders, onResult, serializationData);
69+
let options: restm.IRequestOptions = this.createRequestOptions('application/octet-stream',
70+
versioningData.apiVersion);
71+
options.additionalHeaders = customHeaders;
72+
this.rest.uploadStream<FileContainerInterfaces.FileContainerItem>('PUT', url, contentStream, options)
73+
.then((res: restm.IRestResponse<FileContainerInterfaces.FileContainerItem>) => {
74+
let ret = this.formatResponse(res.result,
75+
FileContainerInterfaces.TypeInfo.FileContainerItem,
76+
false);
77+
onResult(null, res.statusCode, ret);
78+
})
79+
.catch((err) => {
80+
onResult(err, err.statusCode, null);
81+
});
6882
}, (error) => {
6983
onResult(error, error.statusCode, null);
7084
});

0 commit comments

Comments
 (0)