mushy 0.15.3 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/hey.mushy +29 -0
  3. data/lib/mushy/builder/api.rb +15 -3
  4. data/lib/mushy/builder/documentation.rb +37 -0
  5. data/lib/mushy/builder/index.rb +88 -15
  6. data/lib/mushy/flux.rb +5 -1
  7. data/lib/mushy/fluxs/bash.rb +24 -0
  8. data/lib/mushy/fluxs/browser.rb +120 -0
  9. data/lib/mushy/fluxs/build_csv.rb +23 -0
  10. data/lib/mushy/fluxs/cli.rb +12 -0
  11. data/lib/mushy/fluxs/collection.rb +3 -1
  12. data/lib/mushy/fluxs/document.rb +16 -0
  13. data/lib/mushy/fluxs/environment.rb +13 -0
  14. data/lib/mushy/fluxs/file_watch.rb +30 -1
  15. data/lib/mushy/fluxs/filter.rb +28 -0
  16. data/lib/mushy/fluxs/format.rb +42 -1
  17. data/lib/mushy/fluxs/git_log.rb +2 -0
  18. data/lib/mushy/fluxs/global_variables.rb +17 -1
  19. data/lib/mushy/fluxs/interval.rb +2 -0
  20. data/lib/mushy/fluxs/ls.rb +112 -0
  21. data/lib/mushy/fluxs/parse_html.rb +37 -1
  22. data/lib/mushy/fluxs/pdf.rb +72 -1
  23. data/lib/mushy/fluxs/pwd.rb +42 -1
  24. data/lib/mushy/fluxs/read_csv.rb +27 -0
  25. data/lib/mushy/fluxs/read_file.rb +24 -9
  26. data/lib/mushy/fluxs/read_json.rb +21 -7
  27. data/lib/mushy/fluxs/screenshot.rb +72 -2
  28. data/lib/mushy/fluxs/sense_hat_environmental_sensors.rb +2 -0
  29. data/lib/mushy/fluxs/sense_hat_led_matrix.rb +2 -0
  30. data/lib/mushy/fluxs/simple_python_program.rb +1 -0
  31. data/lib/mushy/fluxs/smtp.rb +2 -1
  32. data/lib/mushy/fluxs/stdout.rb +2 -0
  33. data/lib/mushy/fluxs/times.rb +9 -0
  34. data/lib/mushy/fluxs/twilio_message.rb +113 -0
  35. data/lib/mushy/fluxs/write_file.rb +48 -0
  36. data/lib/mushy/fluxs/write_json.rb +16 -0
  37. data/mushy.gemspec +1 -1
  38. metadata +8 -7
  39. data/lib/mushy/fluxs/print.rb +0 -26
@@ -5,7 +5,9 @@ module Mushy
5
5
  def self.details
6
6
  {
7
7
  name: 'Document',
8
+ title: 'Make a multi-line liquid value',
8
9
  description: 'Create a multi-line document.',
10
+ fluxGroup: { name: 'Flows' },
9
11
  config: {
10
12
  document: {
11
13
  description: 'The multi-line document you wish to create.',
@@ -13,6 +15,20 @@ module Mushy
13
15
  value: '',
14
16
  },
15
17
  },
18
+ examples: {
19
+ "Example" => {
20
+ description: 'Using this Flux to build a document',
21
+ input: {
22
+ people: [ { name: "John" }, { name: "Jane" } ]
23
+ },
24
+ config: {
25
+ document: '{% for person in people %} {{ person.name }} {% endfor %}'
26
+ },
27
+ result: {
28
+ document: ' John Jane ',
29
+ }
30
+ },
31
+ }
16
32
  }
17
33
  end
18
34
 
@@ -5,7 +5,9 @@ module Mushy
5
5
  def self.details
6
6
  {
7
7
  name: 'Environment',
8
+ title: 'Pull environment variables',
8
9
  description: 'Pull environment variables.',
10
+ fluxGroup: { name: 'Environment' },
9
11
  config: {
10
12
  variables: {
11
13
  description: 'Map the environment variables to a new event.',
@@ -13,6 +15,17 @@ module Mushy
13
15
  value: {},
14
16
  },
15
17
  },
18
+ examples: {
19
+ "Example" => {
20
+ description: 'Get environmental variables.',
21
+ config: {
22
+ variables: { text_domain: 'TEXTDOMAIN' }
23
+ },
24
+ result: {
25
+ text_domain: 'Linux-PAM',
26
+ }
27
+ },
28
+ }
16
29
  }
17
30
  end
18
31
 
