@webex-test/webexapis-test-versioning
v0.0.3
Published
> Webexapis is NodeJS library developed in typescript and can be used by Javascript and typescript projects. It Contains webexapis implementations, DTOs, and some functionalites (token and context extraction from request) which can be used by developer ea
Downloads
2
Maintainers
Readme
WebexAPIs-Library
Webexapis is NodeJS library developed in typescript and can be used by Javascript and typescript projects. It Contains webexapis implementations, DTOs, and some functionalites (token and context extraction from request) which can be used by developer easily.
Webexapi library implementation is based on starter-kit
Table Of Contents
Install
via npm: npm install webexapis
via yarn: yarn add webexapis
Usage
(Use cases and how to use library functions)
> Simple demo NodeJS app
USE CASE 1 : Use of service layer apis methods
- Developer has to implements only controllers no need to create service layer
// meetingController.ts
import express from "express";
const app = express();
const port = 3000;
import { meetingService } from "webexapis";
import { Request, Response } from "express";
app.get("/meeting", async (request: Request, response: Response) => {
await meetingService
.getListMeeting(request.query, request.headers)
.then((result) => {
response.status(result.status);
response.send(result.data);
})
.catch((error) => {
console.log("unable to fetch list of meetings");
response.status(error.response.status);
response.send(error.response.data);
});
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});
USE CASE 2 : Use of webexapiclients apis methods
- Here, Developer has to create controller and service layer. Inside service layer developer has to use webexapiclients api methods.
// meetingService.ts
import { webexApiClient } from "webexapis";
// this getListMeeting function used in controller which is shown in USE CASE 1
async getListMeeting(reqQueryParams: any, reqHeaders: GetMeetingByIdHeader) {
return await this.webexAPIClient.getListMeeting(reqQueryParams, reqHeaders);
}
USE CASE 3 : Use of webexapiclient setAuthorization function
- Here, Developer has to use setAuthorization function inside service layer to set token
// meetingService.ts
import { webexApiClient } from "webexapis";
// this getListMeeting function used in controller which is shown in USE CASE 1
async getListMeeting(reqQueryParams: any, reqHeaders: GetMeetingByIdHeader) {
const {authorization} = CommonUtils.extractContextAndAuthFromRequest(
undefined, // if request.body is not present then use undefined
reqHeaders
);
// Use of set authorization
if (authorization) {
// Set auth header on Webex API Client
this.webexAPIClient.setAuthorizationHeader(authorization);
} else {
console.log('No authorization/token received in request');
}
return await this.webexAPIClient.getListMeeting(reqQueryParams, reqHeaders);
}
USE CASE 4 : Use of commonUtils extraction method
- If developer wants to extract authorization(token) and context from request so developer can use this functions inside service layer
// This is how we can extract
/**
* Extract context from request body
* Extract auth string from request header OR context
*/
const {context, reqDataWithoutContext, authorization} = CommonUtils.extractContextAndAuthFromRequest(
reqData,
reqHeaders
);
// This extracted values used by developer as per requirements.
// In use case 3 : Shown that how we can use authorization to set token
USE CASE 5 : Use of DTO
- DTOs can be used for typecasting or to show the type of request/response object
- (There's other usecases of DTO as well but we used it for typecasting)
//ex.1
import { meetingDto } from "webexapis";
const listMeetingQueryParams = <meetingDto.ListMeetingQueryParams>request.query;
const listMeetingHeaders = <meetingDto.GetMeetingByIdHeader>request.headers;
//ex. 2
//...
getListMeeting(reqQuery: meetingDto.ListMeetingQueryParams, reqHeaders: meetingDto.GetMeetingByIdHeader)
//...
List of WebexAPIs
Meeting apis
- Create a Meeting
- Get a Meeting
- Register a Meeting Registrant
- List Meeting Registrants
- List Meeting Participants
- List Meetings
Membership apis
People apis
Recordings apis
Room apis(space)
(Note : More apis will be available later)
Method Signature and overview
(List of all available functions with signature) (Note : Function name indicates that it belongs to which apis and refer above section to know more about api Ex. type of api get/post...)
This methods can be used inside controller layer
meetingService
import {meetingService} from 'webexapis'
//...
meetingService.createMeeting(request.body,request.headers);
//...
createMeeting(request.body, request.headers)
getListMeeting(request.query, request.headers)
getListMeetingRegistrants(request.params.meetingId, request.query, request.headers)
getMeetingById(request.params.meetingId, request.query, request.headers)
registerMeetingRegistrants(request.params.meetingId, request.body, request.headers)
listMeetingParticipants(request.query, request.headers)
membershipService
import {membershipService} from 'webexapis'
//...
membershipService.createMembership(request.body,request.headers);
//...
createMembership(request.body, request.headers)
deleteMembership(request.params.membershipId, request.headers)
peopleService
import {peopleService} from 'webexapis'
//...
peopleService.getPersonDetails(request.params.personId, request.query, request.headers);
//...
- getPersonDetails(request.params.personId, request.query, request.headers)
recordingsService
import {recordingsService} from 'webexapis'
//...
recordingsService.listRecordings(request.query,request.headers);
//...
- listRecordings(request.query,request.headers)
roomsService
import {roomsService} from 'webexapis'
//...
roomsService.createRoom(request.body,request.headers);
//...
- createRoom(request.body, request.headers)
This methods can be used inside service layer
Webexapiclients
import {webexApiClient} from 'webexapis'
//...
{
//Here, we need to set authorization without this api will not work
webexAPIClient.setAuthorizationHeader(request.headers.authorization);
webexAPIClient.getListMeeting(reqQueryParams, reqHeaders);
}
//...
createMeeting(request.body)
getListMeeting(request.query, request.headers)
getListMeetingRegistrants(request.params.meetingId, request.query, request.headers)
getMeetingById(meetingId, request.query, request.headers)
registerMeetingRegistrant(request.params.meetingId, request.body)
listParticipantsByMeetingId(request.query)
createMembership(request.body)
deleteMembership(request.params.membershipId)
getPersonDetails(request.params.personId, request.query)
createRoom(request.body)
listRecordings(request.query)
//Below method takes authorization as argument (authorization can be extracted using commonUtils method or from request.headers.authorization)
- setAuthorizationHeader(request.headers.authorization)
CommonUtils methods
import {CommonUtils} from 'webexapis'
//...
const {context, reqDataWithoutContext, authorization} = CommonUtils.extractContextAndAuthFromRequest(//
request.body,
request.headers
);
// if request.body is not presents in request then pass undefined in place of request. like (undefined,req.headers)
//...