コード例 #1
0
ファイル: TestBase.cs プロジェクト: dgoin-us/sovren-dotnet
        static TestBase()
        {
            Credentials data = JsonSerializer.Deserialize <Credentials>(File.ReadAllText("credentials.json"));

            GeocodeCredentials = new GeocodeCredentials()
            {
                Provider    = GeocodeProvider.Google,
                ProviderKey = data.GeocodeProviderKey
            };

            Client = new SovrenClient(data.AccountId, data.ServiceKey, new DataCenter("https://rest-local.sovren.com", "v10", true));

            ParseResumeResponseValue parseResumeResponseValue = Client.ParseResume(new ParseRequest(TestData.Resume)).Result.Value;

            TestParsedResume = parseResumeResponseValue.ResumeData;

            parseResumeResponseValue    = Client.ParseResume(new ParseRequest(TestData.ResumeWithAddress)).Result.Value;
            TestParsedResumeWithAddress = parseResumeResponseValue.ResumeData;

            ParseJobResponseValue parseJobResponseValue = Client.ParseJob(new ParseRequest(TestData.JobOrder)).Result.Value;

            TestParsedJob = parseJobResponseValue.JobData;

            parseJobResponseValue    = Client.ParseJob(new ParseRequest(TestData.JobOrderWithAddress)).Result.Value;
            TestParsedJobWithAddress = parseJobResponseValue.JobData;

            parseJobResponseValue = Client.ParseJob(new ParseRequest(TestData.JobOrderTech)).Result.Value;
            TestParsedJobTech     = parseJobResponseValue.JobData;
        }
コード例 #2
0
ファイル: BatchParser.cs プロジェクト: sovren/sovren-dotnet
        /// <summary>
        /// Parses a batch of resumes
        /// </summary>
        /// <param name="apiClient">The API client to use to parse the files</param>
        /// <param name="parseOptions">Any parsing/indexing options</param>
        /// <param name="rules">
        /// The rules that should be applied to whatever files are found prior to parsing.
        /// This is important to reduce the number of invalid parse API calls and reduce parsing costs.
        /// </param>
        /// <param name="directory">The directory containing the files to be parsed</param>
        /// <param name="searchOption"></param>
        /// <param name="successCallback">A callback for when a file is parsed successfully</param>
        /// <param name="partialSuccessCallback">A callback for when some error happened during/after parsing, but there is still usable data in the response</param>
        /// <param name="errorCallback">A callback for when an error occurred when parsing the file, and there is no usable data</param>
        /// <param name="generateDocumentIdFn">A callback so you can specify a DocumentId for each file that is parsed</param>
        /// <exception cref="SovrenInvalidBatchException">Thrown when the directory provided does not meet the <see cref="BatchParsingRules"/></exception>
        public static async Task ParseResumes(
            SovrenClient apiClient,
            ParseOptions parseOptions,
            BatchParsingRules rules,
            string directory,
            SearchOption searchOption,
            Func <ResumeBatchSuccessResult, Task> successCallback,
            Func <ResumeBatchPartialSuccessResult, Task> partialSuccessCallback,
            Func <BatchErrorResult, Task> errorCallback,
            Func <string, string> generateDocumentIdFn = null)
        {
            if (apiClient == null)
            {
                throw new ArgumentNullException(nameof(apiClient));
            }

            IEnumerable <string> files = GetFiles(rules, directory, searchOption);

            //process the batch serially, since multi-threading could cause the customer to violate the AUP accidentally
            foreach (string file in files)
            {
                Document doc   = new Document(file);
                string   docId = generateDocumentIdFn == null?Guid.NewGuid().ToString() : generateDocumentIdFn(file);

                try
                {
                    //set document id if we plan to index these documents
                    if (parseOptions?.IndexingOptions != null)
                    {
                        parseOptions.IndexingOptions.DocumentId = docId;
                    }

                    ParseRequest        request  = new ParseRequest(doc, parseOptions);
                    ParseResumeResponse response = await apiClient.ParseResume(request);

                    if (successCallback != null)
                    {
                        await successCallback(new ResumeBatchSuccessResult(file, docId, response));
                    }
                }
                catch (SovrenUsableResumeException e)
                {
                    //this happens when something wasn't 100% successful, but there still might be usable data
                    if (partialSuccessCallback != null)
                    {
                        await partialSuccessCallback(new ResumeBatchPartialSuccessResult(file, docId, e));
                    }
                }
                catch (SovrenException e)
                {
                    //this happens where there is no usable data
                    if (errorCallback != null)
                    {
                        await errorCallback(new BatchErrorResult(file, docId, e));
                    }
                }
            }
        }
