ruby-macrodroid 0.5.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b105d3fc8c1fe8e43ad4ea6b8b9018a26e376949c94c1623a11540ba8d5850c
4
- data.tar.gz: 22b28e9b200b82fe6c048a0781845c032502c9b24e8ff566e455b8f2193d97f1
3
+ metadata.gz: dfb49da8914ecdd5cc21ca0223801fa0d432890a3df4c352ab7c3914c1bd63fe
4
+ data.tar.gz: 9f402e6d1c9dbd17f5cb7d3741bcc7c487461a5438adf3cba81a71df9feb50f9
5
5
  SHA512:
6
- metadata.gz: c09be84265a4961e278e378c346a6152924848f3cf2a347aa3c52c2b87dab6711092c07be1dbb3820576e5779e73818c96b34958c1e2044edf29b24a973c5e35
7
- data.tar.gz: 333fc854bc4ce0ff61b1921a971835a1f4d1f75d65ae8608de0990c710f5060ecc7bfedb0468baba7f575ca73b3df96e9036d93a64339ba0e08a73d9c9612ecc
6
+ metadata.gz: 0753ef46f3cdbc1e5a8fb6539747e662a2e537089aa83e32ecf47c89334b1acb71ced47f77230e1fcae00314d8dd70e8e4d37380c27f25ebb0ccafe837121daa
7
+ data.tar.gz: e78f3fc06bcdbd1685de98d5473b2564d904a722053527505002f5a5bbfa43e51e99832d2a9a29eb5a12d3e9bab94d91429f78628625e74acbae6876b909f43a
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -4,6 +4,8 @@
4
4
 
5
5
  require 'uuid'
6
6
  require 'yaml'
7
+ require 'glw'
8
+ require 'geozone'
7
9
  require 'rxfhelper'
8
10
  require 'chronic_cron'
9
11
 
@@ -60,7 +62,11 @@ class TriggersNlp
60
62
  get /^failed_login?$/i do
61
63
  [FailedLoginTrigger, {}]
62
64
  end
63
-
65
+
66
+ get /^Geofence (Entry|Exit) \(([^\)]+)/i do |direction, name|
67
+ enter_area = direction.downcase.to_sym == :entry
68
+ [GeofenceTrigger, {name: name, enter_area: enter_area}]
69
+ end
64
70
 
65
71
  end
66
72
 
@@ -81,14 +87,17 @@ class ActionsNlp
81
87
 
82
88
  def actions(params)
83
89
 
90
+ # e.g. message popup: hello world!
84
91
  get /^message popup: (.*)/i do |msg|
85
92
  [ToastAction, {msg: msg}]
86
93
  end
87
94
 
