Skip to content

Commit 566c902

Browse files
authored
Merge pull request #52 from snek-at/schettn-patch-2
schettn-patch-2 to master (Update: README.md)
2 parents 250161b + b46e610 commit 566c902

File tree

1 file changed

+201
-48
lines changed

1 file changed

+201
-48
lines changed

README.md

Lines changed: 201 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -25,80 +25,233 @@ The client unifies the way external data is handled and unites it under a clean,
2525

2626
## Table of contents
2727

28-
- [Quick start](#quick-start)
29-
- [Status](#status)
30-
- [Bugs and feature requests](#bugs-and-feature-requests)
31-
- [Contributing](#contributing)
32-
- [Versioning](#versioning)
33-
- [Contributers](#contributers)
34-
- [Thanks](#thanks)
35-
- [Copyright and license](#copyright-and-license)
28+
- [Table of contents](#table-of-contents)
29+
- [Installation](#installation)
30+
- [Usage](#usage)
31+
- [Set up](#set-up)
32+
- [Sessions](#sessions)
33+
- [Tasks](#tasks)
34+
- [Custom Tasks](#custom-tasks)
35+
- [Extend Project (Add new specific session with template set)](#extend-project-add-new-specific-session-with-template-set)
36+
- [Contributing](#contributing)
37+
- [Bugs and feature requests](#bugs-and-feature-requests)
38+
- [Versioning](#versioning)
39+
- [Creators](#creators)
40+
- [Thanks](#thanks)
41+
- [Copyright and license](#copyright-and-license)
3642

37-
## [](#quick-start)Quick start
43+
## [](#installation)Installation
44+
The system can be installed using the ```npm install``` command:
45+
```bash
46+
$ npm install snek-client
47+
```
3848

39-
- Clone the repo: `https://github.com/snek-at/client.git`
49+
## [](#usage)Usage
50+
### Set up
51+
```typescript
52+
import SnekClient from "snek-client";
4053

41-
## [](#status)Status
54+
const headers = {}
55+
const type = "testclient"
4256

43-
![Website](https://img.shields.io/website/https/snek.at?label=website)
57+
/* Init snekclient */
58+
const snekclient = new SnekClient(""https://engine.snek.at/api/graphiql", headers, type)
59+
```
4460
45-
## [](#bug-and-feature-requests)Bugs and feature requests
61+
### Sessions
62+
Session are completely handled by the Intel.
63+
```typescript
64+
/*
65+
* Starts the session for an anonymous user or maintains the session if
66+
* a user is logged in.
67+
*/
68+
await snekclient.session.begin();
4669

47-
Do you have a bug or a feature request? Please first search for existing and closed issues. If your problem or idea has
48-
not been addressed yet, [please open a new issue](https://github.com/snek-at/client/issues/new/choose).
70+
/*
71+
* Overrides an active session with a new session using the credential
72+
* pair.
73+
*/
74+
await snekclient.session.begin({
75+
username: "schettn",
76+
password: "tschischkotschicko",
77+
});
4978

50-
## [](#contributing)Contributing
79+
/* Ends the session */
80+
await snekclient.session.end();
81+
```
82+
### Tasks
83+
All tasks are session aware! Every task has the capability of token handling. Modifying a token is not suggested.
84+
```typescript
85+
/** Authorization Tasks */
86+
/* Login an anonymous user on the snek-engine */
87+
let userData =
88+
await snekclient.session.tasks.auth.anon();
5189

52-
![GitHub last commit](https://img.shields.io/github/last-commit/snek-at/client)
53-
![GitHub issues](https://img.shields.io/github/issues-raw/snek-at/client)
54-
![GitHub closed issues](https://img.shields.io/github/issues-closed-raw/snek-at/client?color=green)
90+
/* Login a real user on the snek-engine */
91+
let userData =
92+
await snekclient.session.tasks.auth.nonanon();
5593

56-
Please read through our
57-
[contributing guidelines](https://github.com/snek-at/client/blob/master/CONTRIBUTING.md). Included are
58-
directions for opening issues, coding standards, and notes on development.
94+
/* Refresh the user tokens on the snek-engine */
95+
let refreshState =
96+
await snekclient.session.tasks.auth.refresh();
5997

60-
All code should conform to the [Code Guide](https://github.com/snek-at/tonic/blob/master/STYLE_GUIDE.md), maintained by
61-
[SNEK](https://github.com/snek-at).
98+
/* Revoke the user tokens on the snek-engine */
99+
let revokeState =
100+
await snekclient.session.tasks.auth.revoke();
62101

63-
## [](#versioning)Versioning
64102

65-
![GitHub package.json version](https://img.shields.io/github/package-json/v/snek-at/client)
103+
/** General Tasks */
104+
/* Get all profile pages from snek-engine */
105+
let pagesData =
106+
await snekclient.session.tasks.general.allPageUrls();
66107

67-
For reasons of transparency concering our release cycle and in striving to maintain backward compatibility, this
68-
repository is maintained under [the Semantic Versioning guidelines](https://semver.org/). Some minor screw ups
69-
aside, we try to adhere to those rules whenever possible.
108+
/* Get all GitLab servers from the snek-engine */
109+
let gitlabServerData =
110+
await snekclient.session.tasks.general.gitlabServer();
70111

71-
## [](#contributers)Contributers
112+
/** User Tasks */
113+
/* Get all GitLab servers from the snek-engine */
114+
let cachePageData =
115+
await snekclient.session.tasks.user.cache();
72116

73-
**Schett Nico**
117+
/* Get the profile page data from the snek-engine */
118+
let profilePageData =
119+
await snekclient.session.tasks.user.profile();
74120

75-
- <https://twitter.com/sxct4>
76-
- <https://github.com/schettn>
121+
/* Get the registration data from snek-engine */
122+
let registrationData =
123+
await snekclient.session.tasks.user.registration();
77124

78-
**Pinterics David**
125+
/* Get the whoami data from snek-engine */
126+
let whoamiData =
127+
await snekclient.session.tasks.user.whoami();
128+
```
79129
80-
- <https://github.com/pinterid>
81-
- <https://twitter.com/Deff_IT>
130+
### Custom Tasks
131+
```typescript
132+
/*
133+
* Performs a custom session aware task. Authorization is handled via the session.
134+
*/
135+
await snekclient.session.customTask<{ data: { foo: string; bar: string } }>(
136+
"query",
137+
documentNode,
138+
variables
139+
);
140+
```
82141
83-
**Kleber Florian**
142+
## Extend Project (Add new specific session with template set)
143+
Ref: github.com/snek-at/client/blob/master/src/session/sessions.ts
144+
```typescript
145+
//> Tasks
146+
// Contains SNEK tasks
147+
import CustomTasks from "../templates/customsnek/gql/tasks/index";
84148

85-
- <https://twitter.com/kleberbaum>
86-
- <https://github.com/kleberbaum>
149+
class CustomSession extends CookieSession {
150+
public tasks = CustomTasks;
87151

88-
**Aichner Christian**
152+
/**
153+
* Initializes a custom session.
154+
*
155+
* @constructor
156+
* @extends CookieSession Tokens are handled via cookies
157+
* @author Nico Schett <contact@schett.net>
158+
* @param {string} sId A session name
159+
* @param {Endpoint} ep A endpoint
160+
* @param {SnekTemplate} template A template set
161+
*/
162+
constructor(
163+
sId: string,
164+
public ep: ApolloEndpoint,
165+
public template: SnekTemplate
166+
) {
167+
super(sId);
89168

90-
- <https://twitter.com/realaichner>
91-
- <https://www.facebook.com/aichner.christian>
92-
- <https://github.com/Aichnerc>
169+
this.tokenName = sId + "-" + this.tokenName;
170+
this.refreshTokenName = sId + "-" + this.refreshTokenName;
171+
this.tasks = new CustomTasks(this);
172+
}
93173

94-
## [](#thanks)Thanks
174+
//> Methods
175+
}
95176

96-
We do not have any external contributors yet, but if you want your name to be here, feel free
97-
to [contribute to our project](#contributing).
98177

99-
## [](#copyright-and-license)Copyright and license
178+
/* Custom Client */
179+
class CustomClient extends Client {
180+
gql: ApolloEndpoint;
181+
template: IMainTemplate;
182+
session: CustomSession;
183+
184+
/**
185+
* Initializes a SNEK client.
186+
*
187+
* @constructor
188+
* @author Nico Schett <contact@schett.net>
189+
* @param url The base URL the SnekClient should be working on.
190+
* Default: "https://engine.snek.at/api/graphiql".
191+
* @param headers A object containing various request headers
192+
* @param type A type description to differ between multiple instances
193+
*/
194+
constructor(
195+
url: string = "https://engine.snek.at/api/graphiql",
196+
headers: object = {},
197+
type: string = "graphql"
198+
) {
199+
super({ type, url, headers });
200+
201+
this.template = new MainTemplate();
202+
this.gql = new Apollo(url, { headers });
203+
this.session = new CustomSession("snek", this.gql, this.template.snek);
204+
}
205+
}
206+
```
207+
208+
## [](#contributing)Contributing
209+
![GitHub last commit](https://img.shields.io/github/last-commit/snek-at/intel) ![GitHub issues](https://img.shields.io/github/issues-raw/snek-at/intel) ![GitHub closed issues](https://img.shields.io/github/issues-closed-raw/snek-at/intel?color=green)
210+
211+
Please read through our [contributing guidelines](https://github.com/snek-at/front/blob/master/CONTRIBUTING.md). Included are directions for opening issues, coding standards, and notes on development.
212+
213+
All code should conform to the [Code Guide](https://github.com/snek-at/tonic/blob/master/STYLE_GUIDE.md), maintained by [SNEK](https://github.com/snek-at).
100214
215+
## [](#bug-and-feature-requests)Bugs and feature requests
216+
217+
Do you have a bug or a feature request? Please first search for existing and closed issues. If your problem or idea has not been addressed yet, [please open a new issue](https://github.com/snek-at/package-template/issues/new/choose).
218+
219+
## [](#versioning)Versioning
220+
![GitHub package.json version](https://img.shields.io/github/package-json/v/snek-at/intel)
221+
222+
For reasons of transparency concering our release cycle and in striving to maintain backward compatibility, this repository is maintained under [the Semantic Versioning guidelines](https://semver.org/). Some minor screw ups aside, we try to adhere to those rules whenever possible.
223+
224+
## [](#creators)Creators
225+
<table border="0">
226+
<tr>
227+
<td>
228+
<a href="https://github.com/schettn">
229+
<img src="https://avatars.githubusercontent.com/schettn?s=100" alt="Avatar schettn">
230+
</a>
231+
</td>
232+
<td>
233+
<a href="https://github.com/pinterid">
234+
<img src="https://avatars.githubusercontent.com/pinterid?s=100" alt="Avatar pinterid">
235+
</a>
236+
</td>
237+
<td>
238+
<a href="https://github.com/kleberbaum">
239+
<img src="https://avatars.githubusercontent.com/kleberbaum?s=100" alt="Avatar kleberbaum">
240+
</a>
241+
</td>
242+
</tr>
243+
<tr>
244+
<td><a href="https://github.com/schettn">Nico Schett</a></td>
245+
<td><a href="https://github.com/pinterid">David Pinterics</a></td>
246+
<td><a href="https://github.com/kleberbaum">Florian Kleber</a></td>
247+
</tr>
248+
</table>
249+
250+
## [](#thanks)Thanks
251+
We do not have any external contributors yet, but if you want your name to be here, feel free to [contribute to our project](#contributing).
252+
253+
## [](#copyright-and-license)Copyright and license
101254
![GitHub repository license](https://img.shields.io/badge/license-EUPL--1.2-blue)
102255
103256
SPDX-License-Identifier: (EUPL-1.2)
104-
Copyright © Simon Prast
257+
Copyright © 2019-2020 Simon Prast

0 commit comments

Comments
 (0)