Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@doodle/zoom-client / src / createMeeting.js
Size: Mime:
var fetch = require('fetch-everywhere');
var responseHelpers = require('./helpers/fetch');
var buildUrl = require('./helpers/buildUrl');

/**
 * Create a Zoom Meeting on the user's behalf.
 *
 * @param {Number} accountId - The zoom account id
 * @param {String} token - The user's access-token
 * @param {Object} meetingContext - The context of the Doodle Event to use when creating the Zoom Meeting
 * @param {String} baseUrl
 * @returns {*} Promise
 */
function createMeeting(accountId, token, meetingContext, baseUrl) {
  var fetchOptions;
  var url;

  if (typeof accountId !== 'number') {
    throw new TypeError('accountId param must be a number, got ' + typeof accountId);
  }

  if (typeof token !== 'string') {
    throw new TypeError('token param must be a string, got ' + typeof token);
  }

  // Some quick validation on the meetingContext object, since all of these
  // values are required by the "create meeting" endpoint
  ['title', 'description', 'startTime', 'duration', 'timezone'].forEach(function(key) {
    if (typeof meetingContext[key] === 'undefined') {
      throw new TypeError('meetingContext requires a key named ' + key);
    }
  });

  if (typeof baseUrl !== 'string') {
    throw new TypeError('baseUrl param must be a string, got ' + typeof baseUrl);
  }

  url = buildUrl(baseUrl, '/api/svc-zoom-integration/v1.0/accounts/' + accountId + '/meeting');

  fetchOptions = {
    method: 'POST',
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json',
      'Access-Token': token,
    },
    mode: 'cors',
    credentials: 'include',
    body: JSON.stringify({
      // STRING: The title of the meeting
      topic: meetingContext.title,
      // STRING: The description of the meeting
      agenda: meetingContext.description,
      // DATE STRING: The start time of the meeting, i.e: "2020-02-09T20:00:00"
      startTime: meetingContext.startTime,
      // STRING: the duration (in minutes) of the meeting
      duration: meetingContext.duration,
      // The timezone of the meeting, i.e, "Europe/Zurich"
      timezone: meetingContext.timezone,
    }),
  };

  return fetch(url, fetchOptions)
    .catch(responseHelpers.errorHandler)
    .then(responseHelpers.responseHandler);
}

module.exports = createMeeting;