-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfieldtrip-http.rb
executable file
·41 lines (30 loc) · 1.06 KB
/
fieldtrip-http.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
#!/usr/bin/env ruby
require 'sinatra'
require './fieldtrip.rb'
raise 'Too few arguments' if ARGV.count < 2
raise 'Too many arguments' if ARGV.count > 2
listen = ARGV[0].split(':')
target = ARGV[1].split(':')
raise 'Error parsing target' unless target.count == 2
configure do
set :port, listen[1] ? listen[1] : listen[0]
set :bind, listen[1] ? listen[0] : '0.0.0.0'
set :fieldtrip_client, FieldTrip::Client.new(target[0], target[1])
end
before do
headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE, OPTIONS'
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Headers'] = 'accept, authorization, origin'
end
get '/get/hdr' do
settings.fieldtrip_client.get_header
end
get '/get/dat' do
settings.fieldtrip_client.get_data params['begsample'].to_i, params['endsample'].to_i
end
get '/get/evt' do
settings.fieldtrip_client.get_events params['begevent'].to_i, params['endevent'].to_i
end
get '/wait/dat' do
settings.fieldtrip_client.wait_data params['nsamples'].to_i, params['nevents'].to_i, params['timeout'].to_i
end