コード例 #3
0
        public async Task Test500Message()
        {
            DataCenter   fakeDC = new DataCenter("https://thisisnotarealurlatall-akmeaoiaefoij.com/");
            SovrenClient client = new SovrenClient("1234", "1234", fakeDC);

            try
            {
                await client.GetAccountInfo();
            }
            catch (SovrenException e)
            {
                Assert.AreEqual(HttpStatusCode.InternalServerError, e.HttpStatusCode);
                //the message for a 500 connection failed varies based on environment so do not check that
            }
        }
コード例 #4
0
        public async Task Test404Message()
        {
            DataCenter   fakeDC = new DataCenter("https://rest.resumeparsing.com/v9/fake");
            SovrenClient client = new SovrenClient("1234", "1234", fakeDC);

            try
            {
                await client.GetAccountInfo();
            }
            catch (SovrenException e)
            {
                Assert.AreEqual(HttpStatusCode.NotFound, e.HttpStatusCode);
                Assert.AreEqual("404 - Not Found", e.Message);
            }
        }
コード例 #5
0
        public async Task TestDebugRequestBody()
        {
            DataCenter   fakeDC = new DataCenter("https://thisisnotarealurlatall-akmeaoiaefoij.com/");
            SovrenClient client = new SovrenClient("1234", "1234", fakeDC);

            client.ShowFullRequestBodyInExceptions = true;

            try
            {
                List <String> index = new List <string>();
                index.Add("testIndex");
                await client.Search(index, new FilterCriteria());
            }
            catch (SovrenException e)
            {
                String expectedRequest = "{\"IndexIdsToSearchInto\":[\"testIndex\"],\"FilterCriteria\":{\"UserDefinedTagsMustAllExist\":false,\"HasPatents\":false,\"HasSecurityCredentials\":false,\"IsAuthor\":false,\"IsPublicSpeaker\":false,\"IsMilitary\":false,\"EmployersMustAllBeCurrentEmployer\":false,\"SkillsMustAllExist\":false,\"IsTopStudent\":false,\"IsCurrentStudent\":false,\"IsRecentGraduate\":false,\"LanguagesKnownMustAllExist\":false}}";
                Assert.AreEqual(expectedRequest, e.RequestBody);
            }
        }
コード例 #6
0
 /// <summary>
 /// Access methods for generating Sovren Matching UI sessions. For example: <code>sovClient.UI(options).Search(...)</code>
 /// </summary>
 /// <param name="client">the internal SovrenClient to make the API calls</param>
 /// <param name="uiSessionOptions">
 /// Options/settings for the Matching UI.
 /// <br/>NOTE: if you do not provide a <see cref="BasicUIOptions.Username"/> (in <see cref="MatchUISettings.UIOptions"/>),
 /// the user will be prompted to login as soon as the Matching UI session is loaded
 /// </param>
 public static SovrenClientWithUI UI(this SovrenClient client, MatchUISettings uiSessionOptions = null)
 {
     return(new SovrenClientWithUI(client, uiSessionOptions));
 }
コード例 #7
0
 internal SovrenClientWithUI(SovrenClient client, MatchUISettings uiSessionOptions)
 {
     InternalClient   = client;
     UISessionOptions = uiSessionOptions;
 }