Ejemplo n.º 1
0
        void Awake()
        {
            monoRef = this;
            DontDestroyOnLoad(this);

            programsEndpoint = RequestBuilder.AddParametersToURL(programsURL + "?", new Dictionary <string, string>()
            {
                { "app_id", appID },
                { "app_key", appKey }
            });

            categoriesEndpoint = RequestBuilder.AddParametersToURL(categoriesURL + "?", new Dictionary <string, string>()
            {
                { "app_id", appID },
                { "app_key", appKey }
            });

            //Debug.Log("<color=blue>YleSDKManager | Programs Endpoint: \'" + programsEndpoint + "\'</color>");
            //Debug.Log("<color=blue>YleSDKManager | Categories Endpoint: \'" + categoriesEndpoint + "\'</color>");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the programs list specified by a couple of optional parameters.
        /// </summary>
        /// <param name="onComplete">On complete.</param>
        /// <param name="offset">Offset.</param>
        /// <param name="limit">Limit.</param>
        /// <param name="categoryKey">Category key.</param>
        /// <param name="programType">Program type.</param>
        /// <param name="mediaObjectType">Media object type.</param>
        public static void GetProgramsList(System.Action <IList <ProgramData> > onComplete, int offset = 0, int limit = 10, string categoryKey = null, ProgramType programType = ProgramType.all, MediaObjectType mediaObjectType = MediaObjectType.all)
        {
            if (!Initialized)
            {
                if (onComplete != null)
                {
                    onComplete(null);
                }

                return;
            }

            string formattedURL = RequestBuilder.AddParametersToURL(programsEndpoint, new Dictionary <string, string>()
            {
                { "offset", offset.ToString() },
                { "limit", limit.ToString() }
            });

            string categoryID = GetCategoryCode(categoryKey);

            if (!string.IsNullOrEmpty(categoryID))
            {
                formattedURL = RequestBuilder.AddParameterToURL(formattedURL, "category", System.Uri.EscapeDataString(categoryID));
            }

            if (programType != ProgramType.all)
            {
                formattedURL = RequestBuilder.AddParameterToURL(formattedURL, "type", programType.ToString());
            }

            if (mediaObjectType != MediaObjectType.all)
            {
                formattedURL = RequestBuilder.AddParameterToURL(formattedURL, "mediaobject", mediaObjectType.ToString());
            }

            RequestBuilder.Inst.NewWebRequest(formattedURL, HttpMethod.GET, delegate(WebResponse response) {
                if (!response.Success)
                {
                    Debug.Log("<color=yellow>YleSDKManager.GetProgramsList | Error:" + response.GetResponseMap().GetValue <string>("error") + "</color>");
                }
                else
                {
                    Debug.Log("<color=purple>YleSDKManager.GetProgramsList | Api:" + response.GetResponseMap().GetValue <string>("apiVersion") + "</color>");

                    IList <ProgramData> returnVal = new List <ProgramData>();
                    IDictionary <string, object>[] dataMapCollection = response.GetResponseMap().GetHashCollection("data");

                    if (dataMapCollection != null)
                    {
                        for (int i = 0; i < dataMapCollection.Length; i++)
                        {
                            ProgramData pd = new ProgramData(dataMapCollection[i]);
                            returnVal.Add(pd);
                        }
                    }

                    if (onComplete != null)
                    {
                        onComplete(returnVal);
                    }
                }
            });
        }