-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimsgbridge.rb
50 lines (39 loc) · 1.03 KB
/
imsgbridge.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
require 'sinatra'
require 'sinatra/jsonp'
require 'sinatra/config_file'
set :raise_errors, false
set :show_exceptions, false
config_file 'config.yml'
get '/imsgbridge' do
to = params['to']
message = params['message']
password_params = params['password']
password = settings.password
if password_params == password
system 'osascript <<EOF
tell application "Messages"
set targetService to 1st service whose service type = iMessage
set targetBuddy to buddy "' + to + '" of targetService
send "' + message + '" to targetBuddy
end tell
EOF'
data = {:status => 'sent'}
else
data = {:status => 'unauthenticated'}
end
JSONP data
end
get '/pebble/contacts' do
password_params = params['password']
password = settings.password
if password_params == password
data = {:contact => settings.contact, :status => 'received'}
else
data = {:status => 'unauthenticated'}
end
JSONP data
end
error do
data = {:status => 'error'}
JSONP data
end