95
+ # e.g. Popup Message 'hello world!'
88
96
  get /^Popup[ _]Message ['"]([^'"]+)/i do |msg|
89
97
  [ToastAction, {msg: msg}]
90
98
  end
91
99
 
100
+ # e.g. say current time
92
101
  get /^say current[ _]time/i do
93
102
  [SayTimeAction, {}]
94
103
  end
@@ -105,6 +114,46 @@ class ActionsNlp
105
114
  get /^take_picture/i do
106
115
  [TakePictureAction, {}]
107
116
  end
117
+
118
+ # e.g. Display Notification: Hi there: This is the body of the message
119
+ get /^Display Notification: ([^:]+): [^$]+$/i do |subject, text|
120
+ [NotificationAction, {subject: subject, text: text}]
121
+ end
122
+
123
+
124
+ # e.g. Enable Wifi
125
+ get /^(Enable|Disable) Wifi$/i do |raw_state|
126
+
127
+ state = raw_state.downcase.to_sym == :enable ? 0 : 1
128
+ [SetWifiAction, {state: state}]
129
+
130
+ end
131
+
132
+ # e.g. Play: Altair
133
+ get /^Play: (.*)$/i do |name|
134
+
135
+ [PlaySoundAction, {file_path: name}]
136
+
137
+ end
138
+
139
+ # e.g. Launch Settings
140
+ get /^Launch (.*)$/i do |application|
141
+
142
+ h = {
143
+ application_name: application,
144
+ package_to_launch: 'com.android.' + application.downcase
145
+ }
146
+ [LaunchActivityAction, h]
147
+
148
+ end
149
+
150
+ # e.g. HTTP GET http://someurl.com/something
151
+ get /^HTTP GET ([^$]+)$/i do |url|
152
+
153
+ [OpenWebPageAction, url_to_open: url]
154
+
155
+ end
156
+
108
157
 
109
158
  end
110
159
 
@@ -195,9 +244,9 @@ class Macro
195
244
  attr_reader :local_variables, :triggers, :actions, :constraints, :guid
196
245
  attr_accessor :title, :description
197
246
 
198
- def initialize(name=nil, debug: false)
247
+ def initialize(name=nil, geofence: geofence, debug: false)
199
248
 
200
- @title, @debug = name, debug
249
+ @title, @geofence, @debug = name, geofence, debug
201
250
 
202
251
  puts 'inside Macro#initialize' if @debug
203
252
 
@@ -405,14 +454,23 @@ class Macro
405
454
 
406
455
  end
407
456
 
457
+ # invokes the actions
458
+ #
408
459
  def run()
409
460
  @actions.map(&:invoke)
410
461
  end
462
+
463
+ # prepares the environment in order for triggers to test fire successfully
464
+ # Used for testing
465
+ #
466
+ def set_env()
467
+ @triggers.each(&:set_env)
468
+ end
411
469
 
412
470
  def to_pc()
413
471
 
414
- heading = '# ' + @title + "\n"
415
- heading += '# ' + @description if @description
472
+ heading = '# ' + @title
473
+ heading += '\n# ' + @description if @description
416
474
  condition = @triggers.first.to_pc
417
475
  actions = @actions.map(&:to_pc).join("\n")
418
476
 
@@ -426,14 +484,34 @@ EOF
426
484
  end
427
485
 
428
486
  def to_s()
487
+
429
488
  a = [
430
489
  'm: ' + @title,
431
490
  @triggers.map {|x| "t: %s" % x}.join("\n"),
432
491
  @actions.map {|x| "a: %s" % x}.join("\n"),
433
492
  @constraints.map {|x| "a: %s" % x}.join("\n")
434
493
  ]
435
- a.insert(1, 'd: ' + @description) if @description
494
+
495
+ if @description and @description.length >= 1 then
496
+ a.insert(1, 'd: ' + @description)
497
+ end
498
+
436
499
  a.join("\n")
500
+
501
+ end
502
+
503
+ def to_summary()
504
+
505
+ a = [
506
+ 'm: ' + @title,
507
+ 't: ' + @triggers.map(&:to_s).join(", "),
508
+ 'a: ' + @actions.map(&:to_s).join(", "),
509
+ ]
510
+
511
+ a << 'c: ' + @constraints.map(&:to_s).join(", ") if @constraints.any?
512
+
513
+ a.join("\n") + "\n"
514
+
437
515
  end
438
516
 
439
517
  private
@@ -446,7 +524,15 @@ EOF
446
524
 
447
525
  puts ('inside object h:' + h.inspect).debug if @debug
448
526
  klass = Object.const_get h[:class_type]
449
- klass.new h
527
+ puts klass.inspect.highlight if $debug
528
+
529
+ if klass == GeofenceTrigger then
530
+ puts 'GeofenceTrigger found'.highlight if $debug
531
+ klass.new(@geofence, h)
532
+ else
533
+ klass.new h
534
+ end
535
+
450
536
  end
451
537
 
452
538
  end
@@ -459,7 +545,7 @@ class MacroDroid
459
545
  using ColouredText
460
546
  using Params
461
547
 
462
- attr_reader :macros
548
+ attr_reader :macros, :geofence
463
549
 
464
550
  def initialize(obj=nil, debug: false)
465
551
 
@@ -481,8 +567,11 @@ class MacroDroid
481
567
  @h = build_h
482
568
 
483
569
  else
570
+
571
+ puts 's: ' + s.inspect if @debug
484
572
 
485
- xml = if s =~ /^m: / then
573
+ xml = if s =~ /m:\s/ then
574
+ puts 'before text_to_xml' if @debug
486
575
  text_to_xml(s)
487
576
  elsif s =~ /^# /
488
577
  pc_to_xml(s)
@@ -545,6 +634,29 @@ class MacroDroid
545
634
 
546
635
  alias to_json export_json
547
636
 
637
+
638
+ def to_h()
639
+
640
+ @h.merge(macro_list: @macros.map(&:to_h)).to_camel_case
641
+
642
+ end
643
+
644
+ # returns pseudocode
645
+ #
646
+ def to_pc()
647
+ @macros.map(&:to_pc).join("\n\n")
648
+ end
649
+
650
+ def to_s()
651
+ @macros.map(&:to_s).join("\n")
652
+ end
653
+
654
+ def to_summary()
655
+ @macros.map(&:to_summary).join("\n")
656
+ end
657
+
658
+ private
659
+
548
660
  def import_json(s)
549
661
 
550
662
  h = JSON.parse(s, symbolize_names: true)
@@ -552,11 +664,23 @@ class MacroDroid
552
664
 
553
665
  @h = h.to_snake_case
554
666
  puts ('@h: ' + @h.inspect).debug if @debug
555
-
667
+
668
+
669
+ # fetch the geofence data
670
+ if @h[:geofence_data] then
671
+
672
+ @geofence = @h[:geofence_data][:geofence_map].map do |id, properties|
673
+ [id, GeofenceMap.new(properties)]
674
+ end.to_h
675
+
676
+ end
677
+
556
678
  @macros = @h[:macro_list].map do |macro|
557
679
 
558
680
  puts ('macro: ' + macro.inspect).debug if @debug
559
- m = Macro.new(debug: @debug)
681
+ puts '@geofence: ' + @geofence.inspect if @debug
682
+
683
+ m = Macro.new(geofence: @geofence, debug: @debug )
560
684
  m.import_h(macro)
561
685
  m
562
686
 
@@ -612,7 +736,8 @@ class MacroDroid
612
736
 
613
737
  def text_to_xml(s)
614
738
 
615
- a = s.split(/.*(?=^m:)/); a.shift
739
+ a = s.split(/.*(?=^m:)/)
740
+ puts 'a : ' + a.inspect if @debug
616
741
  a.map!(&:chomp)
617
742
 
618
743
  macros = a.map do |x|
@@ -636,23 +761,18 @@ class MacroDroid
636
761
  doc.root.xml pretty: true
637
762
 
638
763
  end
764
+
639
765
 
640
- def to_h()
641
-
642
- @h.merge(macro_list: @macros.map(&:to_h)).to_camel_case
766
+ end
643
767
 
644
- end
768
+ class GeofenceMap
645
769
 
646
- # returns pseudocode
647
- #
648
- def to_pc()
649
- @macros.map(&:to_pc).join("\n\n")
650
- end
651
-
652
- def to_s()
653
- @macros.map(&:to_s).join("\n")
770
+ attr_accessor :name, :longitude, :latitude, :radius, :id
771
+
772
+ def initialize(h)
773
+ @id, @latitude, @longitude, @name, @radius = h.values
654
774
  end
655
-
775
+
656
776
  end
657
777
 
658
778
  class MacroObject
@@ -663,6 +783,8 @@ class MacroObject
663
783
 
664
784
  def initialize(h={})
665
785
 
786
+ $env ||= {}
787
+
666
788
  @h = {constraint_list: [], is_or_condition: false,
667
789
  is_disabled: false}.merge(h)
668
790
  @list = []
@@ -691,6 +813,10 @@ class MacroObject
691
813
  h2.merge('m_classType' => self.class.to_s)
692
814
 
693
815
  end
816
+
817
+ def to_s()
818
+ "#<%s %s>" % [self.class, @h.inspect]
819
+ end
694
820
 
695
821
  protected
696
822
 
@@ -1205,29 +1331,22 @@ class TimerTrigger < Trigger
1205
1331
  use_alarm: false
1206
1332
  }
