Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ export class UrlEncodedRequestConsumingClient {
}

addMessage(message: Foo | null | undefined, messageId: string | null | undefined): ng.IPromise<void> {
let url_ = this.baseUrl + "/api/UrlEncodedRequestConsuming";
url_ = url_.replace(/[?&]$/, "");
const url_ = new UriBuilder(this.baseUrl + "/api/UrlEncodedRequestConsuming")
.toString();

let content_ = "";
if (message !== undefined)
content_ += encodeURIComponent("message") + "=" + encodeURIComponent("" + message) + "&";
if (messageId !== undefined)
content_ += encodeURIComponent("messageId") + "=" + encodeURIComponent("" + messageId) + "&";
content_ = content_.replace(/&$/, "");
Guard.defined(message, "message");
Guard.defined(messageId, "messageId");

const content_ = new UriBuilder("")
.param("message", message)
.param("messageId", messageId)
.toString();

var options_: ng.IRequestConfig = {
url: url_,
Expand Down Expand Up @@ -134,4 +135,68 @@ function blobToText(blob: Blob, q: ng.IQService): ng.IPromise<string> {
reader.onload = event => resolve((event.target as any).result);
reader.readAsText(blob);
});
}

class Guard {
static required(value: any, name: string) {
if (value === undefined || value === null)
throw new globalThis.Error(`The parameter '${name}' must be defined and cannot be null.`);
}

static defined(value: any, name: string) {
if (value === undefined)
throw new globalThis.Error(`The parameter '${name}' must be defined.`);
}

static notNull(value: any, name: string) {
if (value === null)
throw new globalThis.Error(`The parameter '${name}' cannot be null.`);
}
}

