spear-cb-api 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ module Spear
4
+ module Resource
5
+ module Application
6
+ def history(user_external_id)
7
+ raise Spear::ParametersRequired.new('UserExternalId') if user_external_id.blank?
8
+
9
+ Spear::Request.new.execute(:get, "/application/history",
10
+ {query: {:ExternalID => user_external_id}, api_options: {path: 'v1'}})
11
+ end
12
+
13
+ # Application Creation
14
+ def create_application(host_site, data={})
15
+ raise Spear::ParametersRequired.new('HostSite') if host_site.blank?
16
+
17
+ Spear::Request.new.execute(:apply, "/cbapi/application",
18
+ {query: {:HostSite => host_site}, body: data, api_options: {path: ""}})
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ module Spear
4
+ module Resource
5
+ module Job
6
+ def search_job(params={})
7
+ Spear::Request.new.execute(:get, "/jobsearch", {:query => params})
8
+ end
9
+
10
+ # job_id:
11
+ # 20 character long unique job ID.
12
+ # It's one of the elements received in every v1/jobsearch result item.
13
+ def retrieve_job(job_id, host_site)
14
+ raise Spear::ParametersRequired.new(%w{JobID HostSite}) if job_id.blank? or host_site.blank?
15
+
16
+ Spear::Request.new.execute(:get, "/job", {:query => {:DID => job_id, :HostSite => host_site}})
17
+ end
18
+ end
19
+ end
20
+ end
@@ -5,45 +5,59 @@ module Spear
5
5
  module Resume
6
6
  # file: kind of ActionDispatch::Http::UploadedFile
7
7
  def parse_file(file)
8
- unless (file.kind_of? ActionDispatch::Http::UploadedFile) || (file.kind_of? Rack::Test::UploadedFile)
9
- return {"Errors" => {"Error" => "%q{Expecting type of ActionDispatch::Http::UploadedFile or Rack::Test::UploadedFile, but got #{file.class}.}"}}
8
+ if !file.kind_of?(ActionDispatch::Http::UploadedFile) and !file.kind_of?(Rack::Test::UploadedFile)
9
+ raise Spear::ObjectTypeError.new("Expecting type of ActionDispatch::Http::UploadedFile or Rack::Test::UploadedFile, but got #{file.class}.}")
10
10
  end
11
11
 
12
12
  file.rewind
13
- @request.execute(:parse_file, "/resume/parse", {:FileName => file.original_filename,
14
- :FileBytes => Base64.encode64(file.read)})
13
+ Spear::Request.new.execute(:post, "/resume/parse", {
14
+ :body => {
15
+ :FileName => file.original_filename,
16
+ :FileBytes => Base64.encode64(file.read)
17
+ }
18
+ })
15
19
  end
16
20
 
17
- # Required column value
18
- # <ShowContactInfo>true</ShowContactInfo>
19
- # <Title>asasdasdasd</Title>
20
- # <ResumeText>albee009@gmail.com JobsCentral999</ResumeText>
21
- # <Visibility>true</Visibility>
22
- # <CanRelocateNationally>false</CanRelocateNationally>
23
- # <CanRelocateInternationally>false</CanRelocateInternationally>
24
- # <TotalYearsExperience>0</TotalYearsExperience>
25
- # <HostSite>T3</HostSite>
26
- # <DesiredJobTypes>ETFE</DesiredJobTypes>
27
- # <CompanyExperiences/>
28
- # <Educations/>
29
- # <Languages/>
30
- # <CustomValues/>
21
+ # {
22
+ # ShowContactInfo: true,
23
+ # Title: 'asasdasdasd',
24
+ # ResumeText: 'albee009@gmail.com JobsCentral999',
25
+ # Visibility: true,
26
+ # CanRelocateNationally: false,
27
+ # CanRelocateInternationally: false,
28
+ # TotalYearsExperience: 1,
29
+ # HostSite: 'T3',
30
+ # DesiredJobTypes: 'ETFE',
31
+ # CompanyExperiences: [],
32
+ # Educations: [],
33
+ # Languages: [],
34
+ # CustomValues: []
35
+ # }
31
36
  def create_resume(data={})
32
- @request.execute(:post, "/resume/create", data)
37
+ Spear::Request.new.execute(:post, "/resume/create", {body: data})
38
+ end
39
+
40
+ # {
41
+ # ...
42
+ # # if editting, we should add this column
43
+ # ExternalID: 'asdasdsdaas'
44
+ # }
45
+ def edit_resume(data={})
46
+ Spear::Request.new.execute(:post, "/resume/edit", {body: data})
33
47
  end
34
48
 
35
49
  def upload_file(file, resume_external_id, user_external_id)