@@ -7,14 +7,43 @@ module Mushy
7
7
  def self.details
8
8
  {
9
9
  name: 'FileWatch',
10
+ title: 'Start a flow when files change',
11
+ fluxGroup: { name: 'Starters', position: 0 },
10
12
  description: 'Watch for file changes.',
11
13
  config: {
12
14
  directory: {
13
- description: 'The directory to watch.',
15
+ description: 'The directory to watch, defaults to the current directory.',
14
16
  type: 'text',
17
+ shrink: true,
15
18
  value: '',
16
19
  },
17
20
  },
21
+ examples: {
22
+ "Files Added" => {
23
+ description: 'When a file is added, this type of result will be returned.',
24
+ result: {
25
+ modified: [],
26
+ added: ["/home/pi/Desktop/mushy/bin/hey.txt"],
27
+ removed:[]
28
+ }
29
+ },
30
+ "Files Removed" => {
31
+ description: 'When a file is deleted, this type of result will be returned.',
32
+ result: {
33
+ modified: [],
34
+ added: [],
35
+ removed:["/home/pi/Desktop/mushy/mushy-0.15.3.gem"]
36
+ }
37
+ },
38
+ "Files Modified" => {
39
+ description: 'When a file is modified, this type of result will be returned.',
40
+ result: {
41
+ modified: ["/home/pi/Desktop/mushy/lib/mushy/fluxs/environment.rb"],
42
+ added: [],
43
+ removed:[]
44
+ }
45
+ },
46
+ }
18
47
  }
19
48
  end
20
49
 
@@ -5,7 +5,9 @@ module Mushy
5
5
  def self.details
6
6
  {
7
7
  name: 'Filter',
8
+ title: 'Filter events',
8
9
  description: 'Filters events based on criteria.',
10
+ fluxGroup: { name: 'Flows' },
9
11
  config: {
10
12
  equal: {
11
13
  description: 'Provide key/value pairs that must match in the event.',
@@ -36,6 +38,32 @@ module Mushy
36
38
  value: {},
37
39
  },
38
40
  },
41
+ examples: {
42
+ "Match On A Value" => {
43
+ description: 'The input is returned if it matches on a value.',
44
+ input: {
45
+ name: "John",
46
+ },
47
+ config: {
48
+ matches: { name: "John" }
49
+ },
50
+ result: {
51
+ name: "John",
52
+ }
53
+ },
54
+ "Contains A Value" => {
55
+ description: 'The input is returned if it contains a value.',
56
+ input: {
57
+ name: "John",
58
+ },
59
+ config: {
60
+ contains: { name: "H" }
61
+ },
62
+ result: {
63
+ name: "John",
64
+ }
65
+ },
66
+ }
39
67
  }
40
68
  end
41
69
 
@@ -5,8 +5,49 @@ module Mushy
5
5
  def self.details
6
6
  {
7
7
  name: 'Format',
8
- description: 'Return the event passed to it. This opens the opportunity to further alter results.',
8
+ title: 'Alter the format of an event',
9
+ description: 'Return the event passed to it. This opens the opportunity to use the common fluxing to alter the event.',
10
+ fluxGroup: { name: 'Flows' },
9
11
  config: {},
12
+ examples: {
13
+ "Simplest Example" => {
14
+ description: 'It only returns what is passed to it.',
15
+ input: {
16
+ hello: 'world',
17
+ },
18
+ config: {
19
+ },
20
+ result: {
21
+ hello: 'world',
22
+ }
23
+ },
24
+ "Changing The Event" => {
25
+ description: 'The common fluxing can still be used to alter the event.',
26
+ input: {
27
+ things: [
28
+ { name: "Elephant", type: "Mammal" },
29
+ { name: "Alligator", type: "Reptile" },
30
+ { name: "Giraffe", type: "Mammal" }
31
+ ]
32
+ },
33
+ config: { outgoing_split:"things",group:"type|animal_type" },
34
+ result: [
35
+ {
36
+ animal_type: [
37
+ {
38
+ name: "Elephant",
39
+ type: "Mammal"
40
+ },
41
+ {
42
+ name: "Giraffe",
43
+ type: "Mammal"
44
+ }
45
+ ]
46
+ },
47
+ { animal_type:[ { name:"Alligator",type:"Reptile" } ] }
48
+ ]
49
+ },
50
+ }
10
51
  }
11
52
  end
12
53
 
@@ -5,7 +5,9 @@ module Mushy
5
5
  def self.details