1207
1333
 
1208
- super(options.merge filter(options,h))
1334
+ super(options.merge filter(options, h))
1209
1335
 
1210
1336
  end
1211
1337
 
1212
1338
  def match?(detail={time: $env[:time]}, model=nil)
1213
-
1214
- a = @h[:days_of_week]
1215
- a.unshift a.pop
1216
-
1217
- dow = a.map.with_index {|x, i| x ? i : nil }.compact.join(',')
1218
-
1219
- s = "%s %s * * %s" % [@h[:minute], @h[:hour], dow]
1220
-
1221
- if $debug then
1222
- puts 's: ' + s.inspect
1223
- puts 'detail: ' + detail.inspect
1224
- puts '@h: ' + @h.inspect
1225
- end
1226
1339
 
1227
- ChronicCron.new(s, detail[:time]).to_time == detail[:time]
1340
+ time() == detail[:time]
1228
1341
 
1229
1342
  end
1230
1343
 
1344
+ # sets the environmental conditions for this trigger to fire
1345
+ #
1346
+ def set_env()
1347
+ $env[:time] = time()
1348
+ end
1349
+
1231
1350
  def to_pc()
1232
1351
  "time.is? '%s'" % self.to_s.gsub(',', ' or')
1233
1352
  end
@@ -1243,6 +1362,20 @@ class TimerTrigger < Trigger
1243
1362
 
