ruby-macrodroid 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dfb49da8914ecdd5cc21ca0223801fa0d432890a3df4c352ab7c3914c1bd63fe
4
- data.tar.gz: 9f402e6d1c9dbd17f5cb7d3741bcc7c487461a5438adf3cba81a71df9feb50f9
3
+ metadata.gz: f4d111f7d953dba3eeb6940e3e1f31af4410765fbd4c739de9b53c0d84bac137
4
+ data.tar.gz: 2d8a574b96647abb40194e3885f38153e1de3b50d3f8f86541698b766981f9d8
5
5
  SHA512:
6
- metadata.gz: 0753ef46f3cdbc1e5a8fb6539747e662a2e537089aa83e32ecf47c89334b1acb71ced47f77230e1fcae00314d8dd70e8e4d37380c27f25ebb0ccafe837121daa
7
- data.tar.gz: e78f3fc06bcdbd1685de98d5473b2564d904a722053527505002f5a5bbfa43e51e99832d2a9a29eb5a12d3e9bab94d91429f78628625e74acbae6876b909f43a
6
+ metadata.gz: 5184ff198c42f2e75dbfd232a9b5e7ef18bd37e0484aa697983f9cf950e0811659cbdc6936d1b5f622f719de1b8bee9ba7c10c5ec22e06be5aac34530ed5d4a2
7
+ data.tar.gz: 8f3020868a714825f8e06a04b461761039048e86ecbc22cd70413cbf860bfebb4b61d9c10315530037d1248dcfc3dc8d2d0ccb7be62fe25a625a5045c3a2bade
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -2,8 +2,114 @@
2
2
 
3
3
  # file: ruby-macrodroid.rb
4
4
 
