mushy 0.2.0 → 0.2.5

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: dc571150c0fa3c2315c75186d48836987ca92d93045de5af848fe450c975a039
4
- data.tar.gz: cbd83a5b9fa9c0106b6891afa33eeb16ddd947bba61c62f13b6ff7e7a574ee0e
3
+ metadata.gz: 76db9c933d82210929659d12c7e003926a9e6616bffa13b3bf52a10748397a77
4
+ data.tar.gz: 619f6c29844f159327805bad1b5ab0a7c73b4292008bab772686af8caf90abb5
5
5
  SHA512:
6
- metadata.gz: 720fb42b4b3df8d46cd7e26a87b793e0d41111f12652d588c0378160a00af08de05bedcb32920d1ce01c2c0efe135caaa48a939edd6b25822f8383cac3acdd1a
7
- data.tar.gz: 1707b73e264d067362a7bd00e48558a9981c807319ff925e92c4fc829cbf8129aac14f31dd0edaba53354893de2ec4be633eebe9da2d882ec568a6394e852d9f
6
+ metadata.gz: edfffd82e02a0e3e1bca89e7b448f4648c57ed130ab09228b743b494d4f78dd3fb995c6cee7277033702206bd96c3a62a193879cc71fc7c6342844cc45c49bcf
7
+ data.tar.gz: ff241f80dbb70b03c7347895437f64e66765b94c99e3ec32a303e9dd6f36c43015c3d1b6935ccd7fc3f73719f4f726e68f2d4be0016ee5125e65e0c802fe6fff
data/lib/mushy.rb CHANGED
@@ -3,7 +3,7 @@ require 'symbolized'
3
3
 
4
4
  Dir[File.dirname(__FILE__) + '/mushy/*.rb'].each { |f| require f }
5
5
 
6
- important_flux_files = ['bash'].map { |x| "#{x}.rb" }
6
+ important_flux_files = ['bash', 'browser'].map { |x| "#{x}.rb" }
7
7
  Dir[File.dirname(__FILE__) + '/mushy/fluxs/*.rb']
8
8
  .sort_by { |f| important_flux_files.any? { |x| f.end_with?(x) } ? 0 : 1 }
9
9
  .each { |f| require f }
@@ -107,7 +107,7 @@ module Mushy
107
107
  };
108
108
  },
109
109
  props: ['label', 'placeholder', 'disabled', 'readonly', 'value', 'description', 'view'],
110
- template: '<div><mip-h4 :id="id" :label="label" :description="description"></mip-h4> <pre><code>{{show(view, value)}}</code></pre><button :disabled="view==\\'beautiful\\'" v-on:click.prevent.stop="view=toggle(view)">{{(view == \\'beautiful\\' ? \\'View Smaller\\' : \\'View Pretty\\')}}</button><button :disabled="view!=\\'beautiful\\'" v-on:click.prevent.stop="view=toggle(view)">View Smaller</button><button v-on:click.prevent.stop="copy(view, value)">Copy</button></div>'
110
+ template: '<div><mip-h4 :id="id" :label="label" :description="description"></mip-h4> <pre><code>{{show(view, value)}}</code></pre><button :disabled="view==\\'beautiful\\'" v-on:click.prevent.stop="view=toggle(view)">View Pretty</button><button :disabled="view!=\\'beautiful\\'" v-on:click.prevent.stop="view=toggle(view)">View Smaller</button><button v-on:click.prevent.stop="copy(view, value)">Copy</button></div>'
111
111
  },
112
112
  radio: {
113
113
  props: ['label', 'value', 'options', 'description', 'shrink'],
data/lib/mushy/flow.rb CHANGED
@@ -30,14 +30,14 @@ module Mushy
30
30
  data = JSON.parse data
31
31
 
32
32
  data_fluxs = data['fluxs'] || []
33
- data_fluxs.select { |x| x['parent'] }.map { |r| r["parent_fluxs"] = [r["parent"]] }
33
+ data_fluxs.select { |x| x['parent'] }.map { |r| r["parents"] = [r["parent"]] }
34
34
 
35
35
  flow = new
36
36
 
37
37
  flow.fluxs = data_fluxs.map { |s| build_flux s }
38
38
 
39
39
  fluxs_with_parent_ids = flow.fluxs.reduce({}) { |t, i| t[i.id] = []; t }
40
- data_fluxs.map { |r| fluxs_with_parent_ids[r['id']] = r['parent_fluxs'] || [] }
40
+ data_fluxs.map { |r| fluxs_with_parent_ids[r['id']] = r['parents'] || [] }
41
41
 
42
42
  flow.fluxs.each do |flux|
43
43
  flux.parent_fluxs = flow.fluxs.select { |x| fluxs_with_parent_ids[flux.id].include?(x.id) }
@@ -51,10 +51,10 @@ module Mushy
51
51
  ],
