Class: MindMatch::Client
- Inherits:
-
Object
- Object
- MindMatch::Client
- Defined in:
- lib/mind_match/client.rb
Constant Summary collapse
- EXP_ENTRY_FIELDS =
%w{position description custom_company technologies start_year end_year}.freeze
- EDU_ENTRY_FIELDS =
%{school_name degree discipline start_year end_year}.freeze
- DEFAULT_ENDPOINT =
'https://api.mindmatch.ai'.freeze
- PATH =
'/graphql'.freeze
Instance Method Summary collapse
- #add_feedback(request_id:, person_id:, position_id:, company_id:, value:, comment: nil) ⇒ Object
- #create_match(talent: nil, talents: [], position: nil, positions: [], companies: []) ⇒ Object
-
#initialize(token:, endpoint: DEFAULT_ENDPOINT) ⇒ Client
constructor
A new instance of Client.
- #query_match(id:, query: nil) ⇒ Object
Constructor Details
#initialize(token:, endpoint: DEFAULT_ENDPOINT) ⇒ Client
Returns a new instance of Client.
17 18 19 20 21 22 |
# File 'lib/mind_match/client.rb', line 17 def initialize(token:, endpoint: DEFAULT_ENDPOINT) @token = token uri = URI(endpoint) uri.path = PATH @conn = Faraday.new(url: uri.to_s, headers: headers) end |
Instance Method Details
#add_feedback(request_id:, person_id:, position_id:, company_id:, value:, comment: nil) ⇒ Object
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 |
# File 'lib/mind_match/client.rb', line 66 def add_feedback(request_id:, person_id:, position_id:, company_id:, value:, comment: nil) add_feedback_mutation = <<-GRAPHQL mutation ($input: FeedbackInput!) { addFeedback( input: $input ) { id requestId personId positionId companyId value comment } } GRAPHQL raw_response = conn.post do |req| req.body = JSON.generate( query: add_feedback_mutation, variables: { input: { requestId: request_id, personId: person_id, positionId: position_id, companyId: company_id, value: value, comment: comment }.delete_if { |_k, v| v.nil? } }.to_json ) end handle_error(raw_response) response = JSON.parse(raw_response.body) response.dig('data', 'addFeedback') end |
#create_match(talent: nil, talents: [], position: nil, positions: [], companies: []) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/mind_match/client.rb', line 24 def create_match(talent: nil, talents: [], position: nil, positions: [], companies: []) talents << talent talents = talents.compact positions << position companies = (companies + positions).compact raise ArgumentError, "missing keyword: talents" if talents.empty? raise ArgumentError, "missing keyword: companies" if companies.empty? create_matches(talents: talents, companies: companies) end |
#query_match(id:, query: nil) ⇒ Object
34 35 36 37 38 39 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 |
# File 'lib/mind_match/client.rb', line 34 def query_match(id:, query: nil) unless query.is_a?(QueryBuilder) query = (@query_match_query ||= QueryBuilder.new .with_results(%w(score personId positionId companyId)) .with_people(%w(id refId)) .with_positions(%w(id refId)) .build) end query_match_score = <<-GRAPHQL query ($id: String!) { getMatch(id: $id) { id status #{query.to_s} } } GRAPHQL raw_response = conn.get do |req| req.body = JSON.generate(query: query_match_score, variables: {id: id}.to_json) end handle_error(raw_response) response = JSON.parse(raw_response.body) match = response.dig('data', 'getMatch') if match&.has_key?('data') # FIX: remove data namespace in mindmatch api match = match.merge(match['data'] || query.to_h) match.delete('data') end match || query.to_h end |