5
- require 'uuid'
5
+ # This file contains the following classes:
6
+ #
7
+ # ## Nlp classes
8
+ #
9
+ # TriggersNlp ActionsNlp ConstraintsNlp
10
+ #
11
+ #
12
+ # ## Macro class
13
+ #
14
+ # Macro
15
+ #
16
+ #
17
+ # ## Error class
18
+ #
19
+ # MacroDroidError
20
+ #
21
+ #
22
+ # ## Droid class
23
+ #
24
+ # MacroDroid
25
+ #
26
+ #
27
+ # ## Map class
28
+ #
29
+ # GeofenceMap
30
+ #
31
+ #
32
+ # ## Object class
33
+ #
34
+ # MacroObject
35
+ #
36
+ #
37
+ # ## Trigger classes
38
+ #
39
+ # Trigger WebHookTrigger WifiConnectionTrigger
40
+ # ApplicationInstalledRemovedTrigger ApplicationLaunchedTrigger
41
+ # BatteryLevelTrigger BatteryTemperatureTrigger PowerButtonToggleTrigger
42
+ # ExternalPowerTrigger CallActiveTrigger IncomingCallTrigger
43
+ # OutgoingCallTrigger CallEndedTrigger CallMissedTrigger IncomingSMSTrigger
44
+ # WebHookTrigger WifiConnectionTrigger BluetoothTrigger HeadphonesTrigger
45
+ # SignalOnOffTrigger UsbDeviceConnectionTrigger WifiSSIDTrigger
46
+ # CalendarTrigger TimerTrigger StopwatchTrigger DayTrigger
47
+ # RegularIntervalTrigger DeviceEventsTrigger AirplaneModeTrigger
48
+ # AutoSyncChangeTrigger DayDreamTrigger DockTrigger FailedLoginTrigger
49
+ # GPSEnabledTrigger MusicPlayingTrigger DeviceUnlockedTrigger
50
+ # AutoRotateChangeTrigger ClipboardChangeTrigger BootTrigger
51
+ # IntentReceivedTrigger NotificationTrigger ScreenOnOffTrigger
52
+ # SilentModeTrigger WeatherTrigger GeofenceTrigger SunriseSunsetTrigger
53
+ # SensorsTrigger ActivityRecognitionTrigger ProximityTrigger
54
+ # ShakeDeviceTrigger FlipDeviceTrigger OrientationTrigger
55
+ # FloatingButtonTrigger ShortcutTrigger VolumeButtonTrigger
56
+ # MediaButtonPressedTrigger SwipeTrigger
57
+ #
58
+ #
59
+ # ## Action classes
60
+ #
61
+ # Action LocationAction ShareLocationAction ApplicationAction
62
+ # LaunchActivityAction KillBackgroundAppAction OpenWebPageAction CameraAction
63
+ # UploadPhotoAction TakePictureAction ConnectivityAction SetWifiAction
64
+ # SetBluetoothAction SetBluetoothAction SendIntentAction DateTimeAction
65
+ # SetAlarmClockAction StopWatchAction SayTimeAction DeviceAction
66
+ # AndroidShortcutsAction ClipboardAction PressBackAction SpeakTextAction
67
+ # UIInteractionAction VoiceSearchAction DeviceSettingsAction
68
+ # ExpandCollapseStatusBarAction LaunchHomeScreenAction CameraFlashLightAction
69
+ # VibrateAction SetAutoRotateAction DayDreamAction SetKeyboardAction
70
+ # SetKeyguardAction CarModeAction ChangeKeyboardAction SetWallpaperAction
71
+ # FileAction OpenFileAction LocationAction ForceLocationUpdateAction
72
+ # ShareLocationAction SetLocationUpdateRateAction LoggingAction
73
+ # AddCalendarEntryAction LogAction ClearLogAction MediaAction
74
+ # RecordMicrophoneAction PlaySoundAction MessagingAction SendEmailAction
75
+ # SendSMSAction UDPCommandAction NotificationsAction ClearNotificationsAction
76
+ # MessageDialogAction AllowLEDNotificationLightAction
77
+ # SetNotificationSoundAction SetNotificationSoundAction
78
+ # SetNotificationSoundAction NotificationAction ToastAction PhoneAction
79
+ # AnswerCallAction ClearCallLogAction OpenCallLogAction RejectCallAction
80
+ # MakeCallAction SetRingtoneAction ScreenAction SetBrightnessAction
81
+ # ForceScreenRotationAction ScreenOnAction DimScreenAction KeepAwakeAction
82
+ # SetScreenTimeoutAction VolumeAction SilentModeVibrateOffAction
83
+ # SetVibrateAction VolumeIncrementDecrementAction SpeakerPhoneAction
84
+ # SetVolumeAction
85
+ #
86
+ #
87
+ # ## Constraint classes
88
+ #
89
+ # Constraint TimeOfDayConstraint BatteryLevelConstraint
90
+ # BatterySaverStateConstraint BatteryTemperatureConstraint
91
+ # ExternalPowerConstraint BluetoothConstraint GPSEnabledConstraint
92
+ # LocationModeConstraint SignalOnOffConstraint WifiConstraint
93
+ # CellTowerConstraint IsRoamingConstraint DataOnOffConstraint
94
+ # WifiHotSpotConstraint CalendarConstraint DayOfWeekConstraint
95
+ # TimeOfDayConstraint DayOfMonthConstraint MonthOfYearConstraint
96
+ # SunsetSunriseConstraint AirplaneModeConstraint AutoRotateConstraint
97
+ # DeviceLockedConstraint RoamingOnOffConstraint TimeSinceBootConstraint
98
+ # AutoSyncConstraint NFCStateConstraint IsRootedConstraint VpnConstraint
99
+ # MacroEnabledConstraint ModeConstraint TriggerThatInvokedConstraint
100
+ # LastRunTimeConstraint HeadphonesConnectionConstraint MusicActiveConstraint
101
+ # NotificationPresentConstraint PriorityModeConstraint
102
+ # NotificationVolumeConstraint InCallConstraint PhoneRingingConstraint
103
+ # BrightnessConstraint VolumeConstraint SpeakerPhoneConstraint
104
+ # DarkThemeConstraint ScreenOnOffConstraint VolumeLevelConstraint
105
+ # FaceUpDownConstraint LightLevelConstraint DeviceOrientationConstraint
106
+ # ProximitySensorConstraint
107
+
108
+
109
+
6
110
  require 'yaml'
111
+ require 'rowx'
112
+ require 'uuid'
7
113
  require 'glw'
8
114
  require 'geozone'
9
115
  require 'rxfhelper'
@@ -68,6 +174,11 @@ class TriggersNlp
68
174
  [GeofenceTrigger, {name: name, enter_area: enter_area}]
69
175
  end
70
176
 
177
+ get /^location (entered|exited) \(([^\)]+)/i do |direction, name|
178
+ enter_area = direction.downcase.to_sym == :entered
179
+ [GeofenceTrigger, {name: name, enter_area: enter_area}]
180
+ end
181
+
71
182
  end
72
183
 
73
184
  alias find_trigger run_route
@@ -153,6 +264,12 @@ class ActionsNlp
153
264
  [OpenWebPageAction, url_to_open: url]
154
265
 
