class Cb::Clients::Recommendations

Public Class Methods

for_job(*args) click to toggle source
# File lib/cb/clients/recommendations.rb, line 17
def for_job(*args)
  hash_args = normalize_args(args)
  hash_args = hash_defaults(hash_args)
  json_hash = cb_client.cb_get(Cb.configuration.uri_recommendation_for_job,
                               query: hash_args)

  {
    jobs: create_jobs(json_hash, 'Job'),
    request: json_hash['ResponseRecommendJob']['Request'],
    recid: json_hash['ResponseRecommendJob']['Request']['RequestEvidenceID'],
    errors: json_hash['ResponseRecommendJob']['Errors']
  }
end
for_user(*args) click to toggle source
# File lib/cb/clients/recommendations.rb, line 31
def for_user(*args)
  hash_args = normalize_args(args)
  hash_args = hash_defaults(hash_args)
  json_hash = cb_client.cb_get(Cb.configuration.uri_recommendation_for_user,
                               query: hash_args)

  {
    jobs: create_jobs(json_hash, 'User'),
    request: json_hash['ResponseRecommendUser']['Request'],
    recid: json_hash['ResponseRecommendUser']['Request']['RequestEvidenceID'],
    errors: json_hash['ResponseRecommendUser']['Errors']
  }
end

Private Class Methods

create_jobs(json_hash, type) click to toggle source
# File lib/cb/clients/recommendations.rb, line 64
def create_jobs(json_hash, type)
  [json_hash["ResponseRecommend#{type}"]['RecommendJobResults']['RecommendJobResult']].flatten.map do |api_job|
    Models::Job.new(api_job)
  end
rescue NoMethodError
  []
end
hash_defaults(hash) click to toggle source
# File lib/cb/clients/recommendations.rb, line 58
def hash_defaults(hash)
  hash[:CountLimit] ||= '25'
  hash[:HostSite] ||= Cb.configuration.host_site
  hash
end
normalize_args(args) click to toggle source
# File lib/cb/clients/recommendations.rb, line 47
def 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