6
6
  {
7
7
  name: 'GitLog',
8
+ title: 'Get git logs',
8
9
  description: 'Return git logs.',
10
+ fluxGroup: { name: 'Git' },
9
11
  config: {
10
12
  directory: {
11
13
  description: 'The working directory in which the command will be run.',
@@ -7,7 +7,9 @@ module Mushy
7
7
  def self.details
8
8
  {
9
9
  name: 'GlobalVariables',
10
- description: 'Add global variables.',
10
+ title: 'Set global variables',
11
+ fluxGroup: { name: 'Flows' },
12
+ description: 'Add global variables to use in any future flux. Returns what was passed to it.',
11
13
  config: {
12
14
  values: {
13
15
  description: 'Provide key/value pairs that will be set as global variables.',
@@ -16,6 +18,20 @@ module Mushy
16
18
  value: {},
17
19
  },
18
20
  },
21
+ examples: {
22
+ "Setting Config Variables" => {
23
+ description: 'Set a variable to use in any flux. Here, I can use {{api_key}} anywhere.',
24
+ input: {
25
+ hey: 'you'
26
+ },
27
+ config: {
28
+ values: { api_key: 'my api key' }
29
+ },
30
+ result: {
31
+ hey: 'you',
32
+ }
33
+ },
34
+ }
19
35
  }
20
36
  end
21
37
 
@@ -17,6 +17,8 @@ module Mushy
17
17
  def self.details
18
18
  {
19
19
  name: 'Interval',
20
+ title: 'Start a flow on a regular interval',
21
+ fluxGroup: { name: 'Starters', position: 0 },
20
22
  description: 'Fire an event every X minutes.',
21
23
  config: {},
22
24
  }.tap do |c|
@@ -5,7 +5,9 @@ module Mushy
5
5
  def self.details
6
6
  {
7
7
  name: 'Ls',
8
+ title: 'List Files',
8
9
  description: 'Run the "ls" command.',
10
+ fluxGroup: { name: 'Files' },
9
11
  config: Mushy::Bash.details[:config].tap { |c| c.delete :command },
10
12
  }.tap do |c|
11
13
  c[:config][:recursive] = {
@@ -20,6 +22,114 @@ module Mushy
20
22
  shrink: true,
21
23
  value: '',
22
24
  }
25
+ end.tap do |c|
26
+ c[:examples] = {
27
+ "Run In A Directory" => {
28
+ description: 'This will run the ls command in the specified directory.',
29
+ config: {
30
+ directory: '/home/pi/Desktop/mushy'
31
+ },
32
+ result: [{
33
+ inode: "416921",
34
+ hard_links: 1,
35
+ owner: "pi",
36
+ group: "pi",
37
+ size: 1270,
38
+ date: {
39
+ year: 2021,
40
+ month: 10,
41
+ day: 1,
42
+ hour: 10,
43
+ minute: 43,
44
+ second: 35,
45
+ nanosecond: 664409766,
46
+ utc_offset: -18000,
47
+ weekday: 5,
48
+ day_of_month: 1,
49
+ day_of_year: 274,
50
+ string: "2021-10-01 10:43:35 -0500",
51
+ epoch_integer: 1633103015,
52
+ epoch_float: 1633103015.6644099,
53
+ seconds_ago: 454725.436212074
54
+ },
55
+ name: "mushy.gemspec",
56
+ type: "-",
57
+ owner_permission: "rw-",
58
+ group_permission: "r--",
59
+ other_permission: "r--",
60
+ directory: "/home/pi/Desktop/mushy",
61
+ path: "/home/pi/Desktop/mushy/mushy.gemspec"
62
+ },
63
+ {
64
+ inode: "403479",
65
+ hard_links: 3,
66
+ owner: "pi",
67
+ group: "pi",
68
+ size: 4096,
69
+ date: {
70
+ year: 2021,
71
+ month: 3,
72
+ day: 18,
73
+ hour: 8,
74
+ minute: 58,
75
+ second: 51,
76
+ nanosecond: 149096220,
77
+ utc_offset: -18000,
78
+ weekday: 4,
79
+ day_of_month: 18,
80
+ day_of_year: 77,
81
+ string: "2021-03-18 08:58:51 -0500",
82
+ epoch_integer: 1616075931,
83
+ epoch_float: 1616075931.1490963,
84
+ seconds_ago: 17482042.0544623
85
+ },
86
+ name: "test",
87
+ type: "d",
88
+ owner_permission: "rwx",
89
+ group_permission: "r-x",
90
+ other_permission: "r-x",
91
+ directory: "test"
92
+ }
93
+ ]
94
+ },
95
+ "Run For a Specific File" => {
96
+ description: 'This will run the ls command in the specified directory.',
97
+ config: {
98
+ path: 'mushy.gemspec'
99
+ },
100
+ result: {
101
+ inode: "416921",
102
+ hard_links: 1,
103
+ owner: "pi",
104
+ group: "pi",
105
+ size: 1270,
106
+ date: {
107
+ year: 2021,
108
+ month: 10,
109
+ day: 1,
110
+ hour: 10,
111
+ minute: 43,
112
+ second: 35,
113
+ nanosecond: 664409766,
114
+ utc_offset: -18000,
115
+ weekday: 5,
116
+ day_of_month: 1,
117
+ day_of_year: 274,
118
+ string: "2021-10-01 10:43:35 -0500",
119
+ epoch_integer: 1633103015,
120
+ epoch_float: 1633103015.6644099,
121
+ seconds_ago: 454725.436212074
122
+ },
123
+ name: "mushy.gemspec",
124
+ type: "-",
125
+ owner_permission: "rw-",
126
+ group_permission: "r--",
127
+ other_permission: "r--",
128
+ directory: "/home/pi/Desktop/mushy",
129
+ path: "/home/pi/Desktop/mushy/mushy.gemspec"
130
+ }
131
+ }
132
+ }
23
133
  end
24
134
  end
25
135
 
@@ -129,6 +239,8 @@ module Mushy
129
239
  name_segments = result[:name].split "\/"
130
240
  result[:name] = name_segments.pop
131
241
  result[:directory] = name_segments.join "\/"
242
+ elsif result[:type] == 'd'
243
+ result[:directory] = result[:name]
132
244
  else
133
245
  result[:path] = File.join result[:directory], result[:name]
134
246
  end
@@ -7,7 +7,9 @@ module Mushy
7
7
  def self.details
8
8
  {
9
9
  name: 'ParseHtml',
10
- description: 'Parses HTML.',
10
+ title: 'Parse HTML',
11
+ fluxGroup: { name: 'Web' },
12
+ description: 'Extract data from HTML.',
11
13
  config: {
12
14
  path: {
13
15
  description: 'The path to the HTML in the incoming event.',
@@ -20,6 +22,40 @@ module Mushy
20
22
  value: { url: 'a|@href' },
21
23
  }
22
24
  },
25
+ examples: {
26
+ "Example 1" => {
27
+ description: 'Pulling all links out of HTML.',
28
+ input: {
29
+ html: '<a href="one">First</a><a href="two">Second</a>'
30
+ },
31
+ config: {
32
+ path: 'html',
33
+ extract: {
34
+ url: "a|@href",
35
+ name: "a"
36
+ },
37
+ },
38
+ result: [
39
+ { url: 'one', name: 'First' },
40
+ { url: 'two', name: 'Second' }
41
+ ]
42
+ },
43
+ "Example 2" => {
44
+ description: 'Pulling the contents of a single div.',
45
+ input: {
46
+ html: "<div class=\"main\" data-this=\"you\">HEY</a>"
47
+ },
48
+ config: {
49
+ path: 'html',
50
+ extract: {
51
+ content: "div.main",
52
+ class: "div|@class",
53
+ "data-this" => "div|@data-this",
54
+ },
55
+ },
56
+ result: { content: 'HEY', class: 'main', "data-this" => "you" },
57
+ },
58
+ }
23
59
  }
24
60
  end
25
61
 
@@ -5,6 +5,7 @@ module Mushy
5
5
  def self.details
6
6
  details = Browser.details
7
7
  details[:name] = 'Pdf'
8
+ details[:title] = 'PDF'
8
9
  details[:description] = 'Turn a URL into a PDF.'
9
10
 
10
11
  details[:config][:path] = {
@@ -20,7 +21,77 @@ module Mushy
20
21
  value: '',
21
22
  }
22
23
 
23
- details
24
+ details.tap do |config|
25
+ config[:examples] = {
26
+ "PDF of google.com" => {
27
+ description: 'This will open https://www.google.com and take a screenshot.',
28
+ config: {
29
+ url: "https://www.google.com",
30
+ file: 'file.pdf'
31
+ },
32
+ result: {
33
+ url: "https://www.google.com/",
34
+ status: 200,
35
+ title: "Google",
36
+ cookies: [
37
+ {
38
+ name: "1P_JAR",
39
+ value: "2021-10-07-21",
40
+ domain: ".google.com",
41
+ path: "/",
42
+ expires: 1636232420.005369,
43
+ size: 19,
44
+ httpOnly: false,
45
+ secure: true,
46
+ session: false,
47
+ sameSite: "None",
48
+ priority: "Medium"
49
+ }
50
+ ],
51
+ headers: {},
52
+ time: 1.520785498,
53
+ body: "...",
54
+ options: {
55
+ path: "file.pdf",
56
+ full: true,
57
+ quality: 100
58
+ },
59
+ file: {
60
+ inode: "439545",
61
+ hard_links: 1,
62
+ owner: "pi",
63
+ group: "pi",
64
+ size: 54269,
65
+ date: {
66
+ year: 2021,
67
+ month: 10,
68
+ day: 7,
69
+ hour: 16,
70
+ minute: 0,
71
+ second: 20,
72
+ nanosecond: 444437482,
73
+ utc_offset: -18000,
74
+ weekday: 4,
75
+ day_of_month: 7,
76
+ day_of_year: 280,
77
+ string: "2021-10-07 16:00:20 -0500",
78
+ epoch_integer: 1633640420,
79
+ epoch_float: 1633640420.4444375,
80
+ seconds_ago: 0.016297478
81
+ },
82
+ name: "file.pdf",
83
+ type: "-",
84
+ owner_permission: "rw-",
85
+ group_permission: "r--",
86
+ other_permission: "r--",
87
+ directory: "/home/pi/Desktop/mushy",
88
+ path: "/home/pi/Desktop/mushy/file.pdf"
89
+ }
90
+ }
91
+ },
92
+ }
93
+ config[:fluxGroup] = { name: 'Export' }
94
+ end
24
95
  end
25
96
 
26
97
  def adjust input
@@ -5,9 +5,50 @@ module Mushy
5
5
  def self.details
6
6
  {
7
7
  name: 'Pwd',
8
+ title: 'Get the working directory',
8
9
  description: 'Run the "pwd" command.',
10
+ fluxGroup: { name: 'Environment' },
9
11
  config: Mushy::Bash.details[:config].tap { |c| c.delete :command },
10
- }
12
+ }.tap do |c|
13
+ c[:examples] = {
14
+ "Example" => {
15
+ description: 'This will run the pwd command and return the directory information.',
16
+ result: {
17
+ pwd: {
18
+ inode: "403091",
19
+ hard_links: 5,
20
+ owner: "pi",
21
+ group: "pi",
22
+ size: 4095,
23
+ date: {
24
+ year: 2020,
25
+ month: 9,
26
+ day: 5,
27
+ hour: 10,
28
+ minute: 43,
29
+ second: 36,
30
+ nanosecond: 325720074,
31
+ utc_offset: -18001,
32
+ weekday: 2,
33
+ day_of_month: 5,
34
+ day_of_year: 278,
35
+ string: "2020-10-06 11:44:37 -0500",
36
+ epoch_integer: 1633538676,
37
+ epoch_float: 1633538676.32572,
38
+ seconds_ago: 17558.38995246
39
+ },
40
+ name: "mushy",
41
+ type: "d",
42
+ owner_permission: "rwx",
43
+ group_permission: "r-x",
44
+ other_permission: "r-x",
45
+ directory: "/home/pi/Desktop",
46
+ path: "/home/pi/Desktop/mushy"
47
+ }
48
+ }
49
+ }
50
+ }
51
+ end
11
52
  end
12
53
 
13
54
  def process event, config
@@ -7,6 +7,8 @@ module Mushy
7
7
  def self.details
8
8
  {
9
9
  name: 'ReadCsv',
10
+ title: 'Read CSV',
11
+ fluxGroup: { name: 'CSV' },
10
12
  description: 'Read CSV content into events.',
11
13
  config: {
12
14
  data: {
@@ -21,6 +23,31 @@ module Mushy
21
23
  value: '',
22
24
  },
23
25
  },
26
+ examples: {
27
+ "With Headers" => {
28
+ description: 'Using this Flux to read a CSV into many events.',
29
+ input: {
30
+ csv: "first,last,height\njane,doe,short"
31
+ },
32
+ config: {
33
+ data: '{{csv}}'
34
+ },
35
+ result: { "first": "jane", "last": "doe", "height": "short" }
36
+ },
37
+ "No Headers" => {
38
+ description: 'Using this Flux to read a CSV into many events.',
39
+ input: {
40
+ csv: "john,doe,tall\njane,doe,short"
41
+ },
42
+ config: {
43
+ data: '{{csv}}'
44
+ },
45
+ result: [
46
+ { "a": "john", "b": "doe", "c": "tall" },
47
+ { "a": "jane", "b": "doe", "c": "short" }
48
+ ]
49
+ },
50
+ }
24
51
  }
25
52
  end
26
53