postman_mta 0.1.9 → 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
- SHA1:
3
- metadata.gz: d53a5cdbcde061a2bbe6ffed3e4ce58785c6f636
4
- data.tar.gz: 3f3fdb5cac0656328f4386c1951a398bff266ee2
2
+ SHA256:
3
+ metadata.gz: 6505bfbf9fe78bbb7726d321c38e8206e81c9a21da85fd27d438b7c755fe8b40
4
+ data.tar.gz: 891a13937aa6592cd04df517a3dd04ac0069d625c3f663b96447cd81c5538fd2
5
5
  SHA512:
6
- metadata.gz: a48766136986532d03e64836aa130dc9b89637167dace6d0859d6c00f606c1cd91acd0c30270fc93f7d095d286b359c04be5a52a22953a3a5d4bebfdcecb2768
7
- data.tar.gz: c699eeaa9e14026d4e465202783c865b0a9b00bceeee8ffc349d3533a6b7039c6824a2f32fba061eae4de610accf4f481dbf9f96781523756072c7fdb654119e
6
+ metadata.gz: fcdb6f1967352b1130fd5b0287c475fe79d144ef2dc8739122b7116e5fb811e19fa26714f793dba573a532843eb947fefc2ddc433806edc490569f8a50cad1cc
7
+ data.tar.gz: 037b20cf0e0ec0216e1fa81b7b6f4844c8b570f3999146b90da8401e755a8a648ed4b6f7f97b41deeb7c7612445103bb0b6f32067b40b0fc673b864401a5ccbc
data/.rubocop.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.3
2
+ TargetRubyVersion: 2.4
3
3
 
4
- Excludes:
4
+ Exclude:
5
5
  - "Guardfile"
6
6
  - "Rakefile"
7
7
  - "bin/**/*"
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.1
data/Gemfile CHANGED
@@ -9,6 +9,6 @@ group :development, :test do
9
9
  gem 'api_matchers', '~> 0.6.2'
10
10
  gem 'rails', '~> 5.0'
11
11
  gem 'rspec-rails', '~> 3.5', '>= 3.5.2'
12
- gem 'sqlite3', '~> 1.3', '>= 1.3.13'
12
+ gem 'sqlite3', '~> 1.3', '< 1.4'
13
13
  gem 'webmock', '~> 3.0', '>= 3.0.1'
14
14
  end
@@ -5,9 +5,12 @@ module PostmanMta
5
5
  def show
6
6
  response = attachment.find(params[:uuid]).deep_symbolize_keys
7
7
  file = response.dig(:json, :attachment)
8
- file_data = Base64.decode64(file[:body])
9
8
 
10
- send_data(file_data, type: file[:content_type], filename: file[:filename], dispostion: 'attachment')
9
+ if file[:body].present?
10
+ send_attachment(file)
11
+ else
12
+ proxy_attachment(file)
13
+ end
11
14
  end
12
15
 
13
16
  private
@@ -15,5 +18,15 @@ module PostmanMta
15
18
  def attachment
16
19
  @attachment ||= PostmanMta::Attachment.new(params[:message_token])
17
20
  end
21
+
22
+ def send_attachment(file)
23
+ file_data = Base64.decode64(file[:body])
24
+ send_data(file_data, type: file[:content_type], filename: file[:filename], dispostion: 'attachment')
25
+ end
26
+
27
+ def proxy_attachment(file)
28
+ headers['X-Accel-Redirect'] = PostmanMta::Utils::SendfileUrl.new(file[:url]).to_url
29
+ headers['Content-Disposition'] = "attachment; filename=\"#{file[:filename]}\""
30
+ end
18
31
  end
19
32
  end
data/config.reek CHANGED
@@ -12,3 +12,7 @@ UtilityFunction:
12
12
  exclude:
13
13
  - "PostmanMta::Utils::Signature#digest"
14
14
  - "PostmanMta::ApiClient#perform_request"
15
+
16
+ FeatureEnvy:
17
+ exclude:
18
+ - 'PostmanMta::AttachmentsController#send_attachment'
@@ -0,0 +1,21 @@
1
+ require 'uri'
2
+
3
+ module PostmanMta
4
+ module Utils
5
+ class SendfileUrl
6
+ PREFIX = '/private'.freeze
7
+
8
+ def initialize(data)
9
+ @data = data
10
+ end
11
+
12
+ def uri
13
+ @uri ||= URI(@data)
14
+ end
15
+
16
+ def to_url
17
+ File.join(PREFIX, uri.host, "#{uri.path}?#{uri.query}")
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PostmanMta
4
- VERSION = '0.1.9'
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/postman_mta.rb CHANGED
@@ -5,6 +5,7 @@ module PostmanMta
5
5
  module Utils
6
6
  autoload :Signature, 'postman_mta/utils/signature'
7
7
  autoload :SignedRequest, 'postman_mta/utils/signed_request'
8
+ autoload :SendfileUrl, 'postman_mta/utils/sendfile_url'
8
9
  end
9
10
 
10
11
  autoload :ApiClient, 'postman_mta/api_client'
data/postman_mta.gemspec CHANGED
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency 'rake', '~> 10.0'
30
30
  spec.add_development_dependency 'reek'
31
31
  spec.add_development_dependency 'rubocop'
32
+ spec.add_development_dependency 'sqlite3'
32
33
 
33
34
  spec.add_dependency 'httparty', '~> 0.15'
34
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postman_mta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Malinovskiy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-31 00:00:00.000000000 Z
11
+ date: 2019-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,6 +100,20 @@ dependencies:
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: sqlite3
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
103
117
  - !ruby/object:Gem::Dependency
104
118
  name: httparty
105
119
  requirement: !ruby/object:Gem::Requirement
@@ -126,6 +140,7 @@ files:
126
140
  - ".overcommit.yml"
127
141
  - ".rspec"
128
142
  - ".rubocop.yml"
143
+ - ".ruby-version"
129
144
  - ".travis.yml"
130
145
  - Gemfile
131
146
  - Guardfile
@@ -159,6 +174,7 @@ files:
159
174
  - lib/postman_mta/api_client.rb
160
175
  - lib/postman_mta/api_request.rb
161
176
  - lib/postman_mta/engine.rb
177
+ - lib/postman_mta/utils/sendfile_url.rb
162
178
  - lib/postman_mta/utils/signature.rb
163
179
  - lib/postman_mta/utils/signed_request.rb
164
180
  - lib/postman_mta/version.rb
@@ -183,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
199
  version: '0'
184
200
  requirements: []
185
201
  rubyforge_project:
186
- rubygems_version: 2.6.14.1
202
+ rubygems_version: 2.7.6
187
203
  signing_key:
188
204
  specification_version: 4
189
205
  summary: Rails gem to easy integrate postman to your application