ruby-macrodroid 0.1.0 → 0.2.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: f5ebd24bcf9eaf00297ab7bc09c0a1d55f8f88b85c1299a69d2bb6443fa41583
4
- data.tar.gz: 973b4c08b6df73df6698af7f3c1a8ad87bb3e9188fe956aa61c2cabcd4757105
3
+ metadata.gz: 8caad514012d7a2d749101b29c035de0b00d87d91aaaf98a11f8e29d5d0660c5
4
+ data.tar.gz: 05e52e01b2aa1e9e77bf745bcb4f4c8533d9ab5c7798ed50f4d7081ebc4ccaca
5
5
  SHA512:
6
- metadata.gz: 6cdaa9145b35f8ee7f337a00405749336a4a11b5da01711480f1cebcdb0952b511002137fb478267a2a9bdb02ea6492d08893a58d8fc52f97be3c72a482e02ed
7
- data.tar.gz: 18e4a33b8356b721a5699b8c5725ee7d8ff4a365787d8c1caed4802fb9f12688e8954c61325ab65d802bc26786c367204c22cc259f2b8188fe0af221252255c0
6
+ metadata.gz: 8986f2053233c870ad76a1cf516a3a902197ee63ea2424fd19d60d64ecd331b5a6cf5efa33f54f0970d3ccbe9918a4018a79bf9c433f1363a8771f7b5d547cf2
7
+ data.tar.gz: e8007c3e2b65bf110a32563f7d88e4ec56b0289ee8d0b63a69142b570ed8e312c9721371679cb7d1c3c3597b4917a41f66356e14df99c39c89045a487a693828
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -4,6 +4,7 @@
4
4
 
5
5
  require 'pp'
6
6
  require 'json'
7
+ require 'uuid'
7
8
  require 'rxfhelper'
8
9
 
9
10
 
@@ -11,20 +12,51 @@ module Params
11
12
 
12
13
  refine Hash do
13
14
 
14
- # turns camelCase into snake_case
15
+ # turns keys from camelCase into snake_case
15
16
 
16
- def to_params()
17
+ def to_snake_case(h=self)
17
18
 
18
- self.inject({}) do |r, x|
19
+ h.inject({}) do |r, x|
19
20
 
20
21
  key, value = x
21
- r.merge key.sub(/^m_/,'').gsub(/[A-Z][a-z]/){|x| '_' +
22
+ puts 'value: ' + value.inspect
23
+
24
+ val = if value.is_a?(Hash) then
25
+ to_snake_case(value)
26
+ elsif value.is_a?(Array) and value.first.is_a? Hash
27
+ value.map {|row| to_snake_case(row)}
28
+ else
29
+ value
30
+ end
31
+
32
+ r.merge key.to_s.sub(/^m_/,'').gsub(/[A-Z][a-z]/){|x| '_' +
22
33
  x.downcase}.gsub(/[a-z][A-Z]/){|x| x[0] + '_' + x[1].downcase}\
23
- .downcase.to_sym => value
34
+ .downcase.to_sym => val
24
35
 
25
36
  end
26
37
  end
27
38
 
39
+ # turns keys from snake_case to CamelCase
40
+ def to_camel_case(h=self)
41
+
42
+ h.inject({}) do |r,x|
43
+
44
+ key, value = x
45
+
46
+ val = if value.is_a?(Hash) then
47
+ to_camel_case(value)
48
+ elsif value.is_a?(Array) and value.first.is_a? Hash
49
+ value.map {|row| to_camel_case(row)}
50
+ else
51
+ value
52
+ end
53
+
54
+ r.merge({key.to_s.gsub(/(?<!^m)_[a-z]/){|x| x[-1].upcase} => val})
55
+ end
56
+
57
+ end
58
+
59
+
28
60
  end
29
61
 
30
62
  end
@@ -40,16 +72,43 @@ class Macro
40
72
  @debug = debug
41
73
  lv=[], triggers=[], actions=[]
42
74
  @local_variables, @triggers, @actions = lv, triggers, actions
75
+
76
+ @triggers, @actions = [], []
77
+ @h = {}
78
+
79
+ end
80
+
81
+ def add(obj)
82
+
83
+ if obj.kind_of? Trigger then
84
+
85
+ puts 'trigger found' if @debug
86
+ @triggers << obj
87
+
88
+ elsif obj.kind_of? Action
89
+
90
+ puts 'action found' if @debug
91
+ @actions << obj
92
+
93
+ elsif obj.kind_of? Constraint
94
+
95
+ puts 'constraint found' if @debug
96
+ @constraints << obj
97
+
98
+ end
99
+
43
100
  end
44
101
 
45
102
  def to_h()
46
103
 
47
104
  h = {
48
- 'localVariables' => @local_variables,
49
- 'm_triggerList' => @triggers.map(&:to_h),
50
- 'm_actionList' => @actions.map(&:to_h),
51
- 'm_constraintList' =>[]
52
- }
105
+ local_variables: @local_variables,
106
+ m_trigger_list: @triggers.map(&:to_h),
107
+ m_action_list: @actions.map(&:to_h),
108
+ m_constraint_list: []
109
+ }
110
+
111
+ puts 'h: ' + h.inspect if @debug
53
112
 
