mindmatch 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a5e6cb0f4091f4fa32cb40f19b4d06d3abef15f
4
- data.tar.gz: e2fd55af13ef1ab1692105c31c15d1e852d9ee50
3
+ metadata.gz: 89cf943e81c64ca7244ebb19141d8585c46aaec4
4
+ data.tar.gz: 85e541059898e04083bd8d84f050647895bf0957
5
5
  SHA512:
6
- metadata.gz: fd0605267030b41b7f531b07193ee22f1f79deec0f2801e6f4781e7cc75efb5d92977a7eb80af169f50558668057c219d6c69eb20d149ecc7de2178fab316d10
7
- data.tar.gz: '085d0bf5b3d5bceb9d6802879b1303064ae6dc7d5b0d2f72a929904da2f3c18421f012d6673c2cd057383d7e3dc4930054cc60bc5e13c8abaa9d49dbdad032fb'
6
+ metadata.gz: 26fe24e59fa73d9faf474248d1be778b70b9b1b724ec02f680cea201d52698dfe71fa6aaaf8fb4b45b7429cedb5d7adb0b7500d168dfffd48e3dee28a6f1d1b8
7
+ data.tar.gz: 0d153f13a6c08daf7886051cad02956db8d94dc76d1172a48f09c9a2b5683ef95d3ea43d6d7a16a70d739a7854be916adfba0ff4311360771bc019e81ac8bac9
@@ -38,8 +38,8 @@ module MindMatch
38
38
  end
39
39
 
40
40
  query_match_score = <<-GRAPHQL
