示例#1
0
        private static void Jobs(OAuthAuthenticationStrategy auth)
        {
            var jobApiClient = new JobApiClient(auth, projectId);

            foreach (var job in jobApiClient.Get("ApiSample", new List <string>()
            {
                "AWAITING_AUTHORIZATION", "IN_PROGRESS", "IN_PROGRESS"
            }))
            {
                Console.WriteLine(job.jobName);
            }

            var jobRequest = new CreateJob();

            jobRequest.jobName         = "ApiSample_Job_" + Guid.NewGuid();
            jobRequest.description     = "test";
            jobRequest.dueDate         = DateTime.Now.AddMonths(1).ToString("yyyy-MM-ddTHH:mm:ssZ");
            jobRequest.targetLocaleIds = new List <string>()
            {
                "ru-RU"
            };
            jobRequest.callbackUrl     = "https://www.callback.com/smartling/job";
            jobRequest.callbackMethod  = "GET";
            jobRequest.referenceNumber = "test";

            var createdJob = jobApiClient.Create(jobRequest);

            createdJob = jobApiClient.GetById(createdJob.translationJobUid);

            var jobs      = jobApiClient.Get();
            var processes = jobApiClient.GetProcesses(jobs.First().translationJobUid);

            var updateJob = new UpdateJob();

            updateJob.jobName     = jobRequest.jobName;
            updateJob.description = "test2";
            updateJob.dueDate     = DateTime.Now.AddMonths(1).ToString("yyyy-MM-ddTHH:mm:ssZ");
            var updatedJob = jobApiClient.Update(updateJob, jobs.First().translationJobUid);

            jobs = jobApiClient.Get();
            jobApiClient.AddLocale("nl-NL", jobs.First().translationJobUid);

            var batchApiClient = new BatchApiClient(auth, projectId, String.Empty);
            var batch          =
                batchApiClient.Create(new CreateBatch()
            {
                authorize         = true,
                translationJobUid = jobs.First().translationJobUid
            });

            string filePath = "ApiSample_" + Guid.NewGuid();
            string fileUri  = "/master/" + filePath;

            batchApiClient.UploadFile(new BatchUpload.Builder().CreateUpload(@"C:\Sample.xml", fileUri, "xml", new List <string> {
                "ru-RU"
            }, batch.batchUid).WithNameSpace(filePath));
            batchApiClient.Execute(batch.batchUid);

            var batchResult = batchApiClient.Get(batch.batchUid);
        }
示例#2
0
        private static void Main(string[] args)
        {
            GetCredentials();
            var authApiClient    = new AuthApiClient(userIdentifier, userSecret);
            var auth             = new OAuthAuthenticationStrategy(authApiClient);
            var fileApiClient    = new FileApiClient(auth, projectId, string.Empty);
            var projectApiClient = new ProjectApiClient(auth, projectId);

            fileApiClient.ApiGatewayUrl = "https://api.smartling.com";
            string fileName = "ApiSample_" + Guid.NewGuid();
            string fileUri  = "/master/" + fileName;

            Upload(fileApiClient, fileUri, fileName, "xml");
            Download(fileApiClient, fileUri);
            Submissions(auth);
            Audit(auth);
            Jobs(auth);
            Published(auth);
            GetProjectData(projectApiClient);
            List(fileApiClient);
            Status(fileApiClient, fileUri, "ru-RU");
            LastModified(fileApiClient, fileUri);
            Authorization(fileApiClient);
            Deletion(fileApiClient, fileUri);
            CloudLog();

            Console.WriteLine("All done, press any key to exit");
            Console.ReadKey();
        }
示例#3
0

        
示例#4
0
        private static void Jobs(OAuthAuthenticationStrategy auth)
        {
            var jobApiClient = new JobApiClient(auth, projectId);

            foreach (var job in jobApiClient.Get("ApiSample").items)
            {
                Console.WriteLine(job.jobName);
            }

            var jobRequest = new CreateJob();

            jobRequest.jobName         = "ApiSample_Job_" + Guid.NewGuid();
            jobRequest.description     = "test";
            jobRequest.dueDate         = "2018-11-21T11:51:17Z";
            jobRequest.targetLocaleIds = new List <string>()
            {
                "ru-RU"
            };
            jobRequest.callbackUrl     = "https://www.callback.com/smartling/job";
            jobRequest.callbackMethod  = "GET";
            jobRequest.referenceNumber = "test";

            jobApiClient.Create(jobRequest);
            var jobs      = jobApiClient.GetAll();
            var processes = jobApiClient.GetProcesses(jobs.items.First().translationJobUid);

            var updateJob = new UpdateJob();

            updateJob.jobName     = jobRequest.jobName;
            updateJob.description = "test2";
            updateJob.dueDate     = "2018-11-21T11:51:17Z";
            jobApiClient.Update(updateJob, jobs.items.First().translationJobUid);
            jobs = jobApiClient.GetAll();
            jobApiClient.AddLocale("nl-NL", jobs.items.First().translationJobUid);

            var batchApiClient = new BatchApiClient(auth, projectId, String.Empty);
            var batch          =
                batchApiClient.Create(new CreateBatch()
            {
                authorize         = true,
                translationJobUid = jobs.items.First().translationJobUid
            });

            string fileUri = "ApiSample_" + Guid.NewGuid();

            batchApiClient.UploadFile(@"C:\Sample.xml", fileUri, "xml", "ru-RU", true, batch.batchUid);
            batchApiClient.Execute(batch.batchUid);

            var batchResult = batchApiClient.Get(batch.batchUid);
        }
