Beispiel #1
0
        /// <summary>
        /// Used to get all the video from Vippy.
        /// Vippy endpoint: GET http://rest.vippy.co/videos
        /// </summary>
        /// <param name="withStatistics">Use true to get information about plays, views ..., when false default values returned</param>
        /// <returns>Collection with all videos <see cref="Video"/></returns>
        public async Task <IEnumerable <Video> > GetVideos(bool withStatistics = false)
        {
            HttpClient client   = this.GetHttpClient();
            var        response = await client.GetAsync(string.Format("/videos?statistics={0}", withStatistics ? "1" : "0")).ConfigureAwait(false);

            response.EnsureSuccessStatusCode();
            var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            return(VippyDeserializer.Deserialize <Video>(responseContent));
        }
Beispiel #2
0
        /// <summary>
        /// Used to get video from Vippy.
        /// Vippy endpoint: GET http://rest.vippy.co/video
        /// </summary>
        /// <param name="videoId">Video id</param>
        /// <param name="withStatistics">Use true to get information about plays, views ..., when false default values returned</param>
        /// <returns>Video <see cref="Video"/></returns>
        public async Task <Video> GetVideo(string videoId, bool withStatistics = false)
        {
            HttpClient client   = this.GetHttpClient();
            var        response = await client.GetAsync(string.Format("/video?videoId={0}&statistics={1}", HttpUtility.UrlEncode(videoId), withStatistics ? "1" : "0")).ConfigureAwait(false);

            response.EnsureSuccessStatusCode();
            var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            return(VippyDeserializer.Deserialize <Video>(responseContent).FirstOrDefault());
        }
Beispiel #3
0
        /// <summary>
        /// Used to get all the tags from this Vippy archive.
        /// Vippy endpoint: GET http://rest.vippy.co/archivetags
        /// </summary>
        /// <param name="archiveId">Login to vippy.co, tools -> Archives, at the bottom you have the archive number.</param>
        /// <returns>Collection with all tags <see cref="Tag"/></returns>
        public async Task <IEnumerable <Tag> > GetTags(string archiveId)
        {
            var client = this.GetHttpClient();

            var response = await client.GetAsync(string.Format("/archivetags?archive={0}", HttpUtility.UrlEncode(archiveId))).ConfigureAwait(false);

            response.EnsureSuccessStatusCode();

            var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            return(VippyDeserializer.Deserialize <ArchiveTag>(responseContent));
        }
Beispiel #4
0
        /// <summary>
        /// Used to get all the players from Vippy.
        /// Vippy endpoint: GET http://rest.vippy.co/players
        /// </summary>
        /// <returns>Collection with all players <see cref="Player"/></returns>
        public async Task <IEnumerable <Player> > GetPlayers()
        {
            var client = this.GetHttpClient();

            var response = await client.GetAsync("/players").ConfigureAwait(false);

            response.EnsureSuccessStatusCode();

            var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            return(VippyDeserializer.Deserialize <Player>(responseContent));
        }
Beispiel #5
0
        /// <summary>
        /// Used to get logo from Vippy
        /// Vippy endpoint: GET http://rest.vippy.co/logo
        /// </summary>
        /// <param name="logoId">Logo id</param>
        /// <returns>Logo <see cref="Logo"/></returns>
        public async Task <Logo> GetLogo(string logoId)
        {
            var client = this.GetHttpClient();

            var response = await client.GetAsync(string.Format("/logo?logoId={0}", HttpUtility.UrlEncode(logoId))).ConfigureAwait(false);

            response.EnsureSuccessStatusCode();

            var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            return(VippyDeserializer.Deserialize <Logo>(responseContent).FirstOrDefault());
        }
Beispiel #6
0
        /// <summary>
        /// Used to get all the thumbnails for provided videos.
        /// Vippy endpoint: GET  http://rest.vippy.co/videothumbnails
        /// </summary>
        /// <param name="videoIds">Array of video ids</param>
        /// <returns>Collection with all thumbnails <see cref="Thumbnail"/></returns>
        public async Task <IEnumerable <Thumbnail> > GetVideoThumbnails(string[] videoIds)
        {
            HttpClient client = this.GetHttpClient();

            var queryString = new StringBuilder();

            for (int i = 0; i < videoIds.Length; i++)
            {
                queryString.AppendFormat("&videoId%5B{0}%5D={1}", i, videoIds[i]);
            }

            var requestString = string.Format("/videothumbnails?{0}", queryString.ToString().TrimStart('&'));
            var response      = await client.GetAsync(requestString).ConfigureAwait(false);

            response.EnsureSuccessStatusCode();
            var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            return(VippyDeserializer.Deserialize <Thumbnail>(responseContent));
        }
Beispiel #7
0
        /// <summary>
        /// Used to get HTML code for embedding
        /// Vippy endpoint: GET http://rest.vippy.co/embedvideo
        /// </summary>
        /// <param name="getEmbedCodeRequest"><see cref="GetEmbedCodeRequest"/></param>
        /// <returns>HTML string with embed code</returns>
        public async Task <IHtmlString> GetEmbedCode(GetEmbedCodeRequest getEmbedCodeRequest)
        {
            var client = this.GetHttpClient();

            NameValueCollection queryString = HttpUtility.ParseQueryString(string.Empty);

            queryString["videoId"] = getEmbedCodeRequest.VideoId;

            if (!string.IsNullOrWhiteSpace(getEmbedCodeRequest.PlayerId))
            {
                queryString["playerId"] = getEmbedCodeRequest.PlayerId;
            }

            if (!string.IsNullOrWhiteSpace(getEmbedCodeRequest.Size))
            {
                queryString["size"] = getEmbedCodeRequest.Size;
            }

            queryString["embedcode"] = ToVippyBool(getEmbedCodeRequest.ShowEmbedCode);
            queryString["facebook"]  = ToVippyBool(getEmbedCodeRequest.EnableFacebookSharing);
            queryString["twitter"]   = ToVippyBool(getEmbedCodeRequest.EnableTwitterSharing);
            queryString["linkedin"]  = ToVippyBool(getEmbedCodeRequest.EnableLinkedInSharing);

            if (!string.IsNullOrWhiteSpace(getEmbedCodeRequest.LogoId))
            {
                queryString["logo"] = getEmbedCodeRequest.LogoId;
            }

            var response = await client.GetAsync("/embedvideo?" + queryString).ConfigureAwait(false);

            response.EnsureSuccessStatusCode();

            var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            return(new HtmlString(HttpUtility.HtmlDecode(VippyDeserializer.DeserializeItem <string>(responseContent))));
        }