41
- query getMatch {
42
- match: getMatch(id: "#{id}") {
41
+ query ($id: String!) {
42
+ getMatch(id: $id) {
43
43
  id
44
44
  status
45
45
  data {
@@ -50,16 +50,16 @@ module MindMatch
50
50
  GRAPHQL
51
51
 
52
52
  raw_response = conn.get do |req|
53
- req.body = JSON.generate(query: query_match_score)
53
+ req.body = JSON.generate(query: query_match_score, variables: {id: id}.to_json)
54
54
  end
55
55
  handle_error(raw_response)
56
56
  response = JSON.parse(raw_response.body)
57
- match = response.dig('data', 'match')
57
+ match = response.dig('data', 'getMatch')
58
58
  if match&.has_key?('data') # FIX: remove data namespace in mindmatch api
59
59
  match = match.merge(match['data'] || query.to_h)
60
60
  match.delete('data')
61
61
  end
62
- match
62
+ match || query.to_h
63
63
  end
64
64
 
65
65
  private
@@ -67,12 +67,12 @@ module MindMatch
67
67
 
68
68
  def create_matches(talents:, companies:)
69
69
  create_match_mutation = <<-GRAPHQL
70
- mutation createMatch {
71
- match: createMatch(
70
+ mutation ($companies: [CompanyInput], $people: [PersonInput]) {
71
+ createMatch(
72
72
  input: {
73
73
  data: {
74
- companies: [#{companies.map(&method(:companiesql)).join(',')}],
75
- people: [#{talents.map(&method(:talentql)).join(',')}]
74
+ companies: $companies,
75
+ people: $people
76
76
  }
77
77
  }
78
78
  ) {
@@ -82,67 +82,55 @@ module MindMatch
82
82
  GRAPHQL
83
83
 
84
84
  raw_response = conn.post do |req|
85
- req.body = JSON.generate(query: create_match_mutation)
85
+ req.body = JSON.generate(
86
+ query: create_match_mutation,
87
+ variables: {
88
+ companies: companies.map(&method(:companiesql)),
89
+ people: talents.map(&method(:talentql))
90
+ }.to_json
91
+ )
86
92
  end
87
93
  handle_error(raw_response)
88
94
  response = JSON.parse(raw_response.body)
89
- match = response.dig('data', 'match')
95
+ match = response.dig('data', 'createMatch')
90
96
  if match&.has_key?('data') # FIX: remove data namespece in mindmatch api
91
97
  match = match.merge(match['data'] || {'results'=>[], 'people'=>[], 'positions'=>[]})
92
98
  match.delete('data')
93
99
  end
94
- match['id']
100
+ match && match['id']
95
101
  end
96
102
 
97
103
  def positionql(position)
98
104
  position = stringify(position)
99
- <<-EOS.split.join(" ")
100
- {
101
- refId: "#{value(position['id'])}",
102
- name: "#{value(position['name'])}",
103
- description: "#{value(position['description'])}"
104
- }
105
- EOS
105
+ {
106
+ refId: position['id'],
107
+ name: position['name'],
108
+ description: position['description'],
109
+ technologies: position['technologies'] || []
110
+ }
106
111
  end
107
112
 
108
113
  def companiesql(company)
109
114
  company = stringify(company)
110
- if company.has_key?("positions")
111
- <<-EOS.split.join(" ")
112
- {
113
- name: "#{value(company['name'])}",
114
- location: #{[company['location']].flatten},
115
- url: "#{value(company['url'])}",
116
- profileUrls: #{company['profileUrls'] || []},
117
- positions: [#{company['positions'].map(&method(:positionql)).join(', ')}]
118
- }
119
- EOS
120
- else
121
- warn "[DEPRECATION] providing postition without company information is deprecated."
122
- <<-EOS.split.join(" ")
123
- {
124
- name: "company",
125
- location: ["location"],
126
- url: "http://example.com",
127
- profileUrls: ["https://github.com/honeypotio", "https://linkedin.com/company/honeypot"],
128
- positions: [#{positionql(company)}]
129
- }
130
- EOS
131
- end
115
+ {
116
+ name: company['name'],
117
+ location: [company['location']].flatten,
118
+ url: company['url'],
119
+ profileUrls: company['profileUrls'] || [],
120
+ positions: company.fetch('positions', []).map(&method(:positionql))
121
+ }
132
122
  end
133
123
 
134
124
  def talentql(tal)
135
125
  tal = stringify(tal)
136
- <<-EOS.split.join(" ")
137
- {
138
- refId: "#{value(tal['id'])}",
139
- name: "#{value(tal['name'])}",
140
- email: "#{value(tal['email'])}",
141
- profileUrls: #{tal['profileUrls'] || []},
142
- resumeUrl: "#{value(tal['resumeUrl'])}",
143
- skills: #{tal['skills'].map(&method(:value)) || []}
144
- }
145
- EOS
126
+ {
127
+ refId: tal['id'],
128
+ name: tal['name'],
129
+ email: tal['email'],
130
+ profileUrls: tal['profileUrls'] || [],
131
+ resumeUrl: tal['resumeUrl'],
132
+ skills: tal['skills'] || []
133
+ }
146
134
  end
147
135
 
148
136
  def headers
@@ -154,7 +142,7 @@ module MindMatch
154
142
  end
155
143
 
156
144
  def handle_error(raw_response)
157
- return if raw_response.status.to_s =~ /2\d\d/
145
+ return if raw_response.status.to_s =~ /2\d\d/ and error_free?(raw_response.body)
158
146
 
159
147
  case raw_response.status
160
148
  when 400 then raise(ArgumentError, raw_response.body)
@@ -164,12 +152,14 @@ module MindMatch
164
152
  end
165
153
  end
166
154
 
167
- def stringify(hash)
168
- JSON.parse(JSON.generate(hash))
155
+ def error_free?(body)
156
+ !JSON.parse(body).has_key?('errors')
157
+ rescue StandardError
158
+ return false
169
159
  end
170
160
 
171
- def value(text)
172
- text.to_s.gsub('"','\"')
161
+ def stringify(hash)
162
+ JSON.parse(JSON.generate(hash))
173
163
  end
174
164
  end
175
165
  end
@@ -1,3 +1,3 @@
1
1
  module MindMatch
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mindmatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - MindMatch
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2017-10-06 00:00:00.000000000 Z
13
+ date: 2017-10-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday