Esempio n. 1
0
        public async Task <string> PostEnqueueExportWorkspaceTaskAsync(string workspaceId)
        {
            var request = new EnqueueTaskExportSpaceRequest(workspaceId);
            var result  = await MakePostRequestWithRetriesAsync <EnqueueTaskExportSpaceRequest, EnqueueTaskResult>(
                "enqueueTask",
                request).ConfigureAwait(false);

            if (result.TaskId == null)
            {
                throw new WebException(
                          $"Notion did not return task id for request {JsonSerializer.SerializeObject(request)}");
            }

            return(result.TaskId);
        }
Esempio n. 2
0
        public static void InitConfig(string configRaw)
        {
            var dto = JsonSerializer.DeserializeObject <ConfigDto>(configRaw);

            ValidateConfig(dto);

            ApplicationEnvironment = dto !.ApplicationEnvironment !.Value;
            NotionTokenV2          = dto !.NotionTokenV2 !;
            DropboxAccessToken     = dto !.DropboxAccessToken !;
            NotionWorkspaceId      = dto !.NotionWorkspaceId !;
            UserName  = dto !.UserName !;
            LogPath   = dto !.LogPath !;
            RawConfig = dto;

            RawConfig.DropboxAccessToken = "SECRET";
            RawConfig.NotionTokenV2      = "SECRET";
            RawConfig.UserName           = "******";
            RawConfig.NotionWorkspaceId  = "SECRET";
        }
Esempio n. 3
0
        private async Task <TContentResult> MakePostRequestWithRetriesAsync <TRequest, TContentResult>(string relativeUrl,
                                                                                                       TRequest request) where TContentResult : class
        {
            var result = await ExecuteWithRetriesAsync(async() => await httpClient.SendAsync(
                                                           new HttpRequestMessage(HttpMethod.Post, $"{BaseUrl}/{relativeUrl}")
            {
                Content = new StringContent(JsonSerializer.SerializeObject(request),
                                            Encoding.UTF8, "application/json")
            }).ConfigureAwait(false)).ConfigureAwait(false);

            if (result.StatusCode != HttpStatusCode.OK)
            {
                throw new WebException($"HTTP request unsuccessful. {result}");
            }

            var contentResult = await ExecuteWithRetriesAsync(
                async() => JsonSerializer.DeserializeObject <TContentResult>(await result.Content
                                                                             .ReadAsStringAsync().ConfigureAwait(false))).ConfigureAwait(false);

            return(contentResult !);
        }
Esempio n. 4
0
 public static string ToPrettyJson()
 {
     return(JsonSerializer.SerializeObject(RawConfig));
 }