54
113
  @h.merge(h)
55
114
  end
@@ -57,24 +116,24 @@ class Macro
57
116
  def import_h(h)
58
117
 
59
118
  # fetch the local variables
60
- @local_variables = h['localVariables']
119
+ @local_variables = h['local_variables']
61
120
 
62
121
  # fetch the triggers
63
- @triggers = h['m_triggerList'].map do |trigger|
122
+ @triggers = h[:trigger_list].map do |trigger|
64
123
 
65
- object(trigger.to_params)
124
+ object(trigger.to_snake_case)
66
125
 
67
126
  end
68
127
 
69
- @actions = h['m_actionList'].map do |action|
70
- object(action.to_params)
128
+ @actions = h[:action_list].map do |action|
129
+ object(action.to_snake_case)
71
130
  end
72
131
 
73
132
  # fetch the constraints (not yet implemented)
74
133
 
75
134
  @h = h
76
135
 
77
- %w(localVariables m_triggerList m_actionList).each do |x|
136
+ %i(local_variables m_trigger_list m_action_list).each do |x|
78
137
  @h[x] = []
79
138
  end
80
139
 
@@ -96,14 +155,52 @@ end
96
155
 
97
156
  class MacroDroid
98
157
  using ColouredText
158
+ using Params
99
159
 
100
160
  attr_reader :macros
101
161
 
102
- def initialize(obj, debug: false)
162
+ def initialize(obj=nil, debug: false)
103
163
 
104
- @debug = debug
105
- s, _ = RXFHelper.read(obj)
106
- import_json(s) if s[0] == '{'
164
+ @debug = debug
165
+
166
+ if obj then
167
+
168
+ s, _ = RXFHelper.read(obj)
169
+ import_json(s) if s[0] == '{'
170
+
171
+ else
172
+
173
+ @h = {
174
+ cell_tower_groups: [],
175
+ cell_towers_ignore: [],
176
+ drawer_configuration: {
177
+ drawer_items: [],
178
+ background_color: -1,
179
+ header_color: 12692882,
180
+ left_side: false,
181
+ swipe_area_color: -7829368,
182
+ swipe_area_height: 20,
183
+ swipe_area_offset: 40,
184
+ swipe_area_opacity: 80,
185
+ swipe_area_width: 14,
186
+ visible_swipe_area_width: 0
187
+ },
188
+ variables: [],
189
+ user_icons: [],
190
+ geofence_data: {
191
+ geofence_map: {}
192
+ },
193
+ macro_list: []
194
+
195
+ }
196
+
197
+ @macros = []
198
+
199
+ end
200
+ end
201
+
202
+ def add(macro)
203
+ @macros << macro
107
204
  end
108
205
 
109
206
  def export_json()
@@ -116,10 +213,10 @@ class MacroDroid
116
213
 