示例#5
0
        private static void Published(OAuthAuthenticationStrategy auth)
        {
            var publishedClient = new PublishedFilesApiClient(auth, projectId);
            var search          = new RecentlyPublishedSearch(DateTime.Now.AddDays(-5));

            search.FileUris.Add("/content/Home/6A2CD795_en.xml");
            search.LocaleIds.Add("ru-RU");
            search.Limit  = 10;
            search.Offset = 0;

            var searchResults = publishedClient.GetRecentlyPublished(search);

            foreach (var item in searchResults.items)
            {
                Console.WriteLine(item.fileUri + " " + item.localeId + " " + item.publishDate);
            }
        }
        public void GetTokenShouldRefreshExpiredToken()
        {
            // Arrange
            var client = new Mock <AuthApiClient>("test", "test");

            client.CallBase = true;
            client.Setup(foo => foo.GetResponse(It.IsAny <WebRequest>())).Returns(ExpiredAuthRespone);
            client.Setup(foo => foo.PrepareJsonPostRequest(It.IsAny <string>(), It.IsAny <Object>(), It.IsAny <string>())).Returns((WebRequest)null);
            var strategy = new OAuthAuthenticationStrategy(client.Object);

            // Act
            var accessToken = strategy.GetToken();

            accessToken = strategy.GetToken();

            // Assert
            client.Verify(x => x.Authenticate(), Times.Once());
            client.Verify(x => x.Refresh(It.IsAny <string>()), Times.Once);
            Assert.AreEqual("{access token}", accessToken);
        }
        public void GetTokenShouldAuthenticateIfRefreshFailed()
        {
            // Arrange
            var client = new Mock <AuthApiClient>("test", "test");

            client.CallBase = true;
            client.Setup(foo => foo.GetResponse(It.Is <WebRequest>(x => !x.RequestUri.ToString().Contains("refresh")))).Returns(ExpiredAuthRespone);
            client.Setup(foo => foo.GetResponse(It.Is <WebRequest>(x => x.RequestUri.ToString().Contains("refresh")))).Throws(new Exception());
            client.Setup(foo => foo.PrepareJsonPostRequest(It.IsAny <string>(), It.IsAny <Object>(), It.IsAny <string>())).Returns((string x, Object y, string z) => (HttpWebRequest)WebRequest.Create(x));
            var strategy = new OAuthAuthenticationStrategy(client.Object);

            // Act
            var accessToken = strategy.GetToken();

            accessToken = strategy.GetToken();

            // Assert
            client.Verify(x => x.Authenticate(), Times.Exactly(2));
            client.Verify(x => x.Refresh(It.IsAny <string>()), Times.Once);
            Assert.AreEqual("{access token}", accessToken);
        }
示例#8
0
        private static void Audit(OAuthAuthenticationStrategy auth)
        {
            var            client = new AuditApiClient <SampleAuditLog>(auth, projectId);
            var            itemId = Guid.NewGuid().ToString();
            SampleAuditLog log    = new SampleAuditLogBuilder("sandbox2", "UPLOAD", "testuser", itemId, "test_uri", "/sitecore/content")
                                    .WithJob("test_job", "aabbcc", "batch1")
                                    .WithSourceVersion(1)
                                    .WithSourceLocale("en")
                                    .WithTargetLocale("ru-RU");

            client.Create(log);

            // Wait for audit log to be created and processed
            Thread.Sleep(1000);

            var query = new Dictionary <string, string>();

            query.Add("clientData.ItemId|clientData.Path", itemId);
            query.Add("sourceLocaleId", "en|ru");
            query.Add("envId", "sandbox2");

            var logs = client.Get(query, "_id:desc");
        }
