forked from samuelli/bark_client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cse_bark.rb
executable file
·80 lines (68 loc) · 1.81 KB
/
cse_bark.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
79
80
#!/usr/bin/env ruby
require './client'
@client = WebClient.new(ENV["CSE_HOST"], ENV["CSE_USERNAME"], ENV["CSE_PASSWORD"])
events = @client.events
events.each_with_index do |event, i|
puts "#{i}. #{event.name}"
end
if events.any?
print "Select an event: ".yellow
selected = gets.to_i
if selected < events.count
@event = events[selected]
else
puts "Invalid Event"
exit
end
else
puts "No Events"
exit
end
def scan_card(result, rfid)
if result['status'] == 'CHECKED_IN'
puts "Checked in!".green
puts result['account'].inspect
elsif result['status'] == 'NOT_MEMBER'
puts "Not Registered".red
if rfid
print "Register user with card #{rfid} (y/n): ".yellow
f = gets.chomp
if f == "y"
print "Student ID: ".yellow
student_id = gets.chomp
reg_result = @client.register_user(:student_id => student_id, :rfid => rfid).body
if reg_result['status'] == "REGISTERED"
scan_card(@event.check_in_with_rfid(rfid).body, rfid)
else
puts "Failed to register user - #{result[:reason]}".red
end
end
end
elsif result['status'] == 'INVALID'
puts "Invalid Card - #{result['reason']}".red
else
puts "SCAN_ERROR - #{result.inspect}".red
end
puts
end
begin
while true
puts "Scan a card!".green
rfid = Reader::scan
Thread.new do
`afplay /System/Library/Sounds/Ping.aiff`
end
puts "Loading...".yellow
result = @event.check_in_with_rfid(rfid).body
scan_card(result, rfid)
end
rescue Errno::ENOENT => ex
puts "Card reader not detected".red
puts "Student number entry mode only".red
while true
print "Enter student number: ".yellow
student_id = gets.chomp
result = @event.check_in_with_student_id(student_id).body
scan_card(result, nil)
end
end