-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
74 changed files
with
158,575 additions
and
14,205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Ats | ||
module Workday | ||
module ApplicationFields | ||
def get_application_criteria(job, _data) | ||
p "Getting Workday application criteria" | ||
job.application_criteria = {} # TODO: fix this | ||
job.save | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
module Ats | ||
module Workday | ||
module CompanyDetails | ||
def fetch_subsidiaries(company) | ||
ats_identifier = company.ats_identifier | ||
return if ats_identifier.count('/') > 2 | ||
|
||
puts "Checking if the company has subsidiaries..." | ||
data = fetch_company_jobs(ats_identifier, facets_only: true) | ||
company_facet = data&.find { |f| f['descriptor']&.match?(/compan(y|ies)/i) } | ||
return unless company_facet | ||
|
||
company_facet['values'].map do |company_data| | ||
data = { | ||
name: company_data['descriptor'], | ||
ats_identifier: "#{company.ats_identifier}/#{company_data['id']}" | ||
} | ||
find_or_create_company_by_data(data) | ||
end | ||
end | ||
|
||
# get name from job | ||
# get description from sidebar_data | ||
# get website from approot/sidebar | ||
# website -> Crunchbase -> more reliable name and description | ||
|
||
def company_details(ats_identifier) | ||
api_base, url_ats_main, tenant = parse_identifier(ats_identifier) | ||
return {} unless api_base && url_ats_main && tenant | ||
|
||
sidebar_api_url, approot_api_url, url_ats_api = build_endpoints(api_base) | ||
|
||
sidebar_data = get_json_data(sidebar_api_url) | ||
approot_data = get_json_data(approot_api_url) | ||
return {} unless sidebar_data || approot_data | ||
|
||
url_website = approot_data&.dig('header', 'homePageURL') | ||
name, website, total_live = fetch_details_from_jobs_endpoint(ats_identifier) | ||
url_website = website unless url_website.present? | ||
|
||
{ | ||
name: name || tenant.capitalize, | ||
description: Flipper.enabled?(:company_description) ? fetch_company_description(sidebar_data) : 'Not added yet', | ||
url_ats_api:, | ||
url_ats_main:, | ||
url_careers: check_for_careers_url_redirect(url_ats_main), | ||
url_website:, | ||
url_linkedin: fetch_linkedin(approot_data), | ||
total_live: | ||
# can get logo_url from sidebar_data | ||
} | ||
end | ||
|
||
def fetch_company_id(data) | ||
data[:ats_identifier] | ||
end | ||
|
||
private | ||
|
||
def check_for_careers_url_redirect(url_ats_main) | ||
url_ats_main | ||
end | ||
|
||
def fetch_base_url(ats_identifier) | ||
parse_identifier(ats_identifier).first | ||
end | ||
|
||
def parse_identifier(ats_identifier) | ||
tenant, site_id, version = ats_identifier.split('/') | ||
return unless tenant && site_id | ||
|
||
version ||= 1 | ||
base_url = url_api.gsub('XXX', tenant).sub('YYY', site_id).sub('ZZZ', version) | ||
url_ats_main = url_base.sub('XXX', tenant).sub('YYY', site_id).sub('ZZZ', version) | ||
[base_url, url_ats_main, tenant] | ||
end | ||
|
||
def build_endpoints(api_base) | ||
sidebar_api_url = "#{api_base}sidebar" | ||
approot_api_url = "#{api_base}approot" | ||
url_ats_api = "#{api_base}jobs" | ||
[sidebar_api_url, approot_api_url, url_ats_api] | ||
end | ||
|
||
def fetch_details_from_jobs_endpoint(ats_identifier) | ||
data = fetch_company_jobs(ats_identifier, one_job_only: true) | ||
job_data = data['jobPostings']&.first | ||
total_live = data['total'] | ||
|
||
name, website = fetch_details_from_job(ats_identifier, job_data) | ||
[name, website, total_live] | ||
end | ||
|
||
def fetch_details_from_job(ats_identifier, job_data) | ||
job_id = fetch_id(job_data) | ||
data = fetch_detailed_job_data(ats_identifier, job_id) | ||
return unless data | ||
|
||
name = data.dig('hiringOrganization', 'name') | ||
website = data.dig('hiringOrganization', 'url') | ||
[name, website] | ||
end | ||
|
||
def fetch_company_description(sidebar_data) | ||
return unless sidebar_data | ||
|
||
sidebar_data.find do |data| | ||
type = data['type']&.downcase | ||
break data['text'] if %w[text image].include?(type) | ||
end | ||
end | ||
|
||
def fetch_linkedin(approot_data) | ||
return unless approot_data | ||
|
||
socials = approot_data.dig('footer', 'socialLinksList') | ||
linkedin = socials&.find { |e| e['label'] == 'LinkedIn' } | ||
linkedin&.dig('uri') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
module Ats | ||
module Workday | ||
module FetchCompanyJobs | ||
include Constants | ||
|
||
def fetch_company_jobs(ats_identifier, one_job_only: false, facets_only: false) | ||
api_base = fetch_base_url(ats_identifier) | ||
limit = 20 | ||
initial_parameters = { endpoint: "#{api_base}jobs", limit: } | ||
subsidiary_id = ats_identifier.split('/').last if ats_identifier.count('/') > 2 | ||
|
||
data = fetch_chunk(initial_parameters) # get facets array to build full_parameters | ||
|
||
location_parameters = build_facet(data['facets'], [/location/i, /countr(y|ies)/i], JOB_LOCATION_KEYWORDS.excluding(/remote/)) | ||
company_parameters = build_facet(data['facets'], [/compan(y|ies)/i], [subsidiary_id], 'id') if subsidiary_id | ||
full_parameters = { | ||
location_parameters:, | ||
company_parameters: | ||
}.merge(initial_parameters) | ||
|
||
data = fetch_chunk(full_parameters) # fetch first tranche of jobs | ||
return data if one_job_only | ||
return data['facets'] if facets_only | ||
|
||
total_live = data['total'] | ||
return unless total_live&.positive? | ||
|
||
puts "Couldn't find a location parameter. Returning all jobs regardless of location." unless location_parameters.present? | ||
jobs = data['jobPostings'] | ||
|
||
page = 1 | ||
while page * limit < total_live | ||
data = fetch_chunk(full_parameters, page) # fetch additional tranches | ||
jobs += data['jobPostings'] | ||
page += 1 | ||
end | ||
jobs | ||
end | ||
|
||
private | ||
|
||
def fetch_chunk(params, page = 0) | ||
puts "fetching jobs from #{params[:endpoint]}, page##{page + 1}..." | ||
limit = params[:limit] || 20 | ||
request_body = { | ||
limit:, | ||
offset: page * limit, | ||
appliedFacets: {}, | ||
searchText: "" | ||
} | ||
request_body[:appliedFacets].merge!(params[:location_parameters]) if params[:location_parameters] | ||
request_body[:appliedFacets].merge!(params[:company_parameters]) if params[:company_parameters] | ||
p request_body | ||
json_post_request(params[:endpoint], request_body) | ||
end | ||
|
||
def build_facet(facets, parameter_array, descriptor_array, descriptor_field = 'descriptor') | ||
queue = [[facets, nil]] | ||
parameters = Hash.new { |hash, key| hash[key] = [] } | ||
|
||
until queue.empty? || parameters.present? # returns once it finds a single valid parameter | ||
current_level, facet_parameter = queue.shift | ||
|
||
current_level.each do |facet| | ||
if facet.is_a?(Hash) && facet['values'] | ||
queue << [facet['values'], facet['facetParameter'].to_sym] if parameter_array.any? { |parameter| facet['facetParameter']&.match?(parameter) } || parameter_array.any? { |parameter| facet['descriptor']&.match?(parameter) } | ||
elsif facet[descriptor_field] && descriptor_array.any? { |descriptor| facet[descriptor_field].match?(descriptor) } | ||
parameters[facet_parameter] << facet['id'] | ||
end | ||
end | ||
end | ||
|
||
parameters | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.