Class: Psychometric::Providers::TopTalentSolutions
- Inherits:
-
Psychometric::Provider
- Object
- Psychometric::Provider
- Psychometric::Providers::TopTalentSolutions
- Includes:
- HTTParty
- Defined in:
- lib/psychometric/providers/top_talent_solutions.rb
Instance Method Summary collapse
-
#assessments ⇒ Object
Returns assessments linked to this account once authenticated.
-
#authenticate! ⇒ Object
base_uri(ENV == ‘production’ ? ‘www.tts-assess.com/api’ : ‘www.tts-assessments.com/api’).
- #authenticated? ⇒ Boolean
-
#results(assessment) ⇒ Object
Given an Assessment returns the Results recorded for that Assessment.
Methods inherited from Psychometric::Provider
Constructor Details
This class inherits a constructor from Psychometric::Provider
Instance Method Details
#assessments ⇒ Object
Returns assessments linked to this account once authenticated
NOTE: This is not currently possible with the TTS API
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/psychometric/providers/top_talent_solutions.rb', line 33 def assessments raise Psychometric::Provider::AuthenticationError.new('You need to authenticate first') unless authenticated? raise NotImplementedError # API does not expose Model IDs response = self.class.get '/getProjectList/en_ZA', headers: { 'Authorization' => "Bearer #{@token}", 'Accept' => 'application/json' } # Response Code - 401 {'result': "error", 'errors': {"Not enough permission for this request."}} raise response['errors'].to_json if response['result'] == 'error' # Response Code - 200 { 'result': "success", 'data': [{ 'id': 5, 'internalName': "Internal Project Name 1", 'completedCandidate': 10, 'status': "In Progress", 'costcode': "free" }] if response.code == 200 && response['result'] == 'success' response['data'].map do |hash| # hash end else raise 'Unknown error' end end |
#authenticate! ⇒ Object
base_uri(ENV == ‘production’ ? ‘www.tts-assess.com/api’ : ‘www.tts-assessments.com/api’)
16 17 18 19 20 21 22 23 24 |
# File 'lib/psychometric/providers/top_talent_solutions.rb', line 16 def authenticate! response = self.class.post '/generateToken', headers: { 'Accept' => 'application/json' }, body: { 'username' => @authentication[:username], 'password' => @authentication[:password] }.to_json # Response Code - 401 {"result": "error", "errors": "Bad credentials exception!"} raise response['errors'].to_json if response['result'] == 'error' # Response Code - 200 { "result": "success", "token": "YknYEjMRjVMaIGUTJQ8cWO9xAXSyK0awlQzGpk6_nzhM0n140dUMn-Ja- S9BYKbWc5HIj8LA" } @token = response['token'] if response.code == 200 && response['result'] == 'success' end |
#authenticated? ⇒ Boolean
26 27 28 |
# File 'lib/psychometric/providers/top_talent_solutions.rb', line 26 def authenticated? !@token.nil? && !@token.empty? end |
#results(assessment) ⇒ Object
Given an Assessment returns the Results recorded for that Assessment
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/psychometric/providers/top_talent_solutions.rb', line 53 def results(assessment) raise Psychometric::Provider::AuthenticationError.new('You need to authenticate first') unless authenticated? response = self.class.post '/getDataExtract', timeout: 180, headers: { 'Authorization' => "Bearer #{@token}", 'Accept' => 'application/json' }, body: { 'projectId' => assessment.identity[:project_id], 'modelId' => assessment.identity[:model_id], 'locale' => 'en_ZA', }.to_json # Response Code - 400 { 'result': 'error', 'errors': ['No instrument norm combination found']} raise response['errors'].to_json if response['result'] == 'error' # Response Code - 200 { 'result': 'success', 'data': [{ 'participantId': 12, 'name': "john", 'surname': "doe", 'testCompleted': "05 July 2016 14:25:00", 'variable1': 2, 'variable2': 4, 'variable3': 5 }, ...] } if response['result'] == 'success' response['data'].map do |item| Psychometric::Result.new.tap do |result| result.subject = Psychometric::Subject.new( country: case item['participantId'] when /^\d{13}$/ 'ZA' when /^G\d+/, /^\d{10}$/ 'GH' when /^\d{9}$/ 'BW' else 'XX' end, identity: item['participantId'], email: item['email'], name: "#{item['name']} #{item['surname']}", gender: item['Gender|gender|Raw|Raw score'], title: item['Title|title|Raw|Raw score'], ) # NOTE: This may need to be configurable in the future result.aggregate = item['OverAll'].try(:to_f) values = item.reject do |key, _v| [ 'participantGUID', 'participantId', 'email', 'name', 'surname', 'Gender|gender|Raw|Raw score', 'Title|title|Raw|Raw score', 'OverAll', 'Highest Qualification|highestQualification|Raw|Raw score', 'Cultural Background|culturalBackground|Raw|Raw score', ].include? key end result.values = Hash[values.map { |k, v| [k.split('|').first, v] }] end end else raise 'Unknown error' end end |