1244
1363
  "at %s on %s" % [time, days.join(', ')]
1245
1364
  end
1365
+
1366
+ private
1367
+
1368
+ def time()
1369
+
1370
+ a = @h[:days_of_week].clone
1371
+ a.unshift a.pop
1372
+
1373
+ dow = a.map.with_index {|x, i| x ? i : nil }.compact.join(',')
1374
+ s = "%s %s * * %s" % [@h[:minute], @h[:hour], dow]
1375
+ recent_time = ($env && $env[:time]) ? $env[:time] : Time.now
1376
+ ChronicCron.new(s, recent_time).to_time
1377
+
1378
+ end
1246
1379
 
1247
1380
  end
1248
1381
 
@@ -1622,8 +1755,15 @@ end
1622
1755
  #
1623
1756
  class GeofenceTrigger < Trigger
1624
1757
 
1625
- def initialize(h={})
1758
+ def initialize(geofence, h={})
1626
1759
 
1760
+ if h[:name] then
1761
+
1762
+ found = geofence.find {|x| x.name == h[:name]}
1763
+ h[:geofence_id] = found.id
1764
+
1765
+ end
1766
+
1627
1767
  options = {
1628
1768
  update_rate_text: '5 Minutes',
1629
1769
  geofence_id: '',
@@ -1632,9 +1772,18 @@ class GeofenceTrigger < Trigger
1632
1772
  enter_area: true
1633
1773
  }
1634
1774
 
1635
- super(options.merge h)
1775
+ super(options.merge filter(options, h))
1776
+ @geofence = geofence
1636
1777
 
1637
1778
  end
1779
+
1780
+ def to_s()
1781
+
1782
+ puts ' @geofence: ' + @geofence.inspect if $debug
1783
+ direction = @h[:enter_area] ? 'Entry' : 'Exit'
1784
+ "Geofence %s (%s)" % [direction, @geofence[@h[:geofence_id].to_sym].name]
1785
+
1786
+ end
1638
1787
 
1639
1788
  end
1640
1789
 
@@ -1939,6 +2088,10 @@ class LaunchActivityAction < ApplicationAction
1939
2088
  super(options.merge h)
1940
2089
 
