Class: Bullhorn::Files

Inherits:
Object
  • Object
show all
Defined in:
lib/bullhorn/files.rb

Class Method Summary collapse

Class Method Details

.add(file, entity_id = 114755, entity_name = "Candidate") ⇒ Object

——— Upload a new File and attach it to a Candidate (New) Returns new File Id



8
9
10
11
# File 'lib/bullhorn/files.rb', line 8

def add file, entity_id=114755, entity_name="Candidate" 
  response = (Bullhorn::Client.add_file file_request(file, entity_name, entity_id)).body[:add_file_response][:return][:id]
  
end

.delete_all(candidate_id) ⇒ Object

———- Delete all files for a Candidate



30
31
32
33
34
# File 'lib/bullhorn/files.rb', line 30

def delete_all candidate_id
  (get_entity_files candidate_id).each do |file|
    Bullhorn::Client.api "deleteFile", delete_file_request(file, candidate_id)
  end  
end

.get_entity_files(entity_id = 114755, entity = "Candidate") ⇒ Object

———- Get list of all Files’ meta data attached to a Candidate (Index) ———- Returns: :comments, :content_sub_type, :content_type, :id, :name, :type



20
21
22
# File 'lib/bullhorn/files.rb', line 20

def get_entity_files entity_id = 114755, entity = "Candidate"
  response = (Bullhorn::Client.get_entity_files get_entity_files_request(entity_id, entity)).body[:get_entity_files_response][:return][:api_entity_metas]
end

.get_file_by(id, entity_id = 114775, entity_name = "Candidate") ⇒ Object

———- Get a File specified by its Id (Show) Returns File



25
26
27
# File 'lib/bullhorn/files.rb', line 25

def get_file_by id, entity_id=114775, entity_name="Candidate" 
  (Bullhorn::Client.getFile get_file_request(id, entity_name, entity_id)).body[:get_file_response][:return][:file_data]
end

.parse(resume) ⇒ Object

———- Parse a Resume or return nil if parsing fails



114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/bullhorn/files.rb', line 114

def parse resume
  request = {:base64ChunkedResume => resume}
  response = nil
  index = 15
  
  #--- Bullhorn's parseResume sometimes does't return the proper result.  Keep trying up to index times until captured
  while index > 0 do
    index -= 1
    response = (Bullhorn::Client.parse request).body[:parse_resume_response][:return][:hr_xml]
    return response if response
  end 
  nil
end

.store(file_by_candidate) ⇒ Object

——— Find a Candidate by Email or create a new Candidate,

then update Candidate fields with resume file and save


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
108
109
110
111
# File 'lib/bullhorn/files.rb', line 40

def store file_by_candidate
  sum = []
  response = (Bullhorn::Candidates.query_by file_by_candidate[:email]) || Bullhorn::Candidates.default_candidate
  candidate = {
    :address => response[:address],
    :categoryID => response[:category_id],                            #integer
    :comments => response[:comments],   
    :email => response[:email],                         
    :employeeType => response[:employee_type],
    :firstName => response[:first_name],
    :isDeleted => response[:is_deleted],                               #boolean
    :isEditable => response[:is_editable],         #boolean
    :lastName => response[:last_name],
    :name => response[:name],
    :ownerID => response[:owner_id],               #integer
    :password => response[:password],
    :preferredContact => response[:preferred_contact],
    :status => response[:status],
    :username => response[:username], 
    :userTypeID => response[:user_type_id],         
    :isDayLightSavings => response[:is_day_light_savings],
    :massMailOptOut => response[:mass_mail_opt_out],
    :timeZoneOffsetEST => response[:time_zone_offset_est],
    :dayRate => response[:day_rate],
    :dayRateLow => response[:day_rate_low],
    :degreeList => response[:degree_list],
    :salary => response[:salary],
    :travelLimit => response[:travel_limit],
    :willRelocate => response[:will_relocate],
    :workAuthorized => response[:work_authorized],

    :attributes! => {
      :categoryID => {"xsi:type" => "xs:int"},
      :isDeleted => {"xsi:type" => "xs:boolean"},
      :isEditable => {"xsi:type" => "xs:boolean"},
      :ownerID => {"xsi:type" => "xs:int"},
      :userTypeID => {"xsi:type" => "xs:int"},
      :isDayLightSavings => {"xsi:type" => "xs:boolean"},
    }
  }
  file_by_candidate.each do |key, value|
    if (value.class != HashWithIndifferentAccess)
      candidate[key.camelize(:lower).to_sym] = value if (value && (value != ""))
    else
      value.each do |k, v|
        candidate[key.to_sym][k.to_sym] = v if (v != (nil || "" || " ")) 
      end    
    end  
  end
  
  ###--------- Clean up DTO
  candidate.delete(:attachment)
  if response.has_key?(:user_id)
    sum << "has id"
    sum << (candidate[:userID] = response[:user_id])
    candidate[:attributes!][:userID] = {"xsi:type" => "xs:int"}
  else  
    sum << "no id"
    candidate[:username] = candidate[:email]
    sum << candidate[:username]
    sum << candidate[:lastName]
    candidate[:password] = "hireminds766"
  end 
  [:"@xmlns:xsi", :"@xmlns:ns4", :"@xsi:type", :alerts].each do |key|
    candidate.delete(key)
  end  
  
  Bullhorn::Candidates.save candidate
  
  
  sum << candidate
end

.update(file, entity_id = 114755, entity_name = "Candidate") ⇒ Object

———- Upload a replacement to a File attached to a Candidate (Udate)



14
15
16
# File 'lib/bullhorn/files.rb', line 14

def update file, entity_id=114755, entity_name="Candidate" 
  Bullhorn::Client.update_file file_request(file)
end