glitch-javascript-sdk 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,166 @@
1
+ import UserRoutes from "../routes/UserRoutes";
2
+ import Requests from "../util/Requests";
3
+ import Response from "../util/Response";
4
+ import { AxiosPromise } from "axios";
5
+
6
+ class Users {
7
+
8
+ /**
9
+ * List all the users.
10
+ *
11
+ * @see https://api.glitch.fun/api/documentation#/Users%20Route/userList
12
+ *
13
+ * @returns promise
14
+ */
15
+ public static list<T>(): AxiosPromise<Response<T>> {
16
+ return Requests.processRoute(UserRoutes.routes.list);
17
+ }
18
+
19
+ /**
20
+ * Updates a users information. Requires the users JSON Web Token (JWT) for them to update their profile.
21
+ *
22
+ * @see https://api.glitch.fun/api/documentation#/Users%20Route/updateUser
23
+ *
24
+ * @param data The date to be passed when creating a competiton.
25
+ *
26
+ * @returns Promise
27
+ */
28
+ public static update<T>(data: object): AxiosPromise<Response<T>> {
29
+
30
+ return Requests.processRoute(UserRoutes.routes.update, data);
31
+ }
32
+
33
+ /**
34
+ * Gets the current users information based on the current Json Web Token (JWT).
35
+ *
36
+ * @see https://api.glitch.fun/api/documentation#/Users%20Route/showMe
37
+ *
38
+ * @param user_id The id of the user to update.
39
+ * @param data The data to update.
40
+ *
41
+ * @returns promise
42
+ */
43
+ public static me<T>(): AxiosPromise<Response<T>> {
44
+
45
+ return Requests.processRoute(UserRoutes.routes.me, {});
46
+ }
47
+
48
+ /**
49
+ * Will follow and unfollow a user. If the user is not being following, it will follow the user. If they are following, it will unfollow the user. The current JWT is used for the follower.
50
+ *
51
+ * @see https://api.glitch.fun/api/documentation#/Users%20Route/userToggleFollow
52
+ *
53
+ * @param user_id The id fo the user to retrieve.
54
+ *
55
+ * @returns promise
56
+ */
57
+ public static followToggle<T>(user_id: string): AxiosPromise<Response<T>> {
58
+
59
+ return Requests.processRoute(UserRoutes.routes.follow, {}, { user_id: user_id });
60
+ }
61
+
62
+ /**
63
+ * Show a users profile.
64
+ *
65
+ * @see https://api.glitch.fun/api/documentation#/Users%20Route/showUser
66
+ *
67
+ * @param user_id The id of the user to delete.
68
+ * @returns promise
69
+ */
70
+ public static profile<T>(user_id: string): AxiosPromise<Response<T>> {
71
+
72
+ return Requests.processRoute(UserRoutes.routes.profile, {}, { user_id: user_id });
73
+ }
74
+
75
+ /**
76
+ * Retrieves a user's one time login token based on a users JWT.
77
+ *
78
+ * @see https://api.glitch.fun/api/documentation#/Users%20Route/userOneTimeLoginToken
79
+ *
80
+ *
81
+ * @returns promise
82
+ */
83
+ public static oneTimeLoginToken<T>(): AxiosPromise<Response<T>> {
84
+
85
+ return Requests.processRoute(UserRoutes.routes.oneTimeToken, {});
86
+ }
87
+
88
+ /**
89
+ * Updates the avatar image for the user using a File object.
90
+ *
91
+ * @see https://api.glitch.fun/api/documentation#/Users%20Route/userUploadAvatarImage
92
+ *
93
+ * @param file The file object to upload.
94
+ * @param data Any additional data to pass along to the upload.
95
+ *
96
+ * @returns promise
97
+ */
98
+ public static uploadAvatarImageFile<T>(file : File, data? : object): AxiosPromise<Response<T>> {
99
+
100
+ return Requests.uploadFile(UserRoutes.routes.uploadAvatar.url, 'image', file, data);
101
+ }
102
+
103
+ /**
104
+ * Updates the avatar image for the user using a Blob.
105
+ *
106
+ * @see https://api.glitch.fun/api/documentation#/Users%20Route/userUploadAvatarImage
107
+ *
108
+ * @param blob The blob to upload.
109
+ * @param data Any additional data to pass along to the upload
110
+ *
111
+ * @returns promise
112
+ */
113
+ public static uploadAvatarImageBlob<T>(blob : Blob, data? : object): AxiosPromise<Response<T>> {
114
+
115
+ return Requests.uploadBlob(UserRoutes.routes.uploadAvatar.url, 'image', blob, data);
116
+ }
117
+
118
+ /**
119
+ * Upload a banner image for the user, as a File object.
120
+ *
121
+ * @see https://api.glitch.fun/api/documentation#/Users%20Route/userUploadBannerImage
122
+ *
123
+ * @param file The file object to upload.
124
+ * @param data Any additional data to pass along to the upload.
125
+ *
126
+ * @returns promise
127
+ */
128
+ public static uploadBannerImageFile<T>(file : File, data? : object): AxiosPromise<Response<T>> {
129
+
130
+ return Requests.uploadFile(UserRoutes.routes.uploadBanner.url, 'image', file, data);
131
+ }
132
+
133
+ /**
134
+ * Upload a banner image for the user, as a Blob.
135
+ *
136
+ * @see https://api.glitch.fun/api/documentation#/Users%20Route/userUploadBannerImage
137
+ *
138
+ * @param file The blob to upload.
139
+ * @param data Any additional data to pass along to the upload.
140
+ *
141
+ * @returns promise
142
+ */
143
+ public static uploadBannerImageBlob<T>(blob : Blob, data? : object): AxiosPromise<Response<T>> {
144
+
145
+ return Requests.uploadBlob(UserRoutes.routes.uploadBanner.url, 'image', blob, data);
146
+ }
147
+
148
+ /**
149
+ * Creates a donation page for that user by syncing their information with various
150
+ * payment service.
151
+ *
152
+ * @see https://api.glitch.fun/api/documentation#/Users%20Route/userCreateDonationPage
153
+ *
154
+ * @returns promise
155
+ */
156
+ public static createDonationPage<T>(): AxiosPromise<Response<T>> {
157
+
158
+ return Requests.processRoute(UserRoutes.routes.createDonationPage, {});
159
+ }
160
+
161
+
162
+
163
+
164
+ }
165
+
166
+ export default Users;
package/src/api/index.ts CHANGED
@@ -1,5 +1,11 @@
1
1
  import Auth from "./Auth";