1941
2090
  end
2091
+
2092
+ def to_s()
2093
+ 'Launch ' + @h[:application_name]
2094
+ end
1942
2095
 
1943
2096
  end
1944
2097
 
@@ -1976,6 +2129,10 @@ class OpenWebPageAction < ApplicationAction
1976
2129
  super(options.merge h)
1977
2130
 
1978
2131
  end
2132
+
2133
+ def to_s()
2134
+ 'HTTP GET'
2135
+ end
1979
2136
 
1980
2137
  end
1981
2138
 
@@ -2060,6 +2217,11 @@ class SetWifiAction < ConnectivityAction
2060
2217
  super(options.merge h)
2061
2218
 
2062
2219
  end
2220
+
2221
+ def to_s()
2222
+ action = @h[:state] == 0 ? 'Enable' : 'Disable'
2223
+ action + ' Wifi'
2224
+ end
2063
2225
 
2064
2226
  end
2065
2227
 
@@ -2720,6 +2882,10 @@ class PlaySoundAction < MediaAction
2720
2882
  super(options.merge h)
2721
2883
 
2722
2884
  end
2885
+
2886
+ def to_s()
2887
+ 'Play: ' + @h[:file_path]
2888
+ end
2723
2889
 
2724
2890
  end
2725
2891
 
@@ -2924,6 +3090,9 @@ end
2924
3090
  class NotificationAction < NotificationsAction
2925
3091
 
2926
3092
  def initialize(h={})
3093
+
3094
+ h[:notification_subject] = h[:subject] if h[:subject]
3095
+ h[:notification_text] = h[:text] if h[:text]
2927
3096
 
2928
3097
  options = {
2929
3098
  ringtone_name: 'Default',
@@ -2939,9 +3108,13 @@ class NotificationAction < NotificationsAction
2939
3108
  run_macro_when_pressed: false
2940
3109
  }
2941
3110
 
2942
- super(options.merge h)
3111
+ super(options.merge filter(options, h))
2943
3112
 
2944
3113
  end
3114
+
3115
+ def to_s()
3116
+ 'Display Notification: ' + "%s: %s" % [@h[:notification_subject], @h[:notification_text]]
3117
+ end
2945
3118
 
2946
3119
  end
2947
3120
 
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.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  NZ2kdBIUDnAM24e0/wXdVxg4HnsZbdymxyzMQ4P5pKYcpI6oisBxI37p/Xy+wAg3
36
36
  SBHno3GEuuD8ZWj24IMJpfbp
37
37
  -----END CERTIFICATE-----
38
- date: 2020-09-03 00:00:00.000000000 Z
38
+ date: 2020-09-04 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: uuid
@@ -57,6 +57,46 @@ dependencies:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
59
  version: 2.3.9
60
+ - !ruby/object:Gem::Dependency
61
+ name: glw
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '0.2'
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 0.2.2
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '0.2'
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 0.2.2
80
+ - !ruby/object:Gem::Dependency
81
+ name: geozone
82
+ requirement: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: 0.1.0
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.1'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 0.1.0
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '0.1'
60
100
  - !ruby/object:Gem::Dependency
61
101
  name: rxfhelper
62
102
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +106,7 @@ dependencies:
66
106
  version: '1.0'
67
107
  - - ">="
68
108
  - !ruby/object:Gem::Version
69
- version: 1.0.4
109
+ version: 1.0.5
70
110
  type: :runtime
71
111
  prerelease: false
72
112
  version_requirements: !ruby/object:Gem::Requirement
@@ -76,7 +116,7 @@ dependencies:
76
116
  version: '1.0'
77
117
  - - ">="
78
118
  - !ruby/object:Gem::Version
79
- version: 1.0.4
119
+ version: 1.0.5
80
120
  - !ruby/object:Gem::Dependency
81
121
  name: chronic_cron
82
122
  requirement: !ruby/object:Gem::Requirement
metadata.gz.sig CHANGED
Binary file