-
Notifications
You must be signed in to change notification settings - Fork 1
/
queersync.rb
78 lines (56 loc) · 1.73 KB
/
queersync.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require 'hyperclient'
require './lib/osdi.rb'
require './lib/util.rb'
require 'dotenv'
require 'json'
require 'time'
Dotenv.load
config=JSON.parse(File.read(ENV['CONFIG_MAPPING_FILE']))
CONFIG=config
question_mapping=config['mapping'] || []
interval=config['interval_in_seconds']
start_date=Time.now - interval
puts "Start date #{start_date}"
start_date_string = start_date.iso8601
spoke=OSDI.new
spoke.trace_mode=config.dig('spoke','trace')
spoke.aep=config.dig('spoke','aep')
spoke.api_token=ENV['SPOKE_API_TOKEN']
spoke_aep=spoke.hyperclient
completed_people=[]
van=OSDI.new(config.dig('van'))
van.api_token=ENV['VAN_API_TOKEN']
new_answers_link=spoke_aep['osdi:answers']
unless config.dig('spoke','no_odata') == true
new_answers_link.query_params.merge!({
filter: "modified_date gt '#{start_date_string}'"
})
end
new_answers=new_answers_link['osdi:answers']
new_answers.each do |a|
person_self_link=a._links['osdi:person']._url
next if completed_people.include?(person_self_link)
next if (Time.parse(a.created_date)) < start_date
completed_people << person_self_link
osdi_person=a['osdi:person']
person=osdi_person.to_hash
msg=[
person['given_name'],
person['family_name']
].join(' ')
puts "Processing #{msg}"
psh=van.make_psh(person)
van_person=van.person_signup(psh)
van_person_url=van_person._links['self']._url
puts "Matched to VAN #{van_person_url}"
unless question_mapping.empty?
osdi_answers=osdi_person['osdi:answers']['osdi:answers']
canvass=Util.make_canvass(osdi_answers,question_mapping)
canvass_response=van.record_canvass(van_person,canvass)
if canvass_response['success']==true
puts "SUCCESS for #{msg}"
else
puts "FAILED for #{msg}"
end
end
end