Exemple #1
0
        /// <summary>
        /// Retrieve a playlist based on its publisher-assigned reference id.
        /// </summary>
        /// <param name="reference_id">
        /// The reference id of the playlist we'd like to retrieve.
        /// </param>
        /// <param name="video_fields">
        /// A comma-separated list of the fields you wish to have populated in the videos contained in the returned object. Passing null populates with all fields. (defaults to all)
        /// </param>
        /// <param name="custom_fields">
        /// A comma-separated list of the custom fields you wish to have populated in the videos contained in the returned object. Passing null populates with all fields. (defaults to all)
        /// </param>
        /// <param name="playlist_fields">
        /// A comma-separated list of the fields you wish to have populated in the playlists contained in the returned object. Passing null populates with all fields.
        /// </param>
        /// <returns>
        /// Returns a BCPlaylist item
        /// </returns>
        public BCPlaylist FindPlaylistByReferenceId(string reference_id, List <VideoFields> video_fields, List <string> custom_fields, List <PlaylistFields> playlist_fields, MediaDeliveryTypeEnum media_delivery)
        {
            Dictionary <String, String> reqparams = new Dictionary <string, string>();

            //Build the REST parameter list
            reqparams.Add("command", "find_playlist_by_reference_id");
            reqparams.Add("reference_id", reference_id);
            reqparams.Add("media_delivery", media_delivery.ToString());
            if (playlist_fields != null)
            {
                reqparams.Add("playlist_fields", playlist_fields.ToFieldString());
            }
            if (video_fields != null)
            {
                reqparams.Add("video_fields", video_fields.ToFieldString());
            }
            if (custom_fields != null)
            {
                reqparams.Add("custom_fields", Implode(custom_fields));
            }

            //Get the JSon reader returned from the APIRequest
            string jsonStr = BCAPIRequest.ExecuteRead(reqparams, Account).JsonResult;

            return(JSON.Converter.Deserialize <BCPlaylist>(jsonStr));
        }
Exemple #2
0
        private static void MakeRequest(BCQueryResult qr, Dictionary <string, string> reqparams, BCObjectType itemType, BCAccount account)
        {
            QueryResultPair qrp = BCAPIRequest.ExecuteRead(reqparams, account);

            qrp.JsonResult = qrp.JsonResult.Replace("\"items\":", "\"" + itemType.ToString() + "\":");
            qr.QueryResults.Add(qrp);
            qr.Merge(JSON.Converter.Deserialize <BCQueryResult>(qrp.JsonResult));
        }
        private static BCQueryResult MultipleQueryHandler(Dictionary <String, String> reqparams, BCObjectType itemType, AccountConfigElement account)
        {
            //Get the JSon reader returned from the APIRequest
            BCQueryResult qr = new BCQueryResult();

            qr.TotalCount = 0;

            try {
                //set some global request paramameters
                if (!reqparams.ContainsKey("page_number"))
                {
                    reqparams.Add("page_number", "0");
                }

                //set if not set or
                if (!reqparams.ContainsKey("page_size"))
                {
                    qr.MaxToGet = -1;
                }
                else
                {
                    qr.MaxToGet = Convert.ToInt32(reqparams["page_size"]);
                }

                //get initial query
                double maxPageNum = 0;

                QueryResultPair qrp = BCAPIRequest.ExecuteRead(reqparams, account);
                //convert the result for deserialization
                qrp.JsonResult = qrp.JsonResult.Replace("\"items\":", "\"" + itemType.ToString() + "\":");
                qr.QueryResults.Add(qrp);
                qr.Merge(JSON.Converter.Deserialize <BCQueryResult>(qrp.JsonResult));

                //make sure you get the correct page num
                if (qr.TotalCount > 0)
                {
                    //if you want all use the total count to calculate the number of pages
                    if (qr.MaxToGet.Equals(-1))
                    {
                        maxPageNum = Math.Ceiling((double)(qr.TotalCount / 100));
                    }
                    //or just use the max you want to calculate the number of pages
                    else
                    {
                        maxPageNum = Math.Ceiling((double)(qr.MaxToGet / 100));
                    }
                }

                //if there are more to get move to next page and keep getting them
                for (int pageNum = 1; pageNum <= maxPageNum; pageNum++)
                {
                    //update page each iteration
                    reqparams["page_number"] = pageNum.ToString();

                    QueryResultPair qrp2 = BCAPIRequest.ExecuteRead(reqparams, account);
                    //convert the result for deserialization
                    qrp2.JsonResult = qrp2.JsonResult.Replace("\"items\":", "\"" + itemType.ToString() + "\":");
                    qr.QueryResults.Add(qrp2);
                    qr.Merge(JSON.Converter.Deserialize <BCQueryResult>(qrp2.JsonResult));
                }

                //sorting on our end

                if (itemType.Equals(BCObjectType.videos) && reqparams.ContainsKey("sort_by"))
                {
                    //PUBLISH_DATE,
                    if (reqparams["sort_by"].Equals("PUBLISH_DATE"))
                    {
                        qr.Videos.Sort(BCVideo.PublishDateComparison);
                    }
                    //PLAYS_TOTAL,
                    else if (reqparams["sort_by"].Equals("PLAYS_TOTAL"))
                    {
                        qr.Videos.Sort(BCVideo.TotalPlaysComparison);
                    }
                    //PLAYS_TRAILING_WEEK
                    else if (reqparams["sort_by"].Equals("PLAYS_TRAILING_WEEK"))
                    {
                        qr.Videos.Sort(BCVideo.PlaysTrailingComparison);
                    }
                    //MODIFIED_DATE,
                    else if (reqparams["sort_by"].Equals("MODIFIED_DATE"))
                    {
                        qr.Videos.Sort(BCVideo.ModifiedDateComparison);
                    }
                    //CREATION_DATE,
                    else
                    {
                        qr.Videos.Sort(BCVideo.CreationDateComparison);
                    }

                    //if they want asc
                    if (reqparams["sort_order"].Equals("DESC"))
                    {
                        qr.Videos.Reverse();
                    }

                    //trim if specified
                    if (qr.Videos.Count > qr.MaxToGet && !qr.MaxToGet.Equals(-1) && qr.MaxToGet < qr.TotalCount)
                    {
                        List <BCVideo> vidTemp = qr.Videos.GetRange(0, Convert.ToInt32(qr.MaxToGet));

                        qr.Videos.Clear();
                        qr.Videos.AddRange(vidTemp);
                    }
                }
            }
            catch (Exception ex) {
                throw new Exception(ex.ToString());
            }

            return(qr);
        }