示例#9
0
        private static void Submissions(OAuthAuthenticationStrategy auth)
        {
            var client = new SubmissionApiClient <SampleOriginalAssetKey, SampleCustomTranslationRequestData, SampleTargetAssetKey, SampleCustomSubmissionData>(auth, projectId, "1e65ee5c-2555-4fd4-8305-56228ee3a0dd");

            var itemId = Guid.NewGuid().ToString();

            // List translation requests
            var query = new Dictionary <string, string>();

            query.Add("state", "In Progress|Translated|Completed");
            foreach (var s in client.GetPage(query, 100, 0).items)
            {
                Console.WriteLine(s.translationRequestUid + " " + s.translationSubmissions.Count() + " " + s.fileUri);
                foreach (var sub in s.translationSubmissions)
                {
                    Console.WriteLine("  " + sub.state + sub.targetLocaleId);
                }
            }

            // Sample code to process items in bulk
            foreach (var item in client.GetAll(string.Empty, string.Empty))
            {
                var r = new UpdateTranslationRequest <SampleOriginalAssetKey, SampleCustomTranslationRequestData, SampleTargetAssetKey, SampleCustomSubmissionData>();
                if (item.translationSubmissions == null || item.translationSubmissions.Where(x => x.state != "Deleted").Count() == 0)
                {
                    continue;
                }

                r.translationSubmissions = new List <UpdateSubmissionRequest <SampleTargetAssetKey, SampleCustomSubmissionData> >();
                foreach (TranslationSubmission <SampleTargetAssetKey, SampleCustomSubmissionData> s in item.translationSubmissions)
                {
                    r.translationSubmissions.Add(new UpdateSubmissionRequest <SampleTargetAssetKey, SampleCustomSubmissionData>
                    {
                        translationSubmissionUid = s.translationSubmissionUid,
                        state = "Deleted"
                    });
                }

                var ur = client.UpdateTranslationRequest(r, item.translationRequestUid);
            }

            var singleRequest = client.Get("27c4b81d8d52");

            // Create translation request
            var createTranslationRequest = new CreateTranslationRequest <SampleOriginalAssetKey, SampleCustomTranslationRequestData>();

            createTranslationRequest.contentHash      = Guid.NewGuid().ToString().Substring(0, 32);
            createTranslationRequest.fileUri          = Guid.NewGuid().ToString();
            createTranslationRequest.originalAssetKey = new SampleOriginalAssetKey()
            {
                Key = itemId
            };
            createTranslationRequest.originalLocaleId   = "en";
            createTranslationRequest.title              = "test";
            createTranslationRequest.customOriginalData = new SampleCustomTranslationRequestData()
            {
                ItemId = itemId, Path = "content/home"
            };

            var request = client.CreateTranslationRequest(createTranslationRequest);

            // Search submissions
            var searchResult = client.GetPage("originalAssetKey.Key", itemId, 100, 0);

            searchResult = client.GetPage("translationRequestUid", "2e3b50ec4de3", 100, 0);

            query = new Dictionary <string, string>();
            query.Add("state", "Translated|Completed");
            query.Add("customTranslationData", "{\"MediaContent\": false }");
            // query.Add("customOriginalData", "{\"Path\": \"/sitecore/content/Home/Team/Chris-Castle\" }");
            searchResult = client.GetPage(query, 100, 0);

            // Create subsmission
            var submission = new CreateSubmissionRequest <SampleTargetAssetKey, SampleCustomSubmissionData>();

            submission.state          = "Deleted";
            submission.submitterName  = "test";
            submission.targetLocaleId = "ru-RU";
            submission.targetAssetKey = new SampleTargetAssetKey()
            {
                Key = Guid.NewGuid().ToString()
            };
            submission.customTranslationData = new SampleCustomSubmissionData()
            {
                Revision = Guid.NewGuid().ToString(), Locked = false, MediaContent = false
            };

            request = client.CreateSubmission(request.translationRequestUid, new List <CreateSubmissionRequest <SampleTargetAssetKey, SampleCustomSubmissionData> >()
            {
                submission
            });

            // Update submission
            var updateRequest = new UpdateTranslationRequest <SampleOriginalAssetKey, SampleCustomTranslationRequestData, SampleTargetAssetKey, SampleCustomSubmissionData>();

            updateRequest.customOriginalData      = request.customOriginalData;
            updateRequest.customOriginalData.Path = "newpath";
            updateRequest.translationSubmissions  = new List <UpdateSubmissionRequest <SampleTargetAssetKey, SampleCustomSubmissionData> > {
                new UpdateSubmissionRequest <SampleTargetAssetKey, SampleCustomSubmissionData> {
                    translationSubmissionUid = request.translationSubmissions[0].translationSubmissionUid,
                    state            = "In Progress",
                    lastExportedDate = DateTime.UtcNow
                }
            };

            var updatedRequest = client.UpdateTranslationRequest(updateRequest, request.translationRequestUid);

            // List translation requests
            foreach (var s in client.GetAll("state", "In Progress"))
            {
                Console.WriteLine(s.translationRequestUid + " " + s.translationSubmissions.Count() + " " + s.fileUri);
            }
        }