Method: OpenApiSDK::AtsCandidates#create

Defined in:
lib/open_api_sdk/ats_candidates.rb

#create(x_connection_token, unified_ats_candidate_input, remote_data = nil) ⇒ Object

Raises:

  • (StandardError)


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/open_api_sdk/ats_candidates.rb', line 62

def create(x_connection_token, unified_ats_candidate_input, remote_data = nil)
  # create - Create Candidates
  # Create Candidates in any supported Ats software
  request = ::OpenApiSDK::Operations::CreateAtsCandidateRequest.new(
    
    x_connection_token: x_connection_token,
    unified_ats_candidate_input: unified_ats_candidate_input,
    remote_data: remote_data
  )
  url, params = @sdk_configuration.get_server_details
  base_url = Utils.template_url(url, params)
  url = "#{base_url}/ats/candidates"
  headers = Utils.get_headers(request)
  req_content_type, data, form = Utils.serialize_request_body(request, :unified_ats_candidate_input, :json)
  headers['content-type'] = req_content_type
  raise StandardError, 'request body is required' if data.nil? && form.nil?
  query_params = Utils.get_query_params(::OpenApiSDK::Operations::CreateAtsCandidateRequest, request)
  headers['Accept'] = 'application/json'
  headers['user-agent'] = @sdk_configuration.user_agent

  r = @sdk_configuration.client.post(url) do |req|
    req.headers = headers
    req.params = query_params
    Utils.configure_request_security(req, @sdk_configuration.security) if !@sdk_configuration.nil? && !@sdk_configuration.security.nil?
    if form
      req.body = Utils.encode_form(form)
    elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
      req.body = URI.encode_www_form(data)
    else
      req.body = data
    end
  end

  content_type = r.headers.fetch('Content-Type', 'application/octet-stream')

  res = ::OpenApiSDK::Operations::CreateAtsCandidateResponse.new(
    status_code: r.status, content_type: content_type, raw_response: r
  )
  if r.status == 201
    if Utils.match_content_type(content_type, 'application/json')
      out = Utils.unmarshal_complex(r.env.response_body, ::OpenApiSDK::Shared::UnifiedAtsCandidateOutput)
      res.unified_ats_candidate_output = out
    end
  end
  res
end