52
52
  },
53
53
  carry_cookies_from: {
54
- description: 'Carry the cookies from this path in the event.',
54
+ description: 'Carry the cookies from this path in the event. Defaults to "cookies".',
55
55
  type: 'text',
56
56
  shrink: true,
57
- value: 'cookies',
57
+ value: '',
58
58
  },
59
59
  headers: {
60
60
  description: 'Headers for the web request. These can be received from a previous browser event with {{headers}}, or can be typed manually.',
@@ -63,10 +63,10 @@ module Mushy
63
63
  value: {},
64
64
  },
65
65
  carry_headers_from: {
66
- description: 'Carry the headers from this path in the event.',
66
+ description: 'Carry the headers from this path in the event. Defaults to "headers".',
67
67
  type: 'text',
68
68
  shrink: true,
69
- value: 'headers',
69
+ value: '',
70
70
  },
71
71
  wait_before_closing: {
72
72
  description: 'Wait this many seconds before closing the browser.',
@@ -105,13 +105,20 @@ module Mushy
105
105
  body: browser.body
106
106
  }
107
107
 
108
+ result = adjust( { browser: browser, result: result, config: config } )
109
+
108
110
  browser.quit
109
111
 
110
112
  result
111
113
  end
112
114
 
115
+ def adjust input
116
+ input[:result]
117
+ end
118
+
113
119
  def get_the_cookies_from event, config
114
- cookies = (event[config[:carry_cookies_from].to_sym])
120
+ carry_cookies_from = config[:carry_cookies_from].to_s == '' ? 'cookies' : config[:carry_cookies_from]
121
+ cookies = event[carry_cookies_from.to_sym]
115
122
  cookies = [] unless cookies.is_a?(Array)
116
123
  config[:cookies] = [] unless config[:cookies].is_a?(Array)
117
124
  config[:cookies].each { |x| cookies << x }
@@ -119,7 +126,8 @@ module Mushy
119
126
  end
120
127
 
121
128
  def get_the_headers_from event, config
122
- headers = (event[config[:carry_headers_from].to_sym])
129
+ carry_headers_from = config[:carry_headers_from].to_s == '' ? 'headers' : config[:carry_headers_from]
130
+ headers = event[carry_headers_from.to_sym]
123
131
  headers = {} unless headers.is_a?(Hash)
124
132
  config[:headers] = {} unless config[:headers].is_a?(Hash)
125
133
  config[:headers].each { |k, v| headers[k] = v }
@@ -0,0 +1,46 @@
1
+ module Mushy
2
+
3
+ class Pdf < Browser
4
+
5
+ def self.details
6
+ details = Browser.details
7
+ details['name'] = 'Pdf'
8
+ details['description'] = 'Turn a URL into a PDF.'
9
+
10
+ details[:config][:path] = {
11
+ description: 'The path of the PDF file to save.',
12
+ type: 'text',
13
+ value: 'picture.pdf',
14
+ }
15
+
16
+ details[:config][:landscape] = {
17
+ description: 'Build the PDF in landscape. Defaults to false.',
18
+ type: 'boolean',
19
+ shrink: true,
20
+ value: '',
21
+ }
22
+
23
+ details
24
+ end
25
+
26
+ def adjust input
27
+
28
+ the_browser = input[:browser]
29
+ the_result = input[:result]
30
+ the_config = input[:config]
31
+
32
+ options = {
33
+ path: the_config[:path],
34
+ }
35
+
36
+ options[:landscape] = true if the_config[:landscape].to_s == 'true'
37
+
38
+ the_browser.pdf options
39
+
40
+ options
41
+
42
+ end
43
+
44
+ end
45
+
46
+ end
@@ -4,10 +4,30 @@ module Mushy
4
4
 
5
5
  class ReadCsv < Flux
6
6
 