155
266
  end
267
+
268
+ # e.g. webhook entered_kitchen
269
+ #
270
+ get /webhook|HTTP GET/i do
271
+ [OpenWebPageAction, {}]
272
+ end
156
273
 
157
274
 
158
275
  end
@@ -337,19 +454,20 @@ class Macro
337
454
  end
338
455
 
339
456
  def import_xml(node)
340
-
457
+
341
458
  if @debug then
342
459
  puts 'inside Macro#import_xml'
343
460
  puts 'node: ' + node.xml.inspect
344
461
  end
345
462
 
346
- @title = node.attributes[:name]
347
- @description = node.attributes[:description]
348
-
349
463
  if node.element('triggers') then
350
-
464
+
351
465
  # level 2
352
466
 
467
+ @title = node.attributes[:name]
468
+ @description = node.attributes[:description]
469
+
470
+
353
471
  # get all the triggers
354
472
  @triggers = node.xpath('triggers/*').map do |e|
355
473
 
@@ -385,6 +503,12 @@ class Macro
385
503
 
386
504
  # Level 1
387
505
 
506
+ puts 'import_xml: inside level 1' if @debug
507
+
508
+ @title = node.text('macro') || node.attributes[:name]
509
+
510
+ #@description = node.attributes[:description]
511
+
388
512
  tp = TriggersNlp.new
389
513
 
390
514
  @triggers = node.xpath('trigger').map do |e|
@@ -403,11 +527,21 @@ class Macro
403
527
 
404
528
  @actions = node.xpath('action').map do |e|
405
529
 
530
+ puts 'action e: ' + e.xml.inspect if @debug
406
531
  r = ap.find_action e.text
407
532
  puts 'found action ' + r.inspect if @debug
408
533
 
409
534
  if r then
410
- r[0].new(r[1])
535
+
536
+ a = e.xpath('item/*')
537
+
538
+ h = if a.any? then
539
+ a.map {|node| [node.name.to_sym, node.text.to_s]}.to_h
540
+ else
541
+ {}
542
+ end
543
+
544
+ r[0].new(r[1].merge(h))
411
545
  end
412
546
 
413
547
  end
@@ -570,15 +704,21 @@ class MacroDroid
570
704
 
571
705
  puts 's: ' + s.inspect if @debug
572
706
 
