Class: Sovren::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/sovren/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(file, options = {}) ⇒ Client

Returns a new instance of Client.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/sovren/client.rb', line 3

def initialize file, options={}
  @client = Savon.client(wsdl:"https://services.resumeparsing.com/ParsingService.asmx?WSDL", :log => false)

  @response = @client.call(:parse_resume, message: { "request" => {
    "AccountId"     => Sovren.configuration.,
    "ServiceKey"    => Sovren.configuration.service_key,
    "FileBytes"     => Base64.encode64(file.read),
    "OutputHtml"    => true,
    "Configuration" => nil,
    "RevisionDate"  => nil,
  } })

  @result = @response.to_hash[:parse_resume_response][:parse_resume_result]

  @doc = Nokogiri::XML(@result[:xml]).remove_namespaces!
end

Instance Method Details

#allObject



20
21
22
23
24
25
26
27
# File 'lib/sovren/client.rb', line 20

def all
  {
    user: ,
    educations: educations,
    internships: internships,
    employments: employments,
  }
end

#educationsObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/sovren/client.rb', line 56

def educations
  @doc.css('SchoolOrInstitution').map do |edu|
    {
      degreeType: edu.at_css('Degree').attr('degreeType'),
      degree: edu.at_css('Degree DegreeName'),
      started_on: edu.at_css('Degree DatesOfAttendance StartDate AnyDate'),
      ended_on: edu.at_css('Degree DatesOfAttendance EndDate AnyDate'),
      major: edu.at_css('Degree DegreeMajor'),
      minor: edu.at_css('Degree DegreeMinor'),
      name: edu.at_css('School SchoolName')
    }
  end.map do |hsh|
    format_hash hsh
  end
end

#employmentsObject



76
77
78
# File 'lib/sovren/client.rb', line 76

def employments
  positions 'directHire'
end

#internshipsObject



72
73
74
# File 'lib/sovren/client.rb', line 72

def internships
  positions 'internship'
end

#positions(type) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/sovren/client.rb', line 80

def positions type
  @doc.css('PositionHistory').select do |emp|
    emp.attr('positionType') == type
  end.map do |emp|
    {
      "company": emp.at_css('OrgName OrganizationName'),
      "description": emp.at_css('Description'),
      "ended_on": emp.at_css('EndDate AnyDate'),
      "started_on": emp.at_css('StartDate AnyDate'),
      "title": emp.at_css('Title'),
      "current_employer": emp.attr('currentEmployer') == 'true' ? true : false,
    }
  end.map do |hsh|
    format_hash hsh
  end
end

#to_xmlObject



97
98
99
# File 'lib/sovren/client.rb', line 97

def to_xml
  @result[:xml]
end

#user_infoObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/sovren/client.rb', line 29

def 
  majors = {}

  educations.each do |edu|
    type = edu[:degreeType]
    major = edu[:major]
    if type && major
      if majors[type]
        majors[type] << major
      else
        majors[type] = [major]
      end
    end
  end

  hsh = {
    first_name: @doc.at_css('PersonName GivenName'),
    last_name: @doc.at_css('PersonName FamilyName'),
    name: @doc.at_css('PersonName FormattedName'),
    phone: @doc.at_css('Telephone FormattedNumber') || @doc.at_css('Mobile FormattedNumber'),
    email: @doc.at_css('InternetEmailAddress'),
    majors: majors
  }

  format_hash hsh
end