7
+ def self.details
8
+ {
9
+ name: 'ReadCsv',
10
+ description: 'Read CSV content into events.',
11
+ config: {
12
+ data: {
13
+ description: 'The data to convert to a CSV.',
14
+ type: 'text',
15
+ value: '{{data}}',
16
+ },
17
+ headers: {
18
+ description: 'The CSV contains headers. Defaults to false.',
19
+ type: 'boolean',
20
+ shrink: true,
21
+ value: '',
22
+ },
23
+ },
24
+ }
25
+ end
26
+
7
27
  def process event, config
8
- data = event[config[:key]]
28
+ data = config[:data]
9
29
 
10
- headers = config[:headers].to_s.strip.downcase == 'true' ? true : false
30
+ headers = config[:headers].to_s.strip.downcase == 'true'
11
31
 
12
32
  rows = CSV.new data, headers: headers
13
33
 
@@ -0,0 +1,44 @@
1
+ module Mushy
2
+
3
+ class ReadFile < Flux
4
+
5
+ def self.details
6
+ {
7
+ name: 'ReadFile',
8
+ description: 'Read a file.',
9
+ config: {
10
+ name: {
11
+ description: 'The name of the file to read.',
12
+ type: 'text',
13
+ value: 'file.csv',
14
+ },
15
+ directory: {
16
+ description: 'The directory in which to read the file. Leave blank for the current directory.',
17
+ type: 'text',
18
+ shrink: true,
19
+ value: '',
20
+ },
21
+ path: {
22
+ description: 'The path in the event to return the contents of the file.',
23
+ type: 'text',
24
+ value: 'content',
25
+ },
26
+ },
27
+ }
28
+ end
29
+
30
+ def process event, config
31
+ file = config[:name]
32
+
33
+ file = File.join(config[:directory], file) if config[:directory].to_s != ''
34
+
35
+ content = File.open(file).read
36
+
37
+ {
38
+ config[:path] => content
39
+ }
40
+ end
41
+
42
+ end
43
+
44
+ end
@@ -0,0 +1,50 @@
1
+ module Mushy
2
+
3
+ class Screenshot < Browser
4
+
5
+ def self.details
6
+ details = Browser.details
7
+ details['name'] = 'Screenshot'
8
+ details['description'] = 'Take a screenshot of the browser.'
9
+
10
+ details[:config][:path] = {
11
+ description: 'The path of the file to save.',
12
+ type: 'text',
13
+ value: 'picture.jpg',
14
+ }
15
+ details[:config][:quality] = {
16
+ description: 'The quality of the image, a value beteen 0-100. Only applies to jpg.',
17
+ type: 'integer',
18
+ shrink: true,
19
+ value: '',
20
+ }
21
+ details[:config][:full] = {
22
+ description: 'Take a screenshot of the entire page. If false, the screenshot is limited to the viewport.',
23
+ type: 'boolean',
24
+ shrink: true,
25
+ value: '',
26
+ }
27
+ details
28
+ end
29
+
30
+ def adjust input
31
+
32
+ the_browser = input[:browser]
33
+ the_result = input[:result]
34
+ the_config = input[:config]
35
+
36
+ options = {
37
+ path: the_config[:path],
38
+ full: ['true', ''].include?(the_config[:full].to_s),
39
+ quality: (the_config[:quality].to_s == '' ? '100' : the_config[:quality]).to_i
40
+ }
41
+
42
+ the_browser.screenshot options
43
+
44
+ options
45
+
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,115 @@
1
+ require 'pony'
2
+
3
+ module Mushy
4
+
5
+ class Smtp < Flux
6
+
7
+ def self.details
8
+ {
9
+ name: 'Smtp',
10
+ description: 'Send email through SMTP.',
11
+ config: {
12
+ from: {
13
+ description: 'From whom the email will be sent.',
14
+ type: 'text',
15
+ shrink: true,
16
+ value: '',
17
+ },
18
+ to: {
19
+ description: 'To whom the email should be sent.',
20
+ type: 'text',
21
+ value: '',
22
+ },
23
+ subject: {
24
+ description: 'The subject of the email.',
25
+ type: 'text',
26
+ value: '',
27
+ },
28
+ body: {
29
+ description: 'The text body of the email.',
30
+ type: 'textarea',
31
+ value: '',
32
+ },
33
+ html_body: {
34
+ description: 'The HTML body of the email.',
35
+ type: 'textarea',
36
+ value: '',
37
+ },
38
+ attachment_file: {
39
+ description: 'The full path of a file to attach.',
40
+ type: 'text',
41
+ shrink: true,
42
+ value: '',
43
+ },
44
+ address: {
45
+ description: 'The address of the SMTP server.',
46
+ type: 'text',
47
+ value: 'smtp.gmail.com',
48
+ },
49
+ port: {
50
+ description: 'The SMTP server port.',
51
+ type: 'integer',
52
+ value: '587',
53
+ },
54
+ domain: {
55
+ description: 'The email domain.',
56
+ type: 'text',
57
+ value: 'gmail.com',
58
+ },
59
+ username: {
60
+ description: 'The username.',
61
+ type: 'text',
62
+ value: '',
63
+ },
64
+ password: {
65
+ description: 'The password.',
66
+ type: 'text',
67
+ value: '',
68
+ },
69
+ },
70
+ }
71
+ end
72
+
73
+ def process event, config
74
+ options = adjust(cleanup({
75
+ from: config[:from],
76
+ to: config[:to],
77
+ subject: config[:subject],
78
+ body: config[:body],
79
+ html_body: config[:html_body],
80
+ via_options: get_via_options_from(config)
81
+ }))
82
+
83
+ if (config[:attachment_file].to_s != '')
84
+ options[:attachments] = { config[:attachment_file].split("\/")[-1] => File.read(config[:attachment_file]) }
85
+ end
86
+
87
+ result = Pony.mail options
88
+ options.tap { |x| x.delete(:via_options) }
89
+ end
90
+
91
+ def adjust options
92
+ options.tap { |x| x[:via] = 'smtp' }
93
+ end
94
+
95
+ def cleanup options
96
+ options.tap do |hash|
97
+ hash.delete_if { |_, v| v.to_s == '' }
98
+ end
99
+ end
100
+
101
+ def get_via_options_from config
102
+ {
103
+ address: config[:address],
104
+ port: config[:port].to_s,
105
+ user_name: config[:username],
106
+ password: config[:password],
107
+ domain: config[:domain],
108
+ authentication: :plain,
109
+ enable_starttls_auto: true,
110
+ }
111
+ end
112
+
113
+ end
114
+
115
+ end
@@ -27,12 +27,15 @@ module Mushy
27
27
  end
