npm package: @mahebhat/webexapis
Description: > 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
Author: mahebhat
Latest version: 0.0.6

# 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](https://sqbu-github.cisco.com/WebExSquared/webex-integration-node-framework) 

## Table Of Contents

* [Install](#install)
* [Usage](#usage)
* [List of currently available APIs](#list-of-webexapis)
* [Method signature and overview](#method-signature-and-overview)
* [Refrences](#refrences)

## 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

```typescript
// 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. 

```typescript 
// 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

```typescript 
// 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

```typescript
// 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)

```typescript
//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](https://developer.webex.com/docs/api/v1/meetings/create-a-meeting)
- [Get a Meeting](https://developer.webex.com/docs/api/v1/meetings/get-a-meeting)
- [Register a Meeting Registrant](https://developer.webex.com/docs/api/v1/meetings/register-a-meeting-registrant)
- [List Meeting Registrants](https://developer.webex.com/docs/api/v1/meetings/list-meeting-registrants)
- [List Meeting Participants](https://developer.webex.com/docs/api/v1/meeting-participants/list-meeting-participants)
- [List Meetings](https://developer.webex.com/docs/api/v1/meetings/list-meetings)
---
> Membership apis
- [Create a Membership](https://developer.webex.com/docs/api/v1/memberships/create-a-membership)
- [Delete a Membership](https://developer.webex.com/docs/api/v1/memberships/delete-a-membership)
---
> People apis
- [Get Person Details](https://developer.webex.com/docs/api/v1/people/get-person-details)
---
> Recordings apis
- [List Recordings](https://developer.webex.com/docs/api/v1/recordings/list-recordings)
---
> Room apis(space)
- [Create a Room](https://developer.webex.com/docs/api/v1/rooms/create-a-room)
---
> (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 

```javascript 
  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 

```javascript 
  import {membershipService} from 'webexapis'
  //...
  membershipService.createMembership(request.body,request.headers);
  //...
```
- createMembership(request.body, request.headers)

- deleteMembership(request.params.membershipId, request.headers)

> peopleService

```javascript 
  import {peopleService} from 'webexapis'
  //...
  peopleService.getPersonDetails(request.params.personId, request.query, request.headers);
  //...
```
- getPersonDetails(request.params.personId, request.query, request.headers)

> recordingsService

```javascript 
  import {recordingsService} from 'webexapis'
  //...
  recordingsService.listRecordings(request.query,request.headers);
  //...
```
- listRecordings(request.query,request.headers)

> roomsService

```javascript 
  import {roomsService} from 'webexapis'
  //...
  roomsService.createRoom(request.body,request.headers);
  //...
```
- createRoom(request.body, request.headers)

---
#### This methods can be used inside service layer
> Webexapiclients 

```javascript 
  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

```javascript 
  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)
  //...
```

---

## Refrences

> - [Github repo](https://sqbu-github.cisco.com/mahebhat/WebexAPIs-Library)
> - [NPM library](https://www.npmjs.com/package/webexapis)
> - [Webexapis docs](https://developer.webex.com/docs/getting-started)
> - [Repo for refrence how to create controller and service](https://sqbu-github.cisco.com/WebExSquared/webex-integration-node-framework/tree/master/src/webex-apis/controllers)