573
- xml = if s =~ /m:\s/ then
574
- puts 'before text_to_xml' if @debug
575
- text_to_xml(s)
707
+ if s =~ /m(?:acro)?:\s/ then
708
+
709
+ puts 'before RowX.new' if @debug
710
+
711
+ s2 = s.gsub(/^m:/,'macro:').gsub(/^t:/,'trigger:')\
712
+ .gsub(/^a:/,'action:').gsub(/^c:/,'constraint:')
713
+ xml = RowX.new(s2.gsub(/^#.*/,'')).to_xml
714
+ import_rowxml(xml)
576
715
  elsif s =~ /^# /
577
- pc_to_xml(s)
716
+ xml = pc_to_xml(s)
717
+ import_xml(xml)
578
718
  else
579
719
  raise MacroDroidError, 'invalid input'
580
720
  end
581
- import_xml(xml)
721
+
582
722
  @h = build_h
583
723
 
584
724
 
@@ -690,9 +830,28 @@ class MacroDroid
690
830
 
691
831
  end
692
832
 
833
+ def import_rowxml(raws)
834
+
835
+ s = RXFHelper.read(raws).first
836
+ puts 's: ' + s.inspect if $debug
837
+ doc = Rexle.new(s)
838
+ puts 'after doc' if $debug
839
+
840
+ @macros = doc.root.xpath('item').map do |node|
841
+
842
+ Macro.new.import_xml(node)
843
+
844
+ end
845
+
846
+ end
847
+
693
848
  def import_xml(raws)
694
849
 
695
- puts 'raws: ' + raws.inspect if @debug
850
+ if @debug then
851
+ puts 'inside import_xml'
852
+
853
+ puts 'raws: ' + raws.inspect
854
+ end
696
855
  s = RXFHelper.read(raws).first
697
856
  puts 's: ' + s.inspect if @debug
698
857
  doc = Rexle.new(s)
@@ -700,14 +859,10 @@ class MacroDroid
700
859
  if @debug then
701
860
  puts 'doc: ' + doc.root.xml
702
861
  end
703
-
704
- debug = @debug
705
-
862
+
706
863
  @macros = doc.root.xpath('macro').map do |node|
707
864
 
708
- macro = Macro.new @title, debug: debug
709
- macro.import_xml(node)
710
- macro
865
+ Macro.new.import_xml(node)
711
866
 
712
867
  end
713
868
  end
@@ -732,36 +887,7 @@ class MacroDroid
732
887
  doc = Rexle.new([:macros, {}, '', *macros])
733
888
  doc.root.xml pretty: true
734
889
 
735
- end
736
-
737
- def text_to_xml(s)
738
-
739
- a = s.split(/.*(?=^m:)/)
740
- puts 'a : ' + a.inspect if @debug
741
- a.map!(&:chomp)
742
-
743
- macros = a.map do |x|
744
-
745
- lines = x.lines
746
- puts 'lines: ' + lines.inspect if @debug
747
-
748
- name = lines.shift[/^m: +(.*)/,1]
749
- h = {t: [], a: [], c: []}
750
-
751
- lines.each {|line| h[line[0].to_sym] << line[/^\w: +(.*)/,1] }
752
- triggers = h[:t].map {|text| [:trigger, {}, text]}
753
- actions = h[:a].map {|text| [:action, {}, text]}
754
- constraints = h[:c].map {|text| [:constraint, {}, text]}
755
-
756
- [:macro, {name: name},'', *triggers, *actions, *constraints]
757
-
758
- end
759
-
760
- doc = Rexle.new([:macros, {}, '', *macros])
761
- doc.root.xml pretty: true
762
-
763
- end
764
-
890
+ end
765
891
 
766
892
  end
767
893
 
@@ -2117,6 +2243,8 @@ end
2117
2243
  class OpenWebPageAction < ApplicationAction
2118
2244
 
2119
2245
  def initialize(h={})
2246
+
2247
+ h[:url_to_open] = h[:url] if h[:url]
2120
2248
 
2121
2249
  options = {
2122
2250
  variable_to_save_response: {:m_stringValue=>"", :m_name=>"", :m_decimalValue=>0.0, :isLocal=>true, :m_booleanValue=>false, :excludeFromLog=>false, :m_intValue=>0, :m_type=>2},
@@ -2126,12 +2254,12 @@ class OpenWebPageAction < ApplicationAction
2126
2254
  block_next_action: false
2127
2255
  }
2128
2256
 
2129
- super(options.merge h)
2257
+ super(options.merge filter(options,h))
2130
2258
 
2131
2259
  end
2132
2260
 
2133
2261
  def to_s()
2134
- 'HTTP GET'
2262
+ "HTTP GET\n url: " + @h[:url_to_open]
2135
2263
  end
2136
2264
 
2137
2265
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-macrodroid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,8 +35,28 @@ cert_chain:
35
35
  NZ2kdBIUDnAM24e0/wXdVxg4HnsZbdymxyzMQ4P5pKYcpI6oisBxI37p/Xy+wAg3
36
36
  SBHno3GEuuD8ZWj24IMJpfbp
37
37
  -----END CERTIFICATE-----
38
- date: 2020-09-04 00:00:00.000000000 Z
38
+ date: 2020-09-05 00:00:00.000000000 Z
39
39
  dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: glw
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.2'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.2.2
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '0.2'
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 0.2.2
40
60
  - !ruby/object:Gem::Dependency
41
61
  name: uuid
42
62
  requirement: !ruby/object:Gem::Requirement
@@ -58,25 +78,25 @@ dependencies:
58
78
  - !ruby/object:Gem::Version
59
79
  version: 2.3.9
60
80
  - !ruby/object:Gem::Dependency
61
- name: glw
81
+ name: rowx
62
82
  requirement: !ruby/object:Gem::Requirement
63
83
  requirements:
64
- - - "~>"
65
- - !ruby/object:Gem::Version
66
- version: '0.2'
67
84
  - - ">="
68
85
  - !ruby/object:Gem::Version
69
- version: 0.2.2
86
+ version: 0.7.0
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.7'
70
90
  type: :runtime
71
91
  prerelease: false
72
92
  version_requirements: !ruby/object:Gem::Requirement
73
93
  requirements:
74
- - - "~>"
75
- - !ruby/object:Gem::Version
76
- version: '0.2'
77
94
  - - ">="
78
95
  - !ruby/object:Gem::Version
79
- version: 0.2.2
96
+ version: 0.7.0
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '0.7'
80
100
  - !ruby/object:Gem::Dependency
81
101
  name: geozone
82
102
  requirement: !ruby/object:Gem::Requirement
metadata.gz.sig CHANGED
Binary file