tolliver 2.1.1 → 2.1.2

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: 652fa21e199c69608d3a5bccec4a1702b4ffb547950cc0a4cdecede13100398d
4
- data.tar.gz: 10d9e9b2b207ef9d7af899115b1703794fd5821249bb232fb1fc1e51f29d14fe
3
+ metadata.gz: 5a1110eda739a5bb9763c51608a6a251c356962bc02690b2b5b81d06239d0893
4
+ data.tar.gz: 4ab466afccc3086a66c4d50ecc7c87214b89aa734553f64b8e7f73c93ec491a5
5
5
  SHA512:
6
- metadata.gz: cf3765a95bde23c800142e846a64548dc6fbf293c9bc65027eccddfe24b0f88505ec9310b57821c7268711e1ba8fe0b81ed352a60565ccee6375a797bfb27895
7
- data.tar.gz: '08c5fcda8093414dc792608fa8d21cff313862f054b21e65efc21c4c4045fb5d854dfc4fc296829ad95874b7b9f35f6439d83b601d391bc62c59d0cb0ad72348'
6
+ metadata.gz: 5901317de7117ceca9fcc6396706d018d62d99ebaf69b7361fe2118766c9bf87a6ac684c8169815818b9ac66fe06e9cd6c0326d86ea6f46202abc6352f7d9365
7
+ data.tar.gz: 65913171587f3632ed28e43a00827b109a84b8497ffd39651f1002da4ce7cc0a57a8ccaa43982ecf1ef949e3e0e45f7b9fc85328009784c2b88e51a29d2a6d3f
@@ -0,0 +1,6 @@
1
+ class AddNotificationAttachmentsUrl < ActiveRecord::Migration[6.0]
2
+ def change
3
+ change_column :notification_attachments, :attachment, :text
4
+ add_column :notification_attachments, :url, :string
5
+ end
6
+ end
@@ -29,7 +29,7 @@ module Tolliver
29
29
 
30
30
  # Attachments
31
31
  notification.notification_attachments.each do |notification_attachment|
32
- attachments[notification_attachment.name] = notification_attachment.attachment
32
+ attachments[notification_attachment.name] = notification_attachment.read if notification_attachment.read
33
33
  end
34
34
 
35
35
  # Mail
@@ -30,6 +30,18 @@ module Tolliver
30
30
 
31
31
  end
32
32
 
33
+ def read
34
+ if @data.nil?
35
+ unless notification_attachment.attachment.blank?
36
+ @data = Base64.strict_decode64(notification_attachment.attachment) rescue nil
37
+ end
38
+ unless notification_attachment.url.blank?
39
+ @data = open(notification_attachment.url) { |f| f.read }
40
+ end
41
+ end
42
+ @data
43
+ end
44
+
33
45
  end
34
46
  end
35
47
  end
@@ -38,7 +38,7 @@ module Tolliver
38
38
  message.body_text(ActionController::Base.helpers.strip_tags(notification.message.to_s))
39
39
  message.body_html(notification.message)
40
40
  notification.notification_attachments.each do |notification_attachment|
41
- message.add_attachment(StringIO.new(notification_attachment.attachment), notification_attachment.name)
41
+ message.add_attachment(StringIO.new(notification_attachment.read), notification_attachment.name) if notification_attachment.read
42
42
  end
43
43
  response = @client.send_message(@domain, message)
44
44
  if response.code != 200
@@ -55,8 +55,10 @@ module Tolliver
55
55
  attachments = [attachments] unless attachments.is_a?(Array)
56
56
  attachments.each do |attachment|
57
57
  raise Tolliver::Errors::BadRequest.new('Missing attachment name.') if attachment[:name].blank?
58
- raise Tolliver::Errors::BadRequest.new('Missing attachment data.') if attachment[:attachment].blank?
59
- notification.notification_attachments.create(name: attachment[:name], attachment: attachment[:attachment])
58
+ if attachment[:attachment].blank? && attachment[:url].blank?
59
+ raise Tolliver::Errors::BadRequest.new('Missing attachment data or URL.')
60
+ end
61
+ notification.notification_attachments.create(name: attachment[:name], attachment: attachment[:attachment], url: attachment[:url])
60
62
  end
61
63
  end
62
64
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tolliver
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matěj Outlý
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-05 00:00:00.000000000 Z
11
+ date: 2021-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -50,6 +50,7 @@ files:
50
50
  - db/migrate/20160509144238_create_notification_templates.rb
51
51
  - db/migrate/20170630190600_create_notification_deliveries.rb
52
52
  - db/migrate/20201027150000_create_notification_attachments.rb
53
+ - db/migrate/20210415120000_add_notification_attachments_url.rb
53
54
  - lib/tolliver.rb
54
55
  - lib/tolliver/engine.rb
55
56
  - lib/tolliver/errors/bad_request.rb