36
- unless (file.kind_of? ActionDispatch::Http::UploadedFile) || (file.kind_of? Rack::Test::UploadedFile)
37
- return {"Errors" => {"Error" => "%q{Expecting type of ActionDispatch::Http::UploadedFile or Rack::Test::UploadedFile, but got #{file.class}.}"}}
50
+ if !file.kind_of?(ActionDispatch::Http::UploadedFile) and !file.kind_of?(Rack::Test::UploadedFile)
51
+ raise Spear::ObjectTypeError.new("Expecting type of ActionDispatch::Http::UploadedFile or Rack::Test::UploadedFile, but got #{file.class}.}")
38
52
  end
39
53
 
40
- if user_external_id.blank? or resume_external_id.blank?
41
- return {"Errors" => {"Error" => "%q{User external ID and resume external ID is required.}"}}
42
- end
54
+ raise Spear::ParametersRequired.new(%w{UserExternalId ResumeExternalId}) if user_external_id.blank? or resume_external_id.blank?
43
55
 
44
56
  file.rewind
45
- @request.execute(:upload_file, "/resume/upload", {
46
- :body => Base64.encode64(file.read),
57
+ Spear::Request.new.execute(:upload_file, "/resume/upload", {
58
+ :body => {
59
+ :FileBytes => Base64.encode64(file.read)
60
+ },
47
61
  :query => {
48
62
  :FileName => file.original_filename,
49
63
  :ExternalID => resume_external_id,
@@ -54,20 +68,16 @@ module Spear
54
68
 
55
69
  # list all of my resumes
56
70
  def own_all(user_external_id, host_site)
57
- if user_external_id.blank? or host_site.blank?
58
- return {"Errors" => {"Error" => "%q{User external ID and host site is required.}"}}
59
- end
71
+ raise Spear::ParametersRequired.new(%w{UserExternalId HostSite}) if user_external_id.blank? or host_site.blank?
60
72
 
61
- @request.execute(:get, "/resume/ownall", {
73
+ Spear::Request.new.execute(:get, "/resume/ownall", {
62
74
  :query => {:ExternalUserID => user_external_id, :HostSite => host_site}})
63
75
  end
64
76
 
65
77
  def retrieve_resume(resume_external_id, user_external_id)
66
- if user_external_id.blank? or resume_external_id.blank?
67
- return {"Errors" => {"Error" => "%q{User external ID and host site is required.}"}}
68
- end
78
+ raise Spear::ParametersRequired.new(%w{UserExternalId ResumeExternalId}) if user_external_id.blank? or resume_external_id.blank?
69
79
 
70
- @request.execute(:get, "/resume/retrieve", {
80
+ Spear::Request.new.execute(:get, "/resume/retrieve", {
71
81
  :query => {:ExternalUserID => user_external_id, :ExternalID => resume_external_id}})
72
82
  end
73
83
  end
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+
3
+ module Spear
4
+ module Resource
5
+ module TalentNetwork
6
+ def join_form_questions(talent_network_did)
7
+ raise Spear::ParametersRequired.new('TalentNetworkDID') if talent_network_did.blank?
8
+
9
+ Spear::Request.new.execute(:get, "/talentnetwork/config/join/questions/#{talent_network_did}/json",
10
+ {api_options: {path: ""}})
11
+ end
12
+
13
+ # {
14
+ # TalentNetworkDID: 'YourTalentNetworkDID',
15
+ # PreferredLanguage: 'USEnglish',
16
+ # AcceptPrivacy: '',
17
+ # AcceptTerms: '',
18
+ # ResumeWordDoc: '',
19
+ # JoinValues: [
20
+ # {Key: 'MxDOTalentNetworkMemberInfo_EmailAddress', Value: 'some.email@example.com'},
21
+ # {Key: 'JQ7I3CM6P9B09VCVD9YF', Value: 'AVAILABLENOW'}
22
+ # ]
23
+ # }
24
+ def create_member(data={})
25
+ Spear::Request.new.execute(:post, "/talentnetwork/member/create/json",
26
+ {api_options: {path: ""}, body: data})
27
+ end
28
+ end
29
+ end
30
+ end
@@ -5,18 +5,37 @@ module Spear
5
5
  module User
6
6
  def check_existing(email, password='')
7
7
  if password.blank?
8
- @request.execute(:post, "/user/checkexisting", {:Email => email})
8
+ Spear::Request.new.execute(:post, "/user/checkexisting", {body: {:Email => email}})
9
9
  else
10
- @request.execute(:post, "/user/checkexisting", {:Email => email, :Password => password})
10
+ Spear::Request.new.execute(:post, "/user/checkexisting", {body: {:Email => email, :Password => password}})
11
11
  end
12
12
  end
13
13
 
14
+ # {
15
+ # FirstName: 'asdasdad',
16
+ # LastName: 'asdasdad',
17
+ # Email: 'ascacasc@sina.com.cn',
18
+ # Password: 'Qwer1234!',
19
+ # Phone: '+657777888999',
20
+ # City: 'Singapore',
21
+ # State: 'SG',
22
+ # CountryCode: 'SG',
23
+ # AllowNewsletterEmails: false,
24
+ # HostSite: 'T3',
25
+ # AllowPartnerEmails: false,
26
+ # AllowEventEmails: false,
27
+ # SendEmail: false,
28
+ # Gender: 'U',
29
+ # UserType: 'jobseeker',
30
+ # Status: 'active',
31
+ # Test: false
32
+ # }
14
33
  def create_user(data={})
15
- @request.execute(:post, "/user/create", data)
34
+ Spear::Request.new.execute(:post, "/user/create", {body: data})
16
35
  end
17
36
 
18
37
  def retrieve_user(user_external_id, password)
19
- @request.execute(:post, "/user/retrieve", {:ExternalID => user_external_id, :Password => password})
38
+ Spear::Request.new.execute(:post, "/user/retrieve", {body: {:ExternalID => user_external_id, :Password => password}})
20
39
  end
21
40
  end
22
41
  end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ module Spear
4
+ module Resources
5
+ include Resource::User
6
+ include Resource::Resume
7
+ include Resource::Application
8
+ include Resource::Job
9
+ end
10
+ end
@@ -0,0 +1,43 @@
1
+ module Spear
2
+ module Structure
3
+ class Base
4
+ # response is an instance of Httparty::Response
5
+ attr_reader :response, :root, :status, :error_message
6
+
7
+ def initialize(response)
8
+ raise Spear::ParametersRequired.new('Response') if response.nil?
9
+
10
+ @response = response
11
+ # get the root keyvalue of the hash
12
+ @root = response.to_h.first.last
13
+ @status = @root["Status"]
14
+ @error_message = get_error_message(@root)
15
+ end
16
+
17
+ def success?
18
+ @status.nil? ? @error_message.nil? : @status.include?('Success')
19
+ end
20
+
21
+ private
22
+ def get_error_message(hash)
23
+ if hash["Errors"].kind_of?(Hash)
24
+ if !hash["Errors"]["Error"].kind_of?(Hash)
25
+ # 1. Api error response is an array
26
+ if hash["Errors"]["Error"].kind_of?(Array)
27
+ return hash["Errors"]["Error"].join(", ")
28
+ end
29
+ # 2. Api error response is a string
30
+ return hash["Errors"]["Error"]
31
+ else
32
+ # 3. Api error response is a hash
33
+ if !hash["Errors"]["Error"]["Message"].nil?
34
+ return hash["Errors"]["Error"]["Message"]
35
+ end
36
+ end
37
+ elsif hash["Errors"].kind_of?(Array)
38
+ return hash["Errors"].first
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,17 @@
1
+ module Spear
2
+ module Structure
3
+ module Resume
4
+ class Create < Structure::Base
5
+ attr_reader :external_id, :user_external_id
6
+ attr_accessor :title, :total_years_experience, :educations, :company_experiences
7
+
8
+ def initialize(response)
9
+ super(response)
10
+ @external_id = @root['ResponseExternalID']
11
+ @user_external_id = @root['Request']['ExternalUserID']
12
+ @title = @root['Request']['Title']
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Spear
2
+ module Structure
3
+ module Resume
4
+ class Edit < Structure::Base
5
+ attr_reader :external_id, :user_external_id
6
+ attr_accessor :title, :total_years_experience, :educations, :company_experiences
7
+
8
+ def initialize(response)
9
+ super(response)
10
+ @external_id = @root['Request']['ExternalID']
11
+ @user_external_id = @root['Request']['ExternalUserID']
12
+ @title = @root['Request']['Title']
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,62 @@
1
+ # TODO: Extract Languages and EmployerOrgs ...
2
+ module Spear
3
+ module Structure
4
+ module Resume
5
+ module EmbededClass
6
+ ##################################################################
7
+ # Resume embeded class
8
+ ##################################################################
9
+ class Education
10
+ attr_accessor :school_name, :major, :degree_name, :degree_code, :degree_type, :graduation_date
11
+
12
+ def initialize(education={})
13
+ @school_name = education['SchoolName']
14
+ @major = education['Major']
15
+ @degree_name = education['DegreeName']
16
+ @degree_code = education['DegreeCode']
17
+ @degree_type = education['DegreeType']
18
+ @graduation_date = education['GraduationDate']
19
+ end
20
+ end
21
+
22
+ def generate_educations(educations)
23
+ if !educations.nil?
24
+ if educations['Education'].kind_of?(Array)
25
+ educations['Education'].map {|e| Education.new(e)}
26
+ else # Hash
27
+ [Education.new(educations['Education'])]
28
+ end
29
+ else
30
+ []
31
+ end
32
+ end
33
+
34
+ class CompanyExperience
35
+ # Date must more than 1970-01-01
36
+ attr_accessor :company_name, :job_title, :start_date, :end_date, :details, :is_current
37
+
38
+ def initialize(experience={})
39
+ @company_name = experience['CompanyName']
40
+ @job_title = experience['JobTitle']
41
+ @start_date = experience['StartDate']
42
+ @end_date = experience['EndDate']
43
+ @details = experience['Details']
44
+ @is_current = %w(True ture).include?(experience['IsCurrent'])
45
+ end
46
+ end
47
+
48
+ def generate_experiences(company_experiences)
49
+ if !company_experiences.nil?
50
+ if company_experiences['CompanyExperience'].kind_of?(Array)
51
+ company_experiences['CompanyExperience'].map {|e| CompanyExperience.new(e)}
52
+ else # Hash
53
+ [CompanyExperience.new(company_experiences['CompanyExperience'])]
54
+ end
55
+ else
56
+ []
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,28 @@
1
+ module Spear
2
+ module Structure
3
+ module Resume
4
+ class Ownall < Structure::Base
5
+ attr_reader :resumes
6
+
7
+ def initialize(response)
8
+ super(response)
9
+ @resumes = extract_resume(@root['Resumes'])
10
+ end
11
+
12
+ private
13
+ def extract_resume(resumes, list=[])
14
+ unless resumes.nil?
15
+ if resumes['Resume'].kind_of?(Array)
16
+ resumes['Resume'].each do |resume|
17
+ list << resume
18
+ end
19
+ elsif resumes['Resume'].kind_of?(Hash)
20
+ list << resumes['Resume']
21
+ end
22
+ end
23
+ list
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,80 @@
1
+ module Spear
2
+ module Structure
3
+ module Resume
4
+ # after parse resume, we will call create resume api. So in this class, we will build
5
+ # the data class structure 'Create resume' needs.
6
+ class Parse < Structure::Base
7
+ include EmbededClass
8
+
9
+ attr_reader :resume, :hrxml_resume
10
+ attr_accessor :educations, :company_experiences, :employer_orgs, :languages, :custom_values
11
+ attr_accessor :resume_text, :total_years_experience
12
+
13
+ def initialize(response)
14
+ super(response)
15
+ @resume = @root['Resume'] || {}
16
+ @hrxml_resume = @resume['HRXMLResume']
17
+
18
+ @resume_text = @resume['ResumeText'] || ''
19
+ @total_years_experience = (@resume['TotalYearsExperience'].to_i rescue 0)
20
+ @educations = generate_educations(@resume['Educations'])
21
+ @company_experiences = generate_experiences(@resume['CompanyExperiences'])
22
+ end
23
+
24
+ def hash_for_create(external_user_id, host_site)
25
+ raise Spear::ParametersRequired.new(%w{UserExternalId HostSite}) if external_user_id.blank? or host_site.blank?
26
+
27
+ # Max Educations are 3
28
+ educations = []
29
+ @educations.each_with_index do |e, index|
30
+ break if index > 2
31
+ edu = {}
32
+ edu[:SchoolName] = e.school_name || ""
33
+ edu[:Major] = e.major || ""
34
+ edu[:DegreeCode] = e.degree_code || ""
35
+ edu[:GraduationDate] = e.graduation_date unless e.graduation_date.blank?
36
+ educations << edu
37
+ end
38
+
39
+ # Max CompanyExperiences are 5
40
+ company_experiences = []
41
+ @company_experiences.each_with_index do |ce, index|
42
+ break if index > 4
43
+ cen = {}
44
+ cen[:CompanyName] = ce.company_name || ""
45
+ cen[:JobTitle] = ce.job_title || ""
46
+ if ce.start_date.blank?
47
+ cen[:StartDate] = '1970-01-01'
48
+ else
49
+ cen[:StartDate] = ce.start_date
50
+ end
51
+ if ce.end_date.blank?
52
+ cen[:EndDate] = Time.now.strftime("%Y-%m-%d").to_s
53
+ else
54
+ cen[:EndDate] = ce.end_date
55
+ end
56
+ cen[:Details] = ce.details || ""
57
+ company_experiences << cen
58
+ end
59
+
60
+ {
61
+ :ExternalUserID => external_user_id,
62
+ :ShowContactInfo => true,
63
+ :Title => 'title',
64
+ :ResumeText => @resume_text,
65
+ :Visibility => 'Public',
66
+ :CanRelocateNationally => false,
67
+ :CanRelocateInternationally => false,
68
+ :TotalYearsExperience => @total_years_experience.to_s,
69
+ :HostSite => host_site,
70
+ :DesiredJobTypes => 'ETFE',
71
+ :CompanyExperiences => company_experiences,
72
+ :Educations => educations,
73
+ :Languages => [],
74
+ :CustomValues => []
75
+ }
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end