2
2
  import Competitions from "./Competitions";
3
+ import Users from "./Users";
4
+ import Events from "./Events";
5
+ import Teams from "./Teams";
3
6
 
4
7
  export {Auth};
5
- export {Competitions};
8
+ export {Competitions};
9
+ export {Users};
10
+ export {Events};
11
+ export {Teams};
package/src/index.ts CHANGED
@@ -5,13 +5,21 @@ import Config from "./config/Config";
5
5
  //API
6
6
  import { Auth } from "./api";
7
7
  import { Competitions } from "./api";
8
+ import { Users } from "./api";
9
+ import {Events} from "./api";
10
+ import {Teams} from "./api";
8
11
 
9
12
  class Glitch {
10
13
 
11
14
  public static config: typeof Config = Config;
12
15
 
13
- public static auth: typeof Auth = Auth;
14
- public static competitions: typeof Competitions = Competitions;
16
+ public static api : {
17
+ Auth : typeof Auth,
18
+ Competitions: typeof Competitions,
19
+ Users: typeof Users,
20
+ Events : typeof Events,
21
+ Teams : typeof Teams
22
+ }
15
23
 
16
24
 
17
25
  }
@@ -0,0 +1,35 @@
1
+ import Route from "./interface";
2
+ import HTTP_METHODS from "../constants/HttpMethods";
3
+
4
+ class EventsRoutes {
5
+
6
+ public static routes: { [key: string]: Route } = {
7
+ list: { url: '/events', method: HTTP_METHODS.GET },
8
+ create: { url: '/events', method: HTTP_METHODS.POST },
9
+ view : { url: '/events/{event_id}', method: HTTP_METHODS.GET },
10
+ update :{ url: '/events/{event_id}', method: HTTP_METHODS.PUT },
11
+ delete : { url: '/events/{event_id}', method: HTTP_METHODS.DELETE },
12
+ updateInvirtu : {url : '/events/{event_id}/invirtu', method: HTTP_METHODS.PUT },
13
+ syncAsLive : {url : '/events/{event_id}/syncAsLive', method: HTTP_METHODS.POST },
14
+ addRTMPSource : {url : '/events/{event_id}/addRTMPSource', method: HTTP_METHODS.POST },
15
+ updateRTMPSource : {url : '/events/{event_id}/updateRTMPSource/{subid}', method: HTTP_METHODS.PUT },
16
+ removeRTMPSource : {url : '/events/{event_id}/removeRTMPSource/{subid}', method: HTTP_METHODS.DELETE},
17
+ uploadMainImage : {url : '/events/{event_id}/removeRTMPSource/{subid}', method: HTTP_METHODS.POST},
18
+ uploadBannerImage : {url : '/events/{event_id}/uploadBannerImage', method: HTTP_METHODS.POST},
19
+ enableBroadcastMode : {url : '/events/{event_id}/uploadBannerImage', method: HTTP_METHODS.POST},
20
+ enableLivestreamMode : {url : '/events/{event_id}/enableLivestreamMode', method: HTTP_METHODS.POST},
21
+ sendOnScreenContent : {url : '/events/{event_id}/sendOnScreenContent', method: HTTP_METHODS.POST},
22
+ addOverlay : {url : '/events/{event_id}/addOverlay', method : HTTP_METHODS.POST},
23
+ removeOverlay : {url : '/events/{event_id}/removeOverlay/{subid}', method : HTTP_METHODS.DELETE},
24
+ enableOverlay : {url : '/events/{event_id}/enableOverlay/{subid}', method : HTTP_METHODS.POST},
25
+ disableOverlay : {url : '/events/{event_id}/disableOverlay', method: HTTP_METHODS.POST},
26
+ enableDonations : {url : '/events/{event_id}/enableDonations', method: HTTP_METHODS.POST},
27
+ disableDonations : {url : '/events/{event_id}/disableDonations', method : HTTP_METHODS.POST},
28
+ sendInvite : {url : '/events/{event_id}/sendInvite', method : HTTP_METHODS.POST},
29
+ acceptInvite : {url : '/events/{event_id}/sendInvite', method : HTTP_METHODS.POST}
30
+
31
+ };
32
+
33
+ }
34
+
35
+ export default EventsRoutes;
@@ -0,0 +1,26 @@
1
+ import Route from "./interface";
2
+ import HTTP_METHODS from "../constants/HttpMethods";
3
+
4
+ class TeamsRoute {
5
+
6
+ public static routes: { [key: string]: Route } = {
7
+ list: { url: '/teams', method: HTTP_METHODS.GET },
8
+ create: { url: '/teams', method: HTTP_METHODS.POST },
9
+ view : { url: '/teams/{team_id}', method: HTTP_METHODS.GET },
10
+ update :{ url: '/teams/{team_id}', method: HTTP_METHODS.PUT },
11
+ delete : { url: '/teams/{team_id}', method: HTTP_METHODS.DELETE },
12
+ uploadMainImage : {url: '/teams/{team_id}/uploadMainImage', method : HTTP_METHODS.POST },
13
+ uploadBannerImage : {url : '/teams/{team_id}/uploadBannerImage', method : HTTP_METHODS.POST },
14
+ listInvites : {url : '/teams/{team_id}/invites', method : HTTP_METHODS.GET },
15
+ sendInvite : {url: '/teams/{team_id}/sendInvite', method : HTTP_METHODS.POST},
16
+ acceptInvite : {url : '/teams/{team_id}/acceptInvite', method: HTTP_METHODS.POST},
17
+ listTeamUsers : {url : '/teams/{team_id}/users', method : HTTP_METHODS.GET},
18
+ addTeamUser : {url : '/teams/{team_id}/users', method : HTTP_METHODS.POST},
19
+ showTeamUser : {url : '/teams/{team_id}/users/{user_id}', method : HTTP_METHODS.GET},
20
+ updateTeamUser : {url : '/teams/{team_id}/users/{user_id}', method : HTTP_METHODS.PUT},
21
+ removeTeamUser : {url : '/teams/{team_id}/users/{user_id}', method : HTTP_METHODS.DELETE}
22
+ };
23
+
24
+ }
25
+
26
+ export default TeamsRoute;
@@ -0,0 +1,20 @@
1
+ import Route from "./interface";
2
+ import HTTP_METHODS from "../constants/HttpMethods";
3
+
4
+ class UserRoutes {
5
+
6
+ public static routes: { [key: string]: Route } = {
7
+ list: { url: '/users', method: HTTP_METHODS.GET },
8
+ update: { url: '/users', method: HTTP_METHODS.PUT },
9
+ follow : { url: '/users/{user_id}/follow', method: HTTP_METHODS.POST },
10
+ profile :{ url: '/users/{user_id}/profile', method: HTTP_METHODS.GET },
11
+ me : { url: '/users/me', method: HTTP_METHODS.GET },
12
+ oneTimeToken : { url: '/users/oneTimeToken', method: HTTP_METHODS.GET },
13
+ uploadAvatar : { url: '/users/uploadAvatarImage', method: HTTP_METHODS.POST },
14
+ uploadBanner : { url: '/users/uploadBannerImage', method: HTTP_METHODS.POST },
15
+ createDonationPage : { url: '/users/createDonationPage', method: HTTP_METHODS.POST },
16
+ };
17
+
18
+ }
19
+
20
+ export default UserRoutes;
@@ -53,16 +53,27 @@ class Requests {
53
53
  private static request<T>(
54
54
  method: 'GET' | 'POST' | 'PUT' | 'DELETE',
55
55
  url: string,
56
- data?: any
56
+ data?: any,
57
+ fileData?: any
57
58
  ): AxiosPromise<Response<T>> {
59
+
60
+ let headers = {
61
+ 'Content-Type': 'application/json',
62
+ };
63
+
64
+ if(this.authToken) {
65
+ headers['Authorization'] = `Bearer ${this.authToken}`;
66
+ }
67
+
68
+ if (fileData) {
69
+ headers['Content-Type'] = 'multipart/form-data';
70
+ }
71
+
58
72
  const axiosPromise = axios({
59
73
  method,
60
74
  url: `${this.baseUrl}${url}`,
61
- data,
62
- headers: {
63
- Authorization: `Bearer ${this.authToken}`,
64
- 'Content-Type': 'application/json',
65
- },
75
+ data: fileData || data,
76
+ headers,
66
77
  });
67
78
 
68
79
  return axiosPromise;
@@ -90,6 +101,42 @@ class Requests {
90
101
  return this.request<T>('DELETE', url);
91
102
  }
92
103
 
104
+ public static uploadFile<T>(
105
+ url: string,
106
+ filename : string,
107
+ file: File,
108
+ data?: any
109
+ ): AxiosPromise<Response<T>> {
110
+
111
+ const formData = new FormData();
112
+
113
+ formData.append(filename, file);
114
+
115
+ for (let key in data) {
116
+ formData.append(key, data[key]);
117
+ }
118
+
119
+ return this.request<T>('POST', url, data, formData);
120
+ }
121
+
122
+ public static uploadBlob<T>(
123
+ url: string,
124
+ filename : string,
125
+ blob: Blob,
126
+ data?: any
127
+ ): AxiosPromise<Response<T>> {
128
+
129
+ const formData = new FormData();
130
+
131
+ formData.append(filename, blob);
132
+
133
+ for (let key in data) {
134
+ formData.append(key, data[key]);
135
+ }
136
+
137
+ return this.request<T>('POST', url, data, formData);
138
+ }
139
+
93
140
  /**
94
141
  * The Route class contains the method and url, thereforce items can be
95
142
  * automatically routed depending on the configuration.