class UriBuilder {
private params: string[] = [];

constructor(private url: string) {}

path(name: string, value: any) {
if (value === undefined || value === null) {
this.url = this.url.replace(`/{${name}}`, "").replace(`{${name}}`, "");
return this;
}
const resolved = Array.isArray(value) ? value.join() : value;
this.url = this.url.replace(`{${name}}`, encodeURIComponent("" + resolved));
return this;
}

param(name: string, value: any) {
if (value == null) return this;
this.params.push(`${name}=${encodeURIComponent("" + value)}`);
return this;
}

paramArray(name: string, arr: any[]) {
if (!arr) return this;
arr.forEach(v =>
this.params.push(`${name}=${encodeURIComponent("" + v)}`)
);
return this;
}

paramObjectArray(name: string, arr: any[]) {
if (!arr) return this;
arr.forEach((obj, i) => {
Object.entries(obj).forEach(([k, v]) => {
this.params.push(
`${name}[${i}].${k}=${encodeURIComponent("" + v)}`
);
});
});
return this;
}

toString() {
if (!this.params.length) return this.url;
return this.url + (this.url.includes("?") ? "&" : "?") + this.params.join("&");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class DiscussionClient implements IDiscussionClient {
}

addMessage(message: Foo | null | undefined): ng.IPromise<void> {
let url_ = this.baseUrl + "/api/Discussion";
url_ = url_.replace(/[?&]$/, "");
const url_ = new UriBuilder(this.baseUrl + "/api/Discussion")
.toString();

const content_ = JSON.stringify(message);

Expand Down Expand Up @@ -133,4 +133,68 @@ function blobToText(blob: Blob, q: ng.IQService): ng.IPromise<string> {
reader.onload = event => resolve((event.target as any).result);
reader.readAsText(blob);
});
}

class Guard {
static required(value: any, name: string) {
if (value === undefined || value === null)
throw new globalThis.Error(`The parameter '${name}' must be defined and cannot be null.`);
}

static defined(value: any, name: string) {
if (value === undefined)
throw new globalThis.Error(`The parameter '${name}' must be defined.`);
}

static notNull(value: any, name: string) {
if (value === null)
throw new globalThis.Error(`The parameter '${name}' cannot be null.`);
}
}

class UriBuilder {
private params: string[] = [];

constructor(private url: string) {}

path(name: string, value: any) {
if (value === undefined || value === null) {
this.url = this.url.replace(`/{${name}}`, "").replace(`{${name}}`, "");
return this;
}
const resolved = Array.isArray(value) ? value.join() : value;
this.url = this.url.replace(`{${name}}`, encodeURIComponent("" + resolved));
return this;
}

param(name: string, value: any) {
if (value == null) return this;
this.params.push(`${name}=${encodeURIComponent("" + value)}`);
return this;
}

paramArray(name: string, arr: any[]) {
if (!arr) return this;
arr.forEach(v =>
this.params.push(`${name}=${encodeURIComponent("" + v)}`)
);
return this;
}

paramObjectArray(name: string, arr: any[]) {
if (!arr) return this;
arr.forEach((obj, i) => {
Object.entries(obj).forEach(([k, v]) => {
this.params.push(
`${name}[${i}].${k}=${encodeURIComponent("" + v)}`
);
});
});
return this;
}

toString() {
if (!this.params.length) return this.url;
return this.url + (this.url.includes("?") ? "&" : "?") + this.params.join("&");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export class DiscussionClient implements IDiscussionClient {
}

addMessage(message: Foo | null | undefined): ng.IPromise<void> {
let url_ = this.baseUrl + "/api/Discussion";
url_ = url_.replace(/[?&]$/, "");
const url_ = new UriBuilder(this.baseUrl + "/api/Discussion")
.toString();

const content_ = JSON.stringify(message);

Expand Down Expand Up @@ -133,4 +133,68 @@ function blobToText(blob: Blob, q: ng.IQService): ng.IPromise<string> {
reader.onload = event => resolve((event.target as any).result);
reader.readAsText(blob);
});
}

class Guard {
static required(value: any, name: string) {
if (value === undefined || value === null)
throw new globalThis.Error(`The parameter '${name}' must be defined and cannot be null.`);
}

static defined(value: any, name: string) {
if (value === undefined)
throw new globalThis.Error(`The parameter '${name}' must be defined.`);
}

static notNull(value: any, name: string) {
if (value === null)
throw new globalThis.Error(`The parameter '${name}' cannot be null.`);
}
}

class UriBuilder {
private params: string[] = [];

constructor(private url: string) {}

path(name: string, value: any) {
if (value === undefined || value === null) {
this.url = this.url.replace(`/{${name}}`, "").replace(`{${name}}`, "");
return this;
}
const resolved = Array.isArray(value) ? value.join() : value;
this.url = this.url.replace(`{${name}}`, encodeURIComponent("" + resolved));
return this;
}

param(name: string, value: any) {
if (value == null) return this;
this.params.push(`${name}=${encodeURIComponent("" + value)}`);
return this;
}

paramArray(name: string, arr: any[]) {
if (!arr) return this;
arr.forEach(v =>
this.params.push(`${name}=${encodeURIComponent("" + v)}`)
);
return this;
}

paramObjectArray(name: string, arr: any[]) {
if (!arr) return this;
arr.forEach((obj, i) => {
Object.entries(obj).forEach(([k, v]) => {
this.params.push(
`${name}[${i}].${k}=${encodeURIComponent("" + v)}`
);
});
});
return this;
}

toString() {
if (!this.params.length) return this.url;
return this.url + (this.url.includes("?") ? "&" : "?") + this.params.join("&");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ export class UrlEncodedRequestConsumingClient {
}

addMessage(message: Foo | null | undefined, messageId: string | null | undefined): Observable<void> {
let url_ = this.baseUrl + "/api/UrlEncodedRequestConsuming";
url_ = url_.replace(/[?&]$/, "");
const url_ = new UriBuilder(this.baseUrl + "/api/UrlEncodedRequestConsuming")
.toString();

let content_ = "";
if (message !== undefined)
content_ += encodeURIComponent("message") + "=" + encodeURIComponent("" + message) + "&";
if (messageId !== undefined)
content_ += encodeURIComponent("messageId") + "=" + encodeURIComponent("" + messageId) + "&";
content_ = content_.replace(/&$/, "");
Guard.defined(message, "message");
Guard.defined(messageId, "messageId");

const content_ = new UriBuilder("")
.param("message", message)
.param("messageId", messageId)
.toString();

let options_ : any = {
body: content_,
Expand Down Expand Up @@ -154,4 +155,68 @@ function blobToText(blob: any): Observable<string> {
reader.readAsText(blob);
}
});
}

class Guard {
static required(value: any, name: string) {
if (value === undefined || value === null)
throw new globalThis.Error(`The parameter '${name}' must be defined and cannot be null.`);
}

static defined(value: any, name: string) {
if (value === undefined)
throw new globalThis.Error(`The parameter '${name}' must be defined.`);
}

static notNull(value: any, name: string) {
if (value === null)
throw new globalThis.Error(`The parameter '${name}' cannot be null.`);
}
}

class UriBuilder {
private params: string[] = [];

constructor(private url: string) {}

path(name: string, value: any) {
if (value === undefined || value === null) {
this.url = this.url.replace(`/{${name}}`, "").replace(`{${name}}`, "");
return this;
}
const resolved = Array.isArray(value) ? value.join() : value;
this.url = this.url.replace(`{${name}}`, encodeURIComponent("" + resolved));
return this;
}

param(name: string, value: any) {
if (value == null) return this;
this.params.push(`${name}=${encodeURIComponent("" + value)}`);
return this;
}

paramArray(name: string, arr: any[]) {
if (!arr) return this;
arr.forEach(v =>
this.params.push(`${name}=${encodeURIComponent("" + v)}`)
);
return this;
}

paramObjectArray(name: string, arr: any[]) {
if (!arr) return this;
arr.forEach((obj, i) => {
Object.entries(obj).forEach(([k, v]) => {
this.params.push(
`${name}[${i}].${k}=${encodeURIComponent("" + v)}`
);
});
});
return this;
}

toString() {
if (!this.params.length) return this.url;
return this.url + (this.url.includes("?") ? "&" : "?") + this.params.join("&");
}
}
Loading