forked from plamoni/SiriProxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
siriObjectGenerator.rb
324 lines (279 loc) · 9.6 KB
/
siriObjectGenerator.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
require 'rubygems'
require 'uuidtools'
def generate_siri_utterance(refId, text, speakableText=text, listenAfterSpeaking=false)
object = SiriAddViews.new
object.make_root(refId)
object.views << SiriAssistantUtteranceView.new(text, speakableText, "Misc#ident", listenAfterSpeaking)
return object.to_hash
end
class SiriObject
attr_accessor :klass, :group, :properties
def initialize(klass, group)
@klass = klass
@group = group
@properties = {}
end
#watch out for circular references!
def to_hash
hash = {
"class" => self.klass,
"group" => self.group,
"properties" => {}
}
(hash["refId"] = self.refId) rescue nil
(hash["aceId"] = self.aceId) rescue nil
self.properties.each_key { |key|
if self.properties[key].class == Array
hash["properties"][key] = []
self.properties[key].each { |val| hash["properties"][key] << (val.to_hash rescue val) }
else
hash["properties"][key] = (self.properties[key].to_hash rescue self.properties[key])
end
}
hash
end
def make_root(refId=nil, aceId=nil)
self.extend(SiriRootObject)
self.refId = (refId or self.random_refId)
self.aceId = (aceId or self.random_aceId)
end
end
def add_property_to_class(klass, prop)
klass.send(:define_method, (prop.to_s + "=").to_sym) { |value|
self.properties[prop.to_s] = value
}
klass.send(:define_method, prop.to_s.to_sym) {
self.properties[prop.to_s]
}
end
module SiriRootObject
attr_accessor :refId, :aceId
def random_refId
UUIDTools::UUID.random_create.to_s.upcase
end
def random_aceId
UUIDTools::UUID.random_create.to_s
end
end
class SiriAddViews < SiriObject
def initialize(scrollToTop=false, temporary=false, dialogPhase="Completion", views=[])
super("AddViews", "com.apple.ace.assistant")
self.scrollToTop = scrollToTop
self.views = views
self.temporary = temporary
self.dialogPhase = dialogPhase
end
end
add_property_to_class(SiriAddViews, :scrollToTop)
add_property_to_class(SiriAddViews, :views)
add_property_to_class(SiriAddViews, :temporary)
add_property_to_class(SiriAddViews, :dialogPhase)
#####
# VIEWS
#####
class SiriAssistantUtteranceView < SiriObject
def initialize(text="", speakableText=text, dialogIdentifier="Misc#ident", listenAfterSpeaking=false)
super("AssistantUtteranceView", "com.apple.ace.assistant")
self.text = text
self.speakableText = speakableText
self.dialogIdentifier = dialogIdentifier
self.listenAfterSpeaking = listenAfterSpeaking
end
end
add_property_to_class(SiriAssistantUtteranceView, :text)
add_property_to_class(SiriAssistantUtteranceView, :speakableText)
add_property_to_class(SiriAssistantUtteranceView, :dialogIdentifier)
add_property_to_class(SiriAssistantUtteranceView, :listenAfterSpeaking)
class SiriMapItemSnippet < SiriObject
def initialize(userCurrentLocation=true, items=[])
super("MapItemSnippet", "com.apple.ace.localsearch")
self.userCurrentLocation = userCurrentLocation
self.items = items
end
end
add_property_to_class(SiriMapItemSnippet, :userCurrentLocation)
add_property_to_class(SiriMapItemSnippet, :items)
class SiriButton < SiriObject
def initialize(text="Button Text", commands=[])
super("Button", "com.apple.ace.assistant")
self.text = text
self.commands = commands
end
end
add_property_to_class(SiriButton, :text)
add_property_to_class(SiriButton, :commands)
class SiriAnswerSnippet < SiriObject
def initialize(answers=[], confirmationOptions=nil)
super("Snippet", "com.apple.ace.answer")
self.answers = answers
if confirmationOptions
# need to figure out good way to do API for this
self.confirmationOptions = confirmationOptions
end
end
end
add_property_to_class(SiriAnswerSnippet, :answers)
add_property_to_class(SiriAnswerSnippet, :confirmationOptions)
#####
# Items
#####
class SiriMapItem < SiriObject
def initialize(label="Apple Headquarters", location=SiriLocation.new, detailType="BUSINESS_ITEM")
super("MapItem", "com.apple.ace.localsearch")
self.label = label
self.detailType = detailType
self.location = location
end
end
add_property_to_class(SiriMapItem, :label)
add_property_to_class(SiriMapItem, :detailType)
add_property_to_class(SiriMapItem, :location)
#####
# Commands
#####
class SiriSendCommands < SiriObject
def initialize(commands=[])
super("SendCommands", "com.apple.ace.system")
self.commands=commands
end
end
add_property_to_class(SiriSendCommands, :commands)
class SiriConfirmationOptions < SiriObject
def initialize(submitCommands=[], cancelCommands=[], denyCommands=[], confirmCommands=[], denyText="Cacnel", cancelLabel="Cancel", submitLabel="Send", confirmText="Send", cancelTrigger="Deny")
super("ConfirmationOptions", "com.apple.ace.assistant")
self.submitCommands=submitCommands
self.cancelCommands=cancelCommands
self.denyCommands=denyCommands
self.confirmCommands=confirmCommands
self.denyText = denyText
self.cancelLabel = cancelLabel
self.submitLabel = submitLabel
self.confirmText = confirmText
self.cancelTrigger = cancelTrigger
end
end
add_property_to_class(SiriConfirmationOptions, :submitCommands)
add_property_to_class(SiriConfirmationOptions, :cancelCommands)
add_property_to_class(SiriConfirmationOptions, :denyCommands)
add_property_to_class(SiriConfirmationOptions, :confirmCommands)
add_property_to_class(SiriConfirmationOptions, :denyText)
add_property_to_class(SiriConfirmationOptions, :cancelLabel)
add_property_to_class(SiriConfirmationOptions, :submitLabel)
add_property_to_class(SiriConfirmationOptions, :confirmText)
add_property_to_class(SiriConfirmationOptions, :cancelTrigger)
class SiriConfirmSnippetCommand < SiriObject
def initialize(requestId="")
super("ConfirmSnippet", "com.apple.ace.assistant")
self.requestId=requestId
end
end
add_property_to_class(SiriConfirmSnippetCommand, :requestId)
class SiriCancelSnippetCommand < SiriObject
def initialize(requestId="")
super("ConfirmSnippet", "com.apple.ace.assistant")
self.requestId=requestId
end
end
add_property_to_class(SiriCancelSnippetCommand, :requestId)
#####
# Objects
#####
class SiriLocation < SiriObject
def initialize(label="Apple", street="1 Infinite Loop", city="Cupertino", stateCode="CA", countryCode="US", postalCode="95014", latitude=37.3317031860352, longitude=-122.030089795589)
super("Location", "com.apple.ace.system")
self.label = label
self.street = street
self.city = city
self.stateCode = stateCode
self.countryCode = countryCode
self.postalCode = postalCode
self.latitude = latitude
self.longitude = longitude
end
end
add_property_to_class(SiriLocation, :label)
add_property_to_class(SiriLocation, :street)
add_property_to_class(SiriLocation, :city)
add_property_to_class(SiriLocation, :stateCode)
add_property_to_class(SiriLocation, :countryCode)
add_property_to_class(SiriLocation, :postalCode)
add_property_to_class(SiriLocation, :latitude)
add_property_to_class(SiriLocation, :longitude)
class SiriAnswer < SiriObject
def initialize(title="", lines=[])
super("Object", "com.apple.ace.answer")
self.title = title
self.lines = lines
end
end
add_property_to_class(SiriAnswer, :title)
add_property_to_class(SiriAnswer, :lines)
class SiriAnswerLine < SiriObject
def initialize(text="", image="")
super("ObjectLine", "com.apple.ace.answer")
self.text = text
self.image = image
end
end
add_property_to_class(SiriAnswerLine, :text)
add_property_to_class(SiriAnswerLine, :image)
#####
# Guzzoni Commands (commands that typically come from the server side)
#####
class SiriGetRequestOrigin < SiriObject
def initialize(desiredAccuracy="HundredMeters", searchTimeout=8.0, maxAge=1800)
super("GetRequestOrigin", "com.apple.ace.system")
self.desiredAccuracy = desiredAccuracy
self.searchTimeout = searchTimeout
self.maxAge = maxAge
end
end
add_property_to_class(SiriGetRequestOrigin, :desiredAccuracy)
add_property_to_class(SiriGetRequestOrigin, :searchTimeout)
add_property_to_class(SiriGetRequestOrigin, :maxAge)
class SiriRequestCompleted < SiriObject
def initialize(callbacks=[])
super("RequestCompleted", "com.apple.ace.system")
self.callbacks = callbacks
end
end
add_property_to_class(SiriRequestCompleted, :callbacks)
#####
# iPhone Responses (misc meta data back to the server)
#####
class SiriStartRequest < SiriObject
def initialize(utterance="Testing", handsFree=false, proxyOnly=false)
super("StartRequest", "com.apple.ace.system")
self.utterance = utterance
self.handsFree = handsFree
if proxyOnly # dont send local when false since its non standard
self.proxyOnly = proxyOnly
end
end
end
add_property_to_class(SiriStartRequest, :utterance)
add_property_to_class(SiriStartRequest, :handsFree)
add_property_to_class(SiriStartRequest, :proxyOnly)
class SiriSetRequestOrigin < SiriObject
def initialize(longitude=-122.030089795589, latitude=37.3317031860352, desiredAccuracy="HundredMeters", altitude=0.0, speed=1.0, direction=1.0, age=0, horizontalAccuracy=50.0, verticalAccuracy=10.0)
super("SetRequestOrigin", "com.apple.ace.system")
self.horizontalAccuracy = horizontalAccuracy
self.latitude = latitude
self.desiredAccuracy = desiredAccuracy
self.altitude = altitude
self.speed = speed
self.longitude = longitude
self.verticalAccuracy = verticalAccuracy
self.direction = direction
self.age = age
end
end
add_property_to_class(SiriSetRequestOrigin, :horizontalAccuracy)
add_property_to_class(SiriSetRequestOrigin, :latitude)
add_property_to_class(SiriSetRequestOrigin, :desiredAccuracy)
add_property_to_class(SiriSetRequestOrigin, :altitude)
add_property_to_class(SiriSetRequestOrigin, :speed)
add_property_to_class(SiriSetRequestOrigin, :longitude)
add_property_to_class(SiriSetRequestOrigin, :verticalAccuracy)
add_property_to_class(SiriSetRequestOrigin, :direction)
add_property_to_class(SiriSetRequestOrigin, :age)