示例#1
0
        /// <summary>
        /// Creates the asset.
        /// </summary>
        /// <returns>The asset.</returns>
        /// <param name="theToken">The token.</param>
        /// <param name="strAccountID">String account identifier.</param>
        /// <param name="theBody">The body.</param>
        /// <exception cref="Base.BrightcoveAPIException">Thrown when the CMS API call returns an error.</exception>
        public string CreateVideo(OAuthToken theToken, string strAccountID, CVORequestBody theBody)
        {
            if (!Helper.IsDigitsOnly(strAccountID))
            {
                throw new BrightcoveAPIException(Helper.strAccountIDNotValid);
            }

            var client  = new RestClient(String.Format("{0}/{1}/videos", BaseURL, strAccountID));
            var request = new RestRequest();

            // serialize the object to JSON
            string strJSONBody = SimpleJson.SerializeObject(theBody);

            request.Parameters.Clear();

            request.Method = Method.POST;
            request.AddHeader("Content-type", "application/json");
            request.AddParameter("Authorization", "Bearer " + theToken.Token, ParameterType.HttpHeader);
            request.AddParameter("application/json", strJSONBody, ParameterType.RequestBody);

            IRestResponse apiresponse = client.Execute(request);

            dynamic createAssetResponse = SimpleJson.DeserializeObject(apiresponse.Content);

            if (apiresponse.Content.Contains("error_code"))
            {
                throw new BrightcoveAPIException(createAssetResponse[0]["error_code"]);
            }

            return(createAssetResponse["id"]);
        }
示例#2
0
        /// <summary>
        /// Creates the asset.
        /// </summary>
        /// <returns>The asset.</returns>
        /// <param name="theToken">The token.</param>
        /// <param name="strAccountID">String account identifier.</param>
        /// <param name="strAssetName">String asset name.</param>
        /// <param name="strRefID">String reference identifier.</param>
        /// <exception cref="Base.BrightcoveAPIException">Thrown when the CMS API call returns an error.</exception>
        public string CreateVideo(OAuthToken theToken, string strAccountID, string strAssetName, string strRefID = "")
        {
            // create and populate the request body object
            var createAssetRequestBody = new CVORequestBody();

            createAssetRequestBody.name         = strAssetName;
            createAssetRequestBody.reference_id = strRefID;

            return(CreateVideo(theToken, strAccountID, createAssetRequestBody));
        }