28
28
 
29
29
  def process event, config
30
+ file = config[:name]
30
31
 
31
- File.open(config[:name], 'w') { |f| f.write config[:data] }
32
+ file = File.join(config[:directory], file) if config[:directory].to_s != ''
33
+
34
+ File.open(file, 'w') { |f| f.write config[:data] }
32
35
 
33
36
  {}
34
37
  end
35
38
 
36
39
  end
37
40
 
38
- end
41
+ end
data/mushy.gemspec CHANGED
@@ -4,7 +4,7 @@ require 'mushy/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'mushy'
7
- s.version = '0.2.0'
7
+ s.version = '0.2.5'
8
8
  s.date = '2020-11-23'
9
9
  s.summary = 'Process streams of work using common modules.'
10
10
  s.description = 'This tool assists in the creation and processing of workflows.'
@@ -24,4 +24,5 @@ Gem::Specification.new do |s|
24
24
  s.add_runtime_dependency 'ferrum'
25
25
  s.add_runtime_dependency 'nokogiri'
26
26
  s.add_runtime_dependency 'faraday'
27
+ s.add_runtime_dependency 'pony'
27
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mushy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darren Cauthon
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pony
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  description: This tool assists in the creation and processing of workflows.
126
140
  email: darren@cauthon.com
127
141
  executables:
@@ -149,7 +163,11 @@ files:
149
163
  - lib/mushy/fluxs/get.rb
150
164
  - lib/mushy/fluxs/ls.rb
151
165
  - lib/mushy/fluxs/parse_html.rb
166
+ - lib/mushy/fluxs/pdf.rb
152
167
  - lib/mushy/fluxs/read_csv.rb
168
+ - lib/mushy/fluxs/read_file.rb
169
+ - lib/mushy/fluxs/screenshot.rb
170
+ - lib/mushy/fluxs/smtp.rb
153
171
  - lib/mushy/fluxs/write_file.rb
154
172
  - lib/mushy/masher.rb
155
173
  - lib/mushy/run.rb