Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <section class="bcls-section">
<h2 id="Set_default_profile_app">Set default profile app</h2>

<p>You can use the form below to set the default ingest profile for one or more accounts.</p>

<fieldset><legend>Input</legend>

<p>If you do not enter account information, a Brightcove sample account will be used.</p>

<p>Account ids (comma-delimited list): <input id="account_ids" type="text" placeholder="1752604059001,921483702001,57838016001" /></p>

<p>Client id: <input id="client_id" type="text" size="60" placeholder="c5d0a622-5479-46d8-8d8a-5f034b943fab" /></p>

<p>Client secret: <input id="client_secret" type="text" size="60" placeholder="w7NQYu0vUloM4GYYy2SXAxrvyFpt8fwI35qAFZcS13-VIgs0itwKNsAwHOS80sOWKJ1BUwHIvSFG" /></p>

<p>Profile to set as default: <select name="profileSelect" id="profileSelect" style="width:200px;"></select></p>

<p><button class="bcls-button" id="setDefaults">Set the Selected Profile as Default for these Accounts</button></p>
</fieldset>

<fieldset><legend>Output</legend>

<p id="logger" style="color:rgb(237, 104, 38)">Waiting for input...</p>

<h4>Current API request</h4>

<pre>
  <code id="apiRequest">API request will appear here...</code></pre>

<h4>Response data</h4>

<pre>
  <code id="apiResponse" style="width:95%;height:30em;">Response will appear here...</code></pre>
</fieldset>
</section>
              
            
!

CSS

              
                /* * The body style is just for the
 * background color of the codepen.
 * Do not include in your code.
 */
body {
  background-color: #111;
  color: #f5f5f5;
  font-family: sans-serif;
  margin: 2em;
}
/*
 * Styles essential to the sample
 * are below
 */
.bcls-code {
  color: #111;
  font-family: 'Source Code Pro',monospace;
  padding: 1em;
  width: 90%;
  min-height: 5em;
  background-color: #cfcfcf;
  font-size: 1rem;
}
.bcls-button {
  padding: .5em;
  background-color: #333;
  border: 1px yellow solid;
  border-radius: .5em;
  color: yellow;
  cursor: pointer;
}
fieldset {
  color: #64AAB2;
  border: 1px #64AAB2 solid;
  border-radius: .5em;
}
code {
  color: #E4B842;
  font-family: 'Source Code Pro',monospace;
}
              
            
!