117
214
  def import_json(s)
118
215
 
119
- @h = JSON.parse s
216
+ @h = JSON.parse(s, symbolize_names: true).to_snake_case
120
217
  puts ('@h: ' + @h.pretty_inspect).debug if @debug
121
218
 
122
- @macros = @h["macroList"].map do |macro|
219
+ @macros = @h[:macro_list].map do |macro|
123
220
 
124
221
  puts ('macro: ' + macro.pretty_inspect).debug if @debug
125
222
  m = Macro.new(debug: @debug)
@@ -128,12 +225,12 @@ class MacroDroid
128
225
 
129
226
  end
130
227
 
131
- @h['macroList'] = []
228
+ @h[:macro_list] = []
132
229
  end
133
230
 
134
231
  def to_h()
135
232
 
136
- @h.merge('macroList' => @macros.map(&:to_h))
233
+ @h.merge(macro_list: @macros.map(&:to_h)).to_camel_case
137
234
 
138
235
  end
139
236
 
@@ -154,7 +251,7 @@ class MacroObject
154
251
 
155
252
  h = @h
156
253
 
157
- h.inject({}) do |r,x|
254
+ h2 = h.inject({}) do |r,x|
158
255
  puts 'x: ' + x.inspect if @debug
159
256
  key, value = x
160
257
  puts 'key: ' + key.inspect if @debug
@@ -163,9 +260,17 @@ class MacroObject
163
260
  new_key = 'm_SIGUID' if new_key == 'm_siguid'
164
261
  r.merge(new_key => value)
165
262
  end
263
+
264
+ h2.merge('m_classType' => self.class.to_s)
166
265
 
167
266
  end
168
267
 
268
+ protected
269
+
270
+ def uuid()
271
+ UUID.new.generate
272
+ end
273
+
169
274
  end
170
275
 
171
276
  class Trigger < MacroObject
@@ -355,11 +460,25 @@ class CalendarTrigger < Trigger
355
460
  end
356
461
 
357
462
  end
463
+
464
+
358
465
 
466
+
359
467
  class TimerTrigger < Trigger
360
468
 
361
469
  def initialize(h={})
362
- super({}.merge h)
470
+
471
+ options = {
472
+ alarm_id: uuid(),
473
+ days_of_week: [false, true, false, false, false, false, false],
474
+ hour: 0,
475
+ minute: 0,
476
+ use_alarm: false
477
+ }
478
+
479
+ super(options.merge h)
480
+
481
+
363
482
  end
364
483
 
365
484
  end
@@ -978,7 +1097,19 @@ end
978
1097
  class ToastAction < Action
979
1098
 
980
1099
  def initialize(h={})
981
- super({}.merge h)
1100
+
1101
+ options = {
1102
+ message_text: 'Popup message for you!',
1103
+ image_resource_name: 'launcher_no_border',
1104
+ image_package_name: 'com.arlosoft.macrodroid',
1105
+ image_name: 'launcher_no_border',
1106
+ duration: 0,
1107
+ display_icon: true,
1108
+ background_color: -12434878,
1109
+ position: 0,
1110
+ }
1111
+
1112
+ super(options.merge h)
982
1113
  end
983
1114
 
984
1115
  end
@@ -1118,3 +1249,11 @@ class SetVolumeAction < Action
1118
1249
  end
1119
1250
 
1120
1251
  end
1252
+
1253
+ class Constraint < MacroObject
1254
+
1255
+ def initialize(h={})
1256
+ super(h)
1257
+ end
1258
+
1259
+ 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.1.0
4
+ version: 0.2.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: 2019-10-27 00:00:00.000000000 Z
38
+ date: 2020-08-11 00:00:00.000000000 Z
39
39
  dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: uuid
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.3'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 2.3.9
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '2.3'
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 2.3.9
40
60
  - !ruby/object:Gem::Dependency
41
61
  name: rxfhelper
42
62
  requirement: !ruby/object:Gem::Requirement
metadata.gz.sig CHANGED
Binary file