class Cb::Clients::Recommendation
Public Class Methods
for_company(company_did)
click to toggle source
# File lib/cb/clients/recommendation.rb, line 63 def self.for_company(company_did) json_hash = cb_client.cb_get(Cb.configuration.uri_recommendation_for_company, query: { CompanyDID: company_did }) jobs = [] if json_hash api_jobs = json_hash.fetch('Results', {}).fetch('JobRecommendation', {}).fetch('Jobs', {}) if api_jobs company_jobs = [api_jobs.fetch('CompanyJob', [])].flatten.compact company_jobs.each do |cur_job| jobs << Models::Job.new(cur_job) end end cb_client.append_api_responses(jobs, json_hash.fetch('Results', {}).fetch('JobRecommendation', {})) cb_client.append_api_responses(jobs, json_hash.fetch('Results', {})) cb_client.append_api_responses(jobs, json_hash) end end
for_job(*args)
click to toggle source
# File lib/cb/clients/recommendation.rb, line 16 def self.for_job(*args) hash = normalize_args(args) hash = set_hash_defaults(hash) json_hash = cb_client.cb_get(Cb.configuration.uri_recommendation_for_job, query: hash) jobs = [] if json_hash.key?('ResponseRecommendJob') if json_hash['ResponseRecommendJob'].key?('RecommendJobResults') && !json_hash['ResponseRecommendJob']['RecommendJobResults'].nil? jobs = create_jobs json_hash, 'Job' cb_client.append_api_responses(jobs, json_hash['ResponseRecommendJob']['Request']) end cb_client.append_api_responses(jobs, json_hash['ResponseRecommendJob']) end cb_client.append_api_responses(jobs, json_hash) end
for_user(*args)
click to toggle source
# File lib/cb/clients/recommendation.rb, line 39 def self.for_user(*args) hash = normalize_args(args) hash = set_hash_defaults(hash) json_hash = cb_client.cb_get(Cb.configuration.uri_recommendation_for_user, query: hash) jobs = [] if json_hash.key?('ResponseRecommendUser') if json_hash['ResponseRecommendUser'].key?('RecommendJobResults') && !json_hash['ResponseRecommendUser']['RecommendJobResults'].nil? jobs = create_jobs json_hash, 'User' cb_client.append_api_responses(jobs, json_hash['ResponseRecommendUser']['Request']) end cb_client.append_api_responses(jobs, json_hash['ResponseRecommendUser']) end cb_client.append_api_responses(jobs, json_hash) end
Private Class Methods
create_jobs(json_hash, type)
click to toggle source
# File lib/cb/clients/recommendation.rb, line 99 def self.create_jobs(json_hash, type) jobs = [] [json_hash["ResponseRecommend#{type}"]['RecommendJobResults']['RecommendJobResult']].flatten.each do |api_job| jobs << Models::Job.new(api_job) end jobs end
normalize_args(args)
click to toggle source
# File lib/cb/clients/recommendation.rb, line 82 def self.normalize_args(args) return args[0] if args[0].class == Hash { ExternalID: args[0], JobDID: args[0], CountLimit: args[1] || '25', SiteID: args[2] || '', CoBrand: args[3] || '' } end
set_hash_defaults(hash)
click to toggle source
# File lib/cb/clients/recommendation.rb, line 93 def self.set_hash_defaults(hash) hash[:CountLimit] ||= '25' hash[:HostSite] ||= Cb.configuration.host_site hash end