Ejemplo n.º 1
0
        public static async ValueTask <Block> GetLocateAsync(HttpClient client, WebsiteKind websiteKind,
                                                             Uri locateUri, double apiVersion = Core.ApiVersion)
        {
            var response = await GetLocateResponseAsync(client, websiteKind, locateUri, apiVersion).ConfigureAwait(false);

            return(await Core.DeserializeOsnovaResponseAsync <Block>(response).ConfigureAwait(false));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets an URL to get more events
        /// <para/>
        /// <remarks>Original name: getEventsMore</remarks>
        /// </summary>
        /// <param name="websiteKind">Kind of website</param>
        /// <param name="lastId">Last event's ID of previous query</param>
        /// <param name="cityId">City ID</param>
        /// <param name="specializationIds">Specialization ID's collection</param>
        /// <param name="apiVersion">Target version of API</param>
        /// <returns>Ready URL, e.g.: https://api.vc.ru/v1.9/events/more/0?city_id=0</returns>
        public static Uri GetMoreEventsUri(WebsiteKind websiteKind, int lastId = 0, int cityId           = -1,
                                           IEnumerable <int> specializationIds = null, double apiVersion = Core.ApiVersion)
        {
            string relative = $"more/{lastId}";

            var baseUri = GetDefaultEventsUrl(websiteKind, apiVersion);

            UriBuilder builder = new($"{baseUri}/{relative}");

            string specIds = null;

            if (specializationIds != null)
            {
                foreach (int id in specializationIds)
                {
                    if (string.IsNullOrWhiteSpace(specIds))
                    {
                        specIds = $"{id}";
                    }
                    else
                    {
                        specIds += $",{id}";
                    }
                }
            }

            string cityString            = cityId > -1 ? $"city_id={cityId}" : null;
            string specializationsString = string.IsNullOrWhiteSpace(specIds) ? null : $"specialization_ids={specIds}";

            Core.BuildUri(ref builder, cityString, specializationsString);

            return(builder.Uri);
        }
Ejemplo n.º 3
0
        public static async ValueTask DownloadAllEntryImages(HttpClient client, WebsiteKind websiteKind,
                                                             int entryId, string outputPath,
                                                             double apiVersion           = Core.ApiVersion,
                                                             IProgress <double> progress = null)
        {
            Directory.CreateDirectory(outputPath);

            var entry = await Entry.GetEntryAsync(client, websiteKind, entryId, apiVersion).ConfigureAwait(false);

            var imageDatas = new List <ImageBlockData>();

            foreach (MediaBlock block in entry.Blocks.Where(block => block is MediaBlock))
            {
                imageDatas.AddRange(block.GetImageDatas());
            }

            double counter = 0.0;

            foreach (var imageData in imageDatas)
            {
                var    guid      = imageData.Uuid;
                string extension = imageData.Extension.ToString().ToLowerInvariant();
                var    itemUri   = Core.GetMediaUri(guid);

                var bytes = await client.GetByteArrayAsync(itemUri).ConfigureAwait(false);

                await File.WriteAllBytesAsync(Path.Combine(outputPath, $"{guid}.{extension}"), bytes).ConfigureAwait(false);

                // Report progress
                counter++;
                double percentage = counter / imageDatas.Count * 100.0;
                progress?.Report(percentage);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets quiz results
        /// <para/>
        /// <remarks>Original name: getQuizResults</remarks>
        /// </summary>
        /// <param name="client">Client to send requests</param>
        /// <param name="websiteKind">Kind of website</param>
        /// <param name="quizHash">Quiz hash</param>
        /// <param name="apiVersion">Target version of API</param>
        /// <returns>Requested quiz's results</returns>
        public static async ValueTask <Quiz> GetQuizResultsAsync(HttpClient client, WebsiteKind websiteKind, string quizHash,
                                                                 double apiVersion = Core.ApiVersion)
        {
            using var response = await GetQuizResultsResponseAsync(client, websiteKind, quizHash, apiVersion).ConfigureAwait(false);

            return(await Core.DeserializeOsnovaResponseAsync <Quiz>(response).ConfigureAwait(false));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets an URL to get likers of specified comment
        /// <para/>
        /// <remarks>Original name: getCommentLikersUri</remarks>
        /// </summary>
        /// <param name="websiteKind">Kind of website</param>
        /// <param name="commentId">Comment id</param>
        /// <param name="apiVersion">Target version of API</param>
        /// <returns>Ready URL, e.g.: https://api.dtf.ru/v1.9/comment/likers/0</returns>
        public static Uri GetCommentLikersUri(WebsiteKind websiteKind, int commentId, double apiVersion = Core.ApiVersion)
        {
            var relative = $"likers/{commentId}";

            var baseUri = GetDefaultCommentUrl(websiteKind, apiVersion);

            return(new Uri($"{baseUri}/{relative}"));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets an URL to post entry
        /// <para/>
        /// <remarks>Original name: postEntryCreate</remarks>
        /// </summary>
        /// <param name="websiteKind">Kind of website</param>
        /// <param name="apiVersion">Target version of API</param>
        /// <returns>Ready URL, e.g.: https://api.dtf.ru/v1.9/entry/create</returns>
        public static Uri GetEntryCreateUri(WebsiteKind websiteKind, double apiVersion = Core.ApiVersion)
        {
            const string relative = "create";

            var baseUri = GetDefaultEntryUrl(websiteKind, apiVersion);

            return(new Uri($"{baseUri}/{relative}"));
        }
Ejemplo n.º 7
0
        // TODO: the same version, as API? Test this
        public static Uri GetLayoutUri(WebsiteKind websiteKind, double version, double apiVersion = Core.ApiVersion)
        {
            var relative = $"{version}";

            var baseUri = GetDefaultLayoutUrl(websiteKind, apiVersion);

            return(new Uri($"{baseUri}/{relative}"));
        }
Ejemplo n.º 8
0
        // TODO: use use enums for city id/spec id if possible

        #region GET

        #region GetEventsFilters

        /// <summary>
        /// Gets an URL to get event filters
        /// <para/>
        /// <remarks>Original name: getEventsFilters</remarks>
        /// </summary>
        /// <param name="websiteKind">Kind of website</param>
        /// <param name="apiVersion">Target version of API</param>
        /// <returns>Ready URL, e.g.: https://api.dtf.ru/v1.9/events/filters</returns>
        public static Uri GetEventsFiltersUri(WebsiteKind websiteKind, double apiVersion = Core.ApiVersion)
        {
            const string relative = "filters";

            var baseUri = GetDefaultEventsUrl(websiteKind, apiVersion);

            return(new Uri($"{baseUri}/{relative}"));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets an URL to get quiz results
        /// <para/>
        /// <remarks>Original name: getQuizResults</remarks>
        /// </summary>
        /// <param name="websiteKind">Kind of website</param>
        /// <param name="quizHash">Quiz hash</param>
        /// <param name="apiVersion">Target version of API</param>
        /// <returns>Ready URL, e.g.: https://api.dtf.ru/v1.9/quiz/hash/results</returns>
        public static Uri GetQuizResultsUri(WebsiteKind websiteKind, string quizHash, double apiVersion = Core.ApiVersion)
        {
            string relative = $"{quizHash}/results";

            var baseUri = GetDefaultQuizUrl(websiteKind, apiVersion);

            return(new Uri($"{baseUri}/{relative}"));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Gets an URL to get thread for specified comment
        /// <para/>
        /// <remarks>Original name: getEntryCommentsThread</remarks>
        /// </summary>
        /// <param name="websiteKind">Kind of website</param>
        /// <param name="entryId">Entry id</param>
        /// <param name="commentId">Comment id</param>
        /// <param name="apiVersion">Target version of API</param>
        /// <returns>Ready URL, e.g.: https://api.dtf.ru/v1.9/entry/0/comments/thread/0</returns>
        public static Uri GetCommentThreadUri(WebsiteKind websiteKind, int entryId, int commentId, double apiVersion = Core.ApiVersion)
        {
            var relative = $"{entryId}/comments/thread/{commentId}";

            var baseUri = GetDefaultEntryUrl(websiteKind, apiVersion);

            return(new Uri($"{baseUri}/{relative}"));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets an URL to get entry by it's URL
        /// <para/>
        /// <remarks>Original name: getEntryLocate</remarks>
        /// </summary>
        /// <param name="websiteKind">Kind of website</param>
        /// <param name="entryUri">Entry's URL</param>
        /// <param name="apiVersion">Target version of API</param>
        /// <returns>Ready URL, e.g.: https://api.dtf.ru/v1.9/entry/locate?url=https://dtf.ru/0</returns>
        public static Uri GetEntryLocateUri(WebsiteKind websiteKind, Uri entryUri, double apiVersion = Core.ApiVersion)
        {
            // return new Uri(GetDefaultEntryUrl(websiteKind, apiVersion), $"{entryId}/popular");
            var baseUri = Core.GetBaseUri(websiteKind, apiVersion);

            // TODO: UriBuilder
            return(new Uri($"{baseUri}/entry/locate?url={entryUri}"));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Gets an URL to get comments threads
        /// <para/>
        /// <remarks>Original name: getEntryCommentsLevels</remarks>
        /// </summary>
        /// <param name="websiteKind">Kind of website</param>
        /// <param name="entryId">Entry id</param>
        /// <param name="sorting">Sorting of comments</param>
        /// <param name="apiVersion">Target version of API</param>
        /// <returns>Ready URL, e.g.: https://api.dtf.ru/v1.9/entry/0/comments/levels/date</returns>
        public static Uri GetCommentsThreadsUri(WebsiteKind websiteKind, int entryId, CommentSorting sorting = CommentSorting.Date, double apiVersion = Core.ApiVersion)
        {
            var relative = $"{entryId}/comments/levels/{sorting.ToString().ToLowerInvariant()}";

            var baseUri = GetDefaultEntryUrl(websiteKind, apiVersion);

            return(new Uri($"{baseUri}/{relative}"));
        }
Ejemplo n.º 13
0
        // TODO: why is there entry id in params?

        /// <summary>
        /// Gets an URL to get popular entries, similar to specified id
        /// <para/>
        /// <remarks>Original name: getPopularEntries</remarks>
        /// </summary>
        /// <param name="websiteKind">Kind of website</param>
        /// <param name="entryId">Entry id</param>
        /// <param name="apiVersion">Target version of API</param>
        /// <returns>Ready URL, e.g.: https://api.dtf.ru/v1.9/entry/0/popular</returns>
        public static Uri GetPopularEntriesUri(WebsiteKind websiteKind, int entryId, double apiVersion = Core.ApiVersion)
        {
            var relative = $"{entryId}/popular";

            var baseUri = GetDefaultEntryUrl(websiteKind, apiVersion);

            return(new Uri($"{baseUri}/{relative}"));
        }
Ejemplo n.º 14
0
        public static Uri GetTagUri(WebsiteKind websiteKind, string tag, long lastId, double apiVersion = Core.ApiVersion)
        {
            var baseUri = Core.GetBaseUri(websiteKind, apiVersion);

            UriBuilder builder = new($"{baseUri}/tag/{tag}");

            string queryString = $"last_id={lastId}";

            Core.BuildUri(ref builder, queryString);

            return(builder.Uri);
        }
Ejemplo n.º 15
0
        public static Uri GetSearchHashtagUri(WebsiteKind websiteKind, string query, double apiVersion = Core.ApiVersion)
        {
            var baseUri = Core.GetBaseUri(websiteKind, apiVersion);

            UriBuilder builder = new($"{baseUri}/search-hashtag");

            string queryString = $"q={query}";

            Core.BuildUri(ref builder, queryString);

            return(builder.Uri);
        }
Ejemplo n.º 16
0
        public static Uri GetLocateUri(WebsiteKind websiteKind, Uri locateUri, double apiVersion = Core.ApiVersion)
        {
            var baseUri = Core.GetBaseUri(websiteKind, apiVersion);

            UriBuilder builder = new($"{baseUri}/locate");

            string locateUriString = $"url={locateUri}";

            Core.BuildUri(ref builder, locateUriString);

            return(builder.Uri);
        }
Ejemplo n.º 17
0
        public static Uri GetLayoutHashtagUri(WebsiteKind websiteKind, string hashtag, double apiVersion = Core.ApiVersion)
        {
            //var baseUri = Core.GetBaseUri(websiteKind, apiVersion);

            //// TODO: original uri: /layout/hashtag/{hashtag} doesn't work at all
            //// TODO: isn't it the SAME as GetLayout?
            //return new Uri($"{baseUri}/layout/{hashtag}");

            var relative = hashtag;

            var baseUri = GetDefaultLayoutUrl(websiteKind, apiVersion);

            return(new Uri($"{baseUri}/{relative}"));
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Gets tweets URL
        /// </summary>
        /// <param name="websiteKind">Kind of website</param>
        /// <param name="tweetSorting">Sorting of tweets</param>
        /// <param name="count">Count of tweets</param>
        /// <param name="offset">Tweet offset</param>
        /// <param name="apiVersion">Target version of API</param>
        /// <returns>Ready URL, e.g.: https://api.dtf.ru/v1.9/tweets/fresh?count=10</returns>
        public static Uri GetTweetsUri(WebsiteKind websiteKind, TweetSorting tweetSorting = TweetSorting.Fresh,
                                       int count = -1, int offset = -1, double apiVersion = Core.ApiVersion)
        {
            var baseUri = Core.GetBaseUri(websiteKind, apiVersion);

            UriBuilder builder = new($"{baseUri}/tweets/{tweetSorting.ToString().ToLowerInvariant()}");

            string countQuery  = count > -1 ? $"count={count}" : null;
            string offsetQuery = offset > -1 ? $"offset={offset}" : null;

            Core.BuildUri(ref builder, countQuery, offsetQuery);

            return(builder.Uri);
        }
Ejemplo n.º 19
0
        public static Uri GetBaseUri(WebsiteKind websiteKind, double apiVersion)
        {
            string invariantVersion = apiVersion.ToString(CultureInfo.InvariantCulture);

            var baseString = websiteKind switch
            {
                WebsiteKind.Dtf => BaseDtfUriString,
                WebsiteKind.Tjournal => BaseTjournalUriString,
                WebsiteKind.Vc => BaseVcUriString,
                _ => throw new NotSupportedException()
            };

            return(new Uri($"{baseString}/v{invariantVersion}"));
        }
Ejemplo n.º 20
0
        public static Uri GetTimelineNewsUri(WebsiteKind websiteKind, TimelineSorting sorting,
                                             int count = -1, int offset = -1, double apiVersion = Core.ApiVersion)
        {
            var baseUri = Core.GetBaseUri(websiteKind, apiVersion);

            UriBuilder builder = new($"{baseUri}/news/default/{sorting}");

            string countQuery  = count > -1 ? $"count={count}" : null;
            string offsetQuery = offset > -1 ? $"offset={offset}" : null;

            Core.BuildUri(ref builder, countQuery, offsetQuery);

            return(builder.Uri);
        }
Ejemplo n.º 21
0
        // TODO: test with orderby and page
        public static Uri GetSearchSubsiteUri(WebsiteKind websiteKind, string query, double apiVersion = Core.ApiVersion)
        {
            var baseUri = Core.GetBaseUri(websiteKind, apiVersion);

            UriBuilder builder = new($"{baseUri}/search-subsite");

            string queryString = $"q={query}";

            //string orderByString = $"order_by={orderBy.ToString().ToLowerInvariant()}";
            //string pageString = page > 0 ? $"page={page}" : null;

            Core.BuildUri(ref builder, queryString); //, orderByString, pageString);

            return(builder.Uri);
        }
Ejemplo n.º 22
0
        public static Uri GetTimelineByHashtagUri(WebsiteKind websiteKind, string hashtag,
                                                  TimelineCategory category = TimelineCategory.MainPage, TimelineSorting sorting = TimelineSorting.Recent,
                                                  int limit = -1, int lastId = -1, double apiVersion = Core.ApiVersion)
        {
            var baseUri = Core.GetBaseUri(websiteKind, apiVersion);

            UriBuilder builder = new($"{baseUri}/timeline/{category}/{sorting}");

            string limitQuery  = limit > -1 ? $"limit={limit}" : null;
            string lastIdQuery = lastId > -1 ? $"last_id={lastId}" : null;

            Core.BuildUri(ref builder, hashtag, limitQuery, lastIdQuery);

            return(builder.Uri);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Gets webhooks
        /// <para/>
        /// <remarks>Requires authentication!
        /// <para/>
        /// Original name: getApiWebhooksGet</remarks>
        /// </summary>
        /// <param name="client">Client to send requests</param>
        /// <param name="websiteKind">Kind of website</param>
        /// <param name="apiVersion">Target version of API</param>
        /// <returns>Collection of webhooks</returns>
        public static async ValueTask <IEnumerable <WebhookWatcher> > GetWebhooksAsync(HttpClient client, WebsiteKind websiteKind,
                                                                                       double apiVersion = Core.ApiVersion)
        {
            using var response = await GetWebhooksResponseAsync(client, websiteKind, apiVersion).ConfigureAwait(false);

            return(await Core.DeserializeOsnovaResponseAsync <IEnumerable <WebhookWatcher> >(response).ConfigureAwait(false));
        }
Ejemplo n.º 24
0
 /// <inheritdoc cref="GetWebhooksAsync"/>
 public static ValueTask <HttpResponseMessage> GetWebhooksResponseAsync(HttpClient client, WebsiteKind websiteKind,
                                                                        double apiVersion = Core.ApiVersion)
 {
     return(Core.GetResponseFromApiAsync(client, GetWebhooksGetUri(websiteKind, apiVersion)));
 }
Ejemplo n.º 25
0
        /// <summary>
        /// Gets an URL to get webhooks "get" url
        /// <para/>
        /// <remarks>Original name: getApiWebhooksGet</remarks>
        /// </summary>
        /// <param name="websiteKind">Kind of website</param>
        /// <param name="apiVersion">Target version of API</param>
        /// <returns>Ready URL, e.g.: https://api.dtf.ru/v1.9/webhooks/get</returns>
        public static Uri GetWebhooksGetUri(WebsiteKind websiteKind, double apiVersion = Core.ApiVersion)
        {
            var baseUri = GetDefaultWebhooksUrl(websiteKind, apiVersion);

            return(new Uri($"{baseUri}/get"));
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Returns bool, that shows, if webhook is removed
        /// <para/>
        /// <remarks>Requires authentication!
        /// <para/>
        /// Original name: getApiWebhooksDel</remarks>
        /// </summary>
        /// <param name="client">Client to send requests</param>
        /// <param name="websiteKind">Kind of website</param>
        /// <param name="eventName">Event name</param>
        /// <param name="apiVersion">Target version of API</param>
        /// <returns>Is removed successfully?</returns>

        // TODO: WebhookWatcher overload
        public static async ValueTask <bool> PostWebhooksDeleteAsync(HttpClient client, WebsiteKind websiteKind,
                                                                     string eventName, double apiVersion = Core.ApiVersion)
        {
            using var response = await PostWebhooksDeleteResponseAsync(client, websiteKind, eventName, apiVersion).ConfigureAwait(false);

            var deserialized = await Core.DeserializeOsnovaResponseAsync <Dictionary <string, bool> >(response).ConfigureAwait(false);

            return(deserialized["success"]);
        }
Ejemplo n.º 27
0
        /// <inheritdoc cref="PostWebhooksDeleteAsync"/>
        public static async ValueTask <HttpResponseMessage> PostWebhooksDeleteResponseAsync(HttpClient client, WebsiteKind websiteKind,
                                                                                            string eventName, double apiVersion = Core.ApiVersion)
        {
            var eventContent   = new StringContent(eventName);
            var requestContent = new MultipartFormDataContent
            {
                { eventContent, "\"event\"" }
            };

            var response = await Core.PostToApiAsync(client, GetWebhooksDeleteUri(websiteKind, apiVersion), requestContent).ConfigureAwait(false);

            Core.DisposeHttpContents(eventContent, requestContent);

            return(response);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Add webhook
        /// <para/>
        /// <remarks>Requires authentication!
        /// <para/>
        /// Original name: getApiWebhooksAdd</remarks>
        /// </summary>
        /// <param name="client">Client to send requests</param>
        /// <param name="websiteKind">Kind of website</param>
        /// <param name="url">URL</param>
        /// <param name="eventName">Event name</param>
        /// <param name="apiVersion">Target version of API</param>
        /// <returns>Collection of added webhooks</returns>

        // TODO: WebhookWatcher overload
        public static async ValueTask <WebhookWatcher> PostWebhooksAddAsync(HttpClient client, WebsiteKind websiteKind,
                                                                            Uri url, string eventName, double apiVersion = Core.ApiVersion)
        {
            using var response = await PostWebhooksAddResponseAsync(client, websiteKind, url, eventName, apiVersion).ConfigureAwait(false);

            return(await Core.DeserializeOsnovaResponseAsync <WebhookWatcher>(response).ConfigureAwait(false));
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Gets more events
        /// <para/>
        /// <remarks>Original name: getEventsMore</remarks>
        /// </summary>
        /// <param name="client">Client to send requests</param>
        /// <param name="websiteKind">Kind of website</param>
        /// <param name="lastId">Last event's ID of previous query</param>
        /// <param name="cityId">City ID</param>
        /// <param name="specializationIds">Specialization ID's collection</param>
        /// <param name="apiVersion">Target version of API</param>
        /// <returns>Requested events</returns>
        public static async ValueTask <IEnumerable <OsnovaEvent> > GetMoreEventsAsync(HttpClient client, WebsiteKind websiteKind, int lastId = 0,
                                                                                      int cityId = -1, IEnumerable <int> specializationIds = null, double apiVersion = Core.ApiVersion)
        {
            var response = await GetMoreEventsResponseAsync(client, websiteKind, lastId, cityId, specializationIds, apiVersion).ConfigureAwait(false);

            var searchResult = await Core.DeserializeOsnovaResponseAsync <SearchResult <OsnovaEvent> >(response).ConfigureAwait(false);

            return(searchResult.Items);
        }
Ejemplo n.º 30
0
 /// <inheritdoc cref="GetMoreEventsAsync"/>
 public static ValueTask <HttpResponseMessage> GetMoreEventsResponseAsync(HttpClient client, WebsiteKind websiteKind, int lastId = 0,
                                                                          int cityId = -1, IEnumerable <int> specializationIds = null, double apiVersion = Core.ApiVersion)
 {
     return(Core.GetResponseFromApiAsync(client, GetMoreEventsUri(websiteKind, lastId, cityId, specializationIds, apiVersion)));
 }