Пример #1
0
        public async Task <IList <Posting> > GetPostings(LeverSettings settings)
        {
            if (settings == null || !settings.IsValid())
            {
                Logger.Error("Unable to fetch posting from API because `ApiKey` or `Site` is not defined in settings.");
                return(null);
            }

            try
            {
                var request = new HttpRequestMessage(HttpMethod.Get, $"{URL}{settings.Site}");
                var client  = _clientFactory.CreateClient();

                var response = await client.SendAsync(request);

                if (response.IsSuccessStatusCode)
                {
                    return(JsonConvert.DeserializeObject <IList <Posting> >(await response.Content.ReadAsStringAsync()).Where(x => FilterPostings(settings, x)).ToList());
                }
            }
            catch (Exception e)
            {
                Logger.Error(string.Format("{0}, Error retrieving data from API.", e));
            }

            return(null);
        }
Пример #2
0
        private static bool FilterPostings(LeverSettings settings, Posting posting)
        {
            if (settings.Locations == null || !settings.Locations.Any())
            {
                return(true);
            }

            return(settings.Locations.Any(x => string.Equals(x, posting.Categories.Location, StringComparison.OrdinalIgnoreCase)));
        }
Пример #3
0
        public async Task <PostingResult> Apply(LeverSettings settings, LeverPostingApplyViewModel model)
        {
            if (settings == null || !settings.IsValid())
            {
                Logger.Error("Unable to submit application to API because `Site` or `ApiKey` is not defined in settings.");
                return(null);
            }

            if (string.IsNullOrEmpty(model.PostingId))
            {
                Logger.Error("Please provide postingId.");
                return(null);
            }

            try
            {
                var client   = _clientFactory.CreateClient();
                var response = await client.PostAsync($"{URL}{settings.Site}/{model.PostingId}?key={settings.ApiKey}", model.ToFormData());

                var json = JsonConvert.DeserializeObject <PostingResult>(await response.Content.ReadAsStringAsync());

                if (json.Ok)
                {
                    await TriggerNotificationEvent(model, true, null);
                }

                return(json);
            }
            catch (Exception e)
            {
                await TriggerNotificationEvent(model, false, e.Message);

                Logger.Error(string.Format("{0}, Error apply for posting id: {1}", e, model.PostingId));
            }

            return(null);
        }