JS

              
                var BCLS = (function (window, document) {
  var // account stuff
    accountId,
    bcToken,
    clientId,
    clientSecret,
    newProfile,
    // api stuff
    proxyURL = 'https://solutions.brightcove.com/bcls/bcls-proxy/bcls-proxy-v2.php',
    ipURL = 'https://ingestion.api.brightcove.com/v1/accounts/',
    ipURLsuffix = '/configuration',
    totalCalls = 0,
    callNumber = 0,
    responseArray = [],
    accountsArray = [],
    defaultAccounts = ['1485884786001'],
    profilesArray = ['smart-player-transition', 'videocloud-default-v1', 'high-resolution', 'screencast-1280', 'single-bitrate-high', 'single-bitrate-standard'],
    // elements
    account_ids = document.getElementById('account_ids'),
    client_id = document.getElementById('client_id'),
    client_secret = document.getElementById('client_secret'),
    profileSelect = document.getElementById('profileSelect'),
    setDefaults = document.getElementById('setDefaults'),
    logger = document.getElementById('logger'),
    apiRequest = document.getElementById('apiRequest'),
    apiResponse = document.getElementById('apiResponse');


  /**
   * remove spaces from a string
   * @param {String} str string to process
   */
  function removeSpaces(str) {
    str = str.replace(/\s/g, '');
    return str;
  }

  /**
   * tests for all the ways a variable might be undefined or not have a value
   * @param {String|Number} x the variable to test
   * @return {Boolean} true if variable is defined and has a value
   */
  function isDefined(x) {
    if (x === "" || x === null || x === undefined) {
      return false;
    }
    return true;
  }

  /**
   * get selected value for single select element
   * @param {htmlElement} e the select element
   */
  function getSelectedValue(e) {
    return e.options[e.selectedIndex].value;
  }


  /**
   * disables a button so user can't submit new request until current one finishes
   */
  function disableButton(button) {
    button.setAttribute('disabled', 'disabled');
    button.setAttribute('style', 'opacity:.5,cursor:not-allowed;');
  }

  /**
   * enables a button
   * @param {htmlElement} button - the button to enable
   */
  function enableButton(button) {
    button.removeAttribute('disabled');
    button.setAttribute('style', 'opacity:1;cursor:pointer;');
  }

  /**
   * sets up the data for the API request
   * @param {String} id the id of the button that was clicked
   */
  function setoptions(id, type) {
    var i,
      iMax,
      options = {};
    options.account_id = accountsArray[callNumber];
    options.proxyURL = proxyURL;
    if (isDefined(client_id) && isDefined(client_secret)) {
      options.client_id = clientId;
      options.client_secret = clientSecret;
    }
    switch (id) {
      case 'setDefaults':
        var reqBody = {},
          now;
        logger.textContent = 'Processing account: ' + accountsArray[callNumber];
        endPoint = accountsArray[callNumber];
        options.url = ipURL + endPoint + ipURLsuffix;
        options.requestType = type;
        reqBody.account_id = parseInt(accountsArray[callNumber]);
        reqBody.default_profile_id = newProfile;
        options.requestBody = JSON.stringify(reqBody);
        apiRequest.textContent = options.url;
        makeRequest(options, function (response) {
          var now = new Date().toISOString();
          parsedData = JSON.parse(response);
          responseArray.push(parsedData);
          if (Array.isArray(parsedData)) {
            // we have an error, most likely a conflict
            setoptions('setDefaults', 'PUT');
          } else {
            callNumber++;
            if (callNumber < totalCalls) {
              setoptions('setDefaults', 'POST');
            } else {
              logger.textContent = 'Finished at ' + now;
              apiResponse.textContent = JSON.stringify(responseArray, null, '  ');
            }
          }

        });
        break;
    }
  }

  /**
   * send API request to the proxy
   * @param  {Object} options for the request
   * @param  {String} options.url the full API request URL
   * @param  {String="GET","POST","PATCH","PUT","DELETE"} requestData [options.requestType="GET"] HTTP type for the request
   * @param  {String} options.proxyURL proxyURL to send the request to
   * @param  {String} options.client_id client id for the account (default is in the proxy)
   * @param  {String} options.client_secret client secret for the account (default is in the proxy)
   * @param  {JSON} [options.requestBody] Data to be sent in the request body in the form of a JSON string
   * @param  {Function} [callback] callback function that will process the response
   */
  function makeRequest(options, callback) {
    var httpRequest = new XMLHttpRequest(),
      response,
      proxyURL = options.proxyURL,
      // response handler
      getResponse = function () {
        try {
          if (httpRequest.readyState === 4) {
            if (httpRequest.status >= 200 && httpRequest.status < 300) {
              response = httpRequest.responseText;
              // some API requests return '{null}' for empty responses - breaks JSON.parse
              if (response === '{null}') {
                response = null;
              }
              // return the response
              callback(response);
            } else {
              alert('There was a problem with the request. Request returned ' + httpRequest.status);
            }
          }
        } catch (e) {
          alert('Caught Exception: ' + e);
        }
      };
    /**
     * set up request data
     * the proxy used here takes the following request body:
     * JSON.stringify(options)
     */
    // set response handler
    httpRequest.onreadystatechange = getResponse;
    // open the request
    httpRequest.open('POST', proxyURL);
    // set headers if there is a set header line, remove it
    // open and send request
    httpRequest.send(JSON.stringify(options));
  }

  function init() {
    var i,
      iMax,
      opt;
    // set up profiles selector
    iMax = profilesArray.length;
    for (i = 0; i < iMax; i++) {
      opt = document.createElement('option');
      opt.value = profilesArray[i];
      opt.text = profilesArray[i];
      profileSelect.add(opt, null);
    }
    // event handlers
    setDefaults.addEventListener('click', function () {
      var accountIds;
      // get the inputs
      clientId = client_id.value;
      clientSecret = client_secret.value;
      newProfile = getSelectedValue(profileSelect);
      // only use entered account id if client id and secret are entered also
      if (isDefined(clientId) && isDefined(clientSecret)) {
        if (isDefined(account_ids.value)) {
          accountIds = removeSpaces(account_ids.value);
          accountsArray = accountIds.split(',');
        } else {
          window.alert('To use your own account, you must specify an account id, and client id, and a client secret - since at least one of these is missing, a sample account will be used');
          clientId = '';
          clientSecret = '';
          accountsArray = defaultAccounts;
        }
      } else {
        accountsArray = defaultAccounts;
      }
      totalCalls = accountsArray.length;
      setoptions('setDefaults', 'POST');
    });

    apiResponse.addEventListener('click', function () {
      apiResponse.select();
    });
  }
  // kick things off
  init();
})(window, document);


              
            
!
999px

Console