kanal 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +2 -2
- data/lib/kanal/plugins/batteries/attachments/attachment.rb +163 -0
- data/lib/kanal/plugins/batteries/batteries_plugin.rb +16 -0
- data/lib/kanal/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22224712e17434c60d3b437d44a35a5a997dd739cddcf53eb365d588fdf19fcd
|
4
|
+
data.tar.gz: f6677a4a8bc6eacf2e41469ba4a36da1b324d3b7d9092ae9271aa1b9f3fa8be6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e1416fb809513b53627cb120d8b09dfb76cae30f952de0212a1c2edde48e01d733afb122189230d0e6426dba812d143a8b2fc35b8561fba95954ea0b0bccbe2
|
7
|
+
data.tar.gz: 3dcc90d49fa16f4df0482d77a94f3f21a7ddc12742983a8925714199100284bfb4d84a96bef19aa289c3ad1ebcc21996d3a27fb9874837b24ca343ba53f700d6
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.4.1] 2023-03-16
|
4
|
+
- Added Attachment that can be used inside new input parameters in Batteries plugin
|
5
|
+
- New input and output parameters in Batteries plugin: image, audio, file
|
6
|
+
|
3
7
|
## [0.4.0] 2023-03-10
|
4
8
|
- Added logging feature to Kanal, for a time being - just stdout
|
5
9
|
- Error response, now Kanal Router accepts error response block, when things go haywire inside constructing output
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,163 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "fileutils"
|
4
|
+
require "uri"
|
5
|
+
require 'open-uri'
|
6
|
+
|
7
|
+
module Kanal
|
8
|
+
module Plugins
|
9
|
+
module Batteries
|
10
|
+
module Attachments
|
11
|
+
class Attachment
|
12
|
+
attr_reader :url
|
13
|
+
|
14
|
+
def initialize(url)
|
15
|
+
@url = url
|
16
|
+
end
|
17
|
+
|
18
|
+
def audio?
|
19
|
+
mp3? || wav? || ogg?
|
20
|
+
end
|
21
|
+
|
22
|
+
def mp3?
|
23
|
+
extension == "mp3"
|
24
|
+
end
|
25
|
+
|
26
|
+
def wav?
|
27
|
+
extension == "wav"
|
28
|
+
end
|
29
|
+
|
30
|
+
def ogg?
|
31
|
+
extension == "ogg"
|
32
|
+
end
|
33
|
+
|
34
|
+
def document?
|
35
|
+
doc? || docx? || odf?
|
36
|
+
end
|
37
|
+
|
38
|
+
def doc?
|
39
|
+
extension == "doc"
|
40
|
+
end
|
41
|
+
|
42
|
+
def docx?
|
43
|
+
extension == "docx"
|
44
|
+
end
|
45
|
+
|
46
|
+
def odf?
|
47
|
+
extension == "odf"
|
48
|
+
end
|
49
|
+
|
50
|
+
def image?
|
51
|
+
jpg? || jpeg? || png? || bpm? || gif?
|
52
|
+
end
|
53
|
+
|
54
|
+
def jpg?
|
55
|
+
extension == "jpg"
|
56
|
+
end
|
57
|
+
|
58
|
+
def jpeg?
|
59
|
+
extension == "jpeg"
|
60
|
+
end
|
61
|
+
|
62
|
+
def png?
|
63
|
+
extension == "png"
|
64
|
+
end
|
65
|
+
|
66
|
+
def bpm?
|
67
|
+
extension == "bpm"
|
68
|
+
end
|
69
|
+
|
70
|
+
def gif?
|
71
|
+
extension == "gif"
|
72
|
+
end
|
73
|
+
|
74
|
+
def video?
|
75
|
+
mp4? || mov? || mkv?
|
76
|
+
end
|
77
|
+
|
78
|
+
def mp4?
|
79
|
+
extension == "mp4"
|
80
|
+
end
|
81
|
+
|
82
|
+
def mov?
|
83
|
+
extension == "mov"
|
84
|
+
end
|
85
|
+
|
86
|
+
def mkv?
|
87
|
+
extension == "mkv"
|
88
|
+
end
|
89
|
+
|
90
|
+
#
|
91
|
+
# Method that returns extension of url file if possible
|
92
|
+
# For example calling extension https://123.txt?something=1 will return 'txt'
|
93
|
+
#
|
94
|
+
# @return [String, nil]
|
95
|
+
#
|
96
|
+
def extension
|
97
|
+
uri = URI.parse(@url)
|
98
|
+
return nil if uri.path.nil?
|
99
|
+
|
100
|
+
File.extname(uri.path).split(".").last if File.basename(uri.path).include? "."
|
101
|
+
end
|
102
|
+
|
103
|
+
#
|
104
|
+
# Saves file to specified path. End user provides full filepath.
|
105
|
+
#
|
106
|
+
# @param [String] <Full filepath>
|
107
|
+
# @param [Boolean] <Should directories be created or not>
|
108
|
+
#
|
109
|
+
# @return [void]
|
110
|
+
#
|
111
|
+
def save(filepath, create_dirs = false)
|
112
|
+
stream = URI.open(@url)
|
113
|
+
|
114
|
+
save_stream_to_file stream, filepath, create_dirs
|
115
|
+
end
|
116
|
+
|
117
|
+
#
|
118
|
+
# Saves file. End user provides directory only. Filename gets generated, extension is read from url.
|
119
|
+
#
|
120
|
+
# @param [String] <Directory>
|
121
|
+
# @param [Boolean] <Should directories be created or not>
|
122
|
+
# @param [Integer] <Length of filename to generate>
|
123
|
+
#
|
124
|
+
# @return [String] Full filepath to saved file
|
125
|
+
#
|
126
|
+
def quick_save(directory, create_dir = false, filename_length = 32)
|
127
|
+
filename = generate_filename filename_length, extension
|
128
|
+
|
129
|
+
return quick_save directory, create_dir, filename_length if File.exist? filename
|
130
|
+
|
131
|
+
save directory + filename, create_dir
|
132
|
+
|
133
|
+
directory + filename
|
134
|
+
end
|
135
|
+
|
136
|
+
private
|
137
|
+
|
138
|
+
def generate_filename(filename_length, extension = nil)
|
139
|
+
alphanumeric = "abcdefghijkmnopQRSTUVWNXYZW12345676789-".chars
|
140
|
+
|
141
|
+
name = ""
|
142
|
+
|
143
|
+
filename_length.times do
|
144
|
+
name += alphanumeric.sample
|
145
|
+
end
|
146
|
+
|
147
|
+
extension ? "#{name}.#{extension}" : name
|
148
|
+
end
|
149
|
+
|
150
|
+
def save_stream_to_file(stream, filepath, create_dirs)
|
151
|
+
raise "File with that name already exists!" if File.exist? filepath
|
152
|
+
|
153
|
+
if create_dirs == true
|
154
|
+
FileUtils.mkdir_p(File.dirname(filepath)) unless File.directory?(File.dirname(filepath))
|
155
|
+
end
|
156
|
+
|
157
|
+
IO.copy_stream stream, filepath
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
@@ -16,6 +16,8 @@ module Kanal
|
|
16
16
|
source_batteries core
|
17
17
|
body_batteries core
|
18
18
|
flow_batteries core
|
19
|
+
attachments_batteries core
|
20
|
+
reply_markup_batteries core
|
19
21
|
end
|
20
22
|
|
21
23
|
def flow_batteries(core)
|
@@ -110,6 +112,20 @@ module Kanal
|
|
110
112
|
end
|
111
113
|
end
|
112
114
|
end
|
115
|
+
|
116
|
+
def attachments_batteries(core)
|
117
|
+
core.register_input_parameter :image
|
118
|
+
core.register_input_parameter :audio
|
119
|
+
core.register_input_parameter :file
|
120
|
+
|
121
|
+
core.register_output_parameter :image
|
122
|
+
core.register_output_parameter :audio
|
123
|
+
core.register_output_parameter :file
|
124
|
+
end
|
125
|
+
|
126
|
+
def reply_markup_batteries(core)
|
127
|
+
core.register_output_parameter :reply_markup
|
128
|
+
end
|
113
129
|
end
|
114
130
|
end
|
115
131
|
end
|
data/lib/kanal/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kanal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- idchlife
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Thanks to the core library, ecosystem of Kanal tools can be extendted
|
14
14
|
to use with input-output bot-like behaviour, with routing
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- lib/kanal/core/router/router_storage.rb
|
59
59
|
- lib/kanal/core/services/service_container.rb
|
60
60
|
- lib/kanal/interfaces/simple_cli/simple_cli_interface.rb
|
61
|
+
- lib/kanal/plugins/batteries/attachments/attachment.rb
|
61
62
|
- lib/kanal/plugins/batteries/batteries_plugin.rb
|
62
63
|
- lib/kanal/version.rb
|
63
64
|
- sig/kanal.rbs
|