Пример #1
0
        private RestCall BuildRestCall(TextTranslationRequest request)
        {
            var apiKey  = _settingsProvider.ProvideSettings().DeeplApiKey;
            var builder = _restCallBuilderFactory
                          .StartBuilding(new Uri("https://api.deepl.com/v2/translate"), RestCallMethodType.Post);

            var queryParamBuilder = builder.WithQueryParameters()
                                    .WithQueryParameter("auth_key", apiKey)
                                    .WithQueryParameter("target_lang", request.TargetLanguage.Code);

            request.SourceLanguage.Evaluate(language =>
            {
                queryParamBuilder.WithQueryParameter("source_lang", language.Code);
            });

            request.ApplyIgnoreMarkUp(queryParamBuilder);
            request.TextParts.ForEach(tp =>
            {
                queryParamBuilder.WithQueryParameter("text", tp.Text);
            });

            builder = queryParamBuilder.BuildQueryParameters();

            return(builder.Build());
        }
Пример #2
0
        public async Task <IActionResult> GetPersonalInfos()
        {
            var uri      = new Uri("https://api.linkedin.com/v2/me");
            var restCall = _restCallBuilderFactory.StartBuilding(uri)
                           .WithSecurity(RestSecurity.CreateTokenSecurity("Bearer " + LinkedInAccessTokenSingleton.Value))
                           .Build();

            var tra = await _restProxy.PerformCallAsync <string>(restCall);

            return(Ok());
        }
        public async Task <RestCall> CreateAsync(TranslationRequestDto request)
        {
            var resourcePath = CreateResourcePath(request);
            var token        = await _authorizationTokenFactory.CreateAuthorizationTokenAsync();

            return(_restCallBuilderFactory
                   .StartBuilding(_translationBaseUrl, RestCallMethodType.Post)
                   .WithResourcePath(resourcePath)
                   .WithSecurity(RestSecurity.CreateTokenSecurity(token))
                   .WithBody(new RestCallBody(request.Entries))
                   .Build());
        }
        private RestCall BuildRestCall(TranslationRequest request)
        {
            var builder = _restCallBuilderFactory
                          .StartBuilding(_deeplApiUrl, RestCallMethodType.Post);

            var queryParamBuilder = builder.WithQueryParameters()
                                    .WithQueryParameter("auth_key", _settingsProvider.Settings.DeeplApiKey)
                                    .WithQueryParameter("target_lang", request.TargetLanguage.Code);

            ApplySourceLanguage(request, queryParamBuilder);
            ApplyTextParts(request, queryParamBuilder);
            ApplyIgnoreMarkup(request, queryParamBuilder);

            builder = queryParamBuilder.BuildQueryParameters();
            return(builder.Build());
        }
 protected IRestCallBuilder CreateBaseBuilder(string resourcePath, RestCallMethodType method)
 {
     return(_restCallBuilderFactory.StartBuilding(RestSettings.BasePath, method)
            .WithResourcePath(resourcePath)
            .WithSecurity(RestSettings.RestSecurity));
 }