Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve client 1 to implement 1 #21

Merged
merged 4 commits into from
May 13, 2020
Merged
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
36 changes: 28 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import { IMainTemplate } from "./templates/index";
//#region > Interfaces
/** @interface Endpoint defines the structure of object a endpoint requieres to initialize. */
interface IEndpoint {
/**
* Url: the URL of an endpoint. For performance reasons,
* https should always be selected as protocol if possible.
*/
url: string;
type: string;
headers: object;
Expand All @@ -32,7 +36,19 @@ interface IClient {}
//#region > Classes
/** @class The snek-client. Enjoy it. Will be implemented in the future. */
class Client implements IClient {
constructor(ep: IEndpoint) {}
constructor(ep: IEndpoint) {
/*
* When no protocol is defined, http will be appended. Therefore https
* should always be included for performance.
*/
ep.url = ((url: string) => {
if (!/^(?:f|ht)tps?\:\/\//.test(url)) {
url = "http://" + url;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add newline.


return url;
})(ep.url);
}
}

/** @class A client implementation for snek interaction. */
Expand Down Expand Up @@ -73,21 +89,25 @@ class GithubClient extends Client {
}
}

/** @class A client implementation for gitlab interaction. */
class GitlabClient extends Client {
public endpointScraper: ScraperEndpoint;
/**
* @class A client implementation for web interaction like scraping or access
* to APIv4 endpoints.
*/
class WebClient extends Client {
public scraper: ScraperEndpoint;

constructor(
url: string = "https://gitlab.com",
type: string = "scraper",
url: string,
type: string = "A webscraper client",
headers: object = {}
) {
super({ type, url, headers });

this.endpointScraper = new Scraper(url, { headers });
this.scraper = new Scraper(url, { headers });
}
}
//#endregion

//#region > Exports
export { SnekClient, GithubClient, GitlabClient };
export { SnekClient, GithubClient, WebClient };
//#endregion