postman_mta 0.1.7 → 0.2.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
- SHA1:
3
- metadata.gz: fab550588eda2e9d22a008b8acbd4004922fa042
4
- data.tar.gz: 2b28cbeb65d3e81abaef24122bf1228b3b77e0ea
2
+ SHA256:
3
+ metadata.gz: 7d6d5fffa4743f5f68aca42d85ce8504cd3b1438e87b08b9aab67f8c86dcd1a8
4
+ data.tar.gz: 9e533b9344643973321ed86143708bd19db68424f995499478a24c0e5b5c05e6
5
5
  SHA512:
6
- metadata.gz: 5bb1c93d360b9dfbf0fdc2169ff5411747fd03e3e74e57eac9d08e3f60a56292ed86573ca9f4369259d8c2098cbaadff7336b503b5ef245828ec4b47137a1e66
7
- data.tar.gz: 8b02e0f717d57da96b8ba2917aba388740a4d8186674ca541956f644c535e62a4046e0ed7a4f4d89051bca501972fe3531c6d1d53ea05655a1248181f7a7cef6
6
+ metadata.gz: f1eec23222904c934a81f5e1a867f9a0bb0a670403e984274ae4a941a6acd6d702c630fd623c05bb6c155b2fe3a32280699be1e8aa58d2c750de866aa5f100f1
7
+ data.tar.gz: ca7da62ced3248c0735e49f7fa4f4f323fab93cd72e59cd32f2a7d65d5ba836ba9c70fcc544d038eab9b231d8989f37292ecb2dbba66317b4df205080130014a
@@ -1,7 +1,7 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.3
3
-
4
- Excludes:
2
+ NewCops: disable
3
+ TargetRubyVersion: 2.4
4
+ Exclude:
5
5
  - "Guardfile"
6
6
  - "Rakefile"
7
7
  - "bin/**/*"
@@ -30,7 +30,7 @@ Lint/AmbiguousBlockAssociation:
30
30
 
31
31
  ##################### Metrics ##################################
32
32
 
33
- Metrics/LineLength:
33
+ Layout/LineLength:
34
34
  Max: 110
35
35
 
36
36
  Metrics/ClassLength:
@@ -45,11 +45,3 @@ Metrics/BlockLength:
45
45
  Max: 50
46
46
  Exclude:
47
47
  - "**/*_spec.rb"
48
-
49
- ##################### Rails ##################################
50
-
51
- Rails:
52
- Enabled: true
53
-
54
- Rails/SkipsModelValidations:
55
- Enabled: false
@@ -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
@@ -0,0 +1,23 @@
1
+ module PostmanMta
2
+ module Archive
3
+ class ConversationsController < ApplicationController
4
+ def index
5
+ render conversation.index(permitted_params)
6
+ end
7
+
8
+ def show
9
+ render conversation.find(params[:id])
10
+ end
11
+
12
+ private
13
+
14
+ def conversation
15
+ @conversation ||= PostmanMta::Archive::Conversation.new
16
+ end
17
+
18
+ def permitted_params
19
+ params.permit!
20
+ end
21
+ end
22
+ end
23
+ 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
@@ -30,6 +30,10 @@ module PostmanMta
30
30
  render conversation.move(permitted_params)
31
31
  end
32
32
 
33
+ def search
34
+ render conversation.search(permitted_params)
35
+ end
36
+
33
37
  private
34
38
 
35
39
  def conversation
@@ -0,0 +1,17 @@
1
+ module PostmanMta
2
+ class DomainsController < ApplicationController
3
+ def index
4
+ render domain.index(permitted_params)
5
+ end
6
+
7
+ private
8
+
9
+ def domain
10
+ @domain ||= PostmanMta::Domain.new
11
+ end
12
+
13
+ def permitted_params
14
+ params.permit!
15
+ end
16
+ end
17
+ end
@@ -1,9 +1,17 @@
1
1
  module PostmanMta
2
2
  class LabelsController < ApplicationController
3
+ def index
4
+ render label.index(label_params)
5
+ end
6
+
3
7
  def create
4
8
  render label.create(label_params)
5
9
  end
6
10
 
11
+ def update
12
+ render label.update(params[:id], label_params)
13
+ end
14
+
7
15
  def destroy
8
16
  render label.destroy(params[:id])
9
17
  end
@@ -0,0 +1,13 @@
1
+ module PostmanMta
2
+ module Archive
3
+ class Conversation < PostmanMta::Conversation
4
+ def index(params = {})
5
+ get('/archive/conversations', body: params)
6
+ end
7
+
8
+ def find(conversation_id)
9
+ get("/archive/conversations/#{conversation_id}")
10
+ end
11
+ end
12
+ end
13
+ end
@@ -7,7 +7,7 @@ module PostmanMta
7
7
  end
8
8
 
9
9
  def find(uuid)
10
- get("/api/v1/messages/#{message_token}/attachments/#{uuid}")
10
+ get("/messages/#{message_token}/attachments/#{uuid}")
11
11
  end
12
12
  end
13
13
  end
@@ -0,0 +1,18 @@
1
+ module PostmanMta
2
+ class Bookmark < ApplicationModel
3
+ attr_reader :target_type, :target_id
4
+
5
+ def initialize(target_type, target_id)
6
+ @target_type = target_type
7
+ @target_id = target_id
8
+ end
9
+
10
+ def create(params)
11
+ post("/#{target_type}/#{target_id}/bookmarks", body: params)
12
+ end
13
+
14
+ def destroy(bookmark_id)
15
+ delete("/#{target_type}/#{target_id}/bookmarks/#{bookmark_id}")
16
+ end
17
+ end
18
+ end
@@ -1,35 +1,43 @@
1
1
  module PostmanMta
2
2
  class Conversation < ApplicationModel
3
3
  def index(params = {})
4
- get('/api/v1/conversations', body: params)
4
+ get('/conversations', body: params)
5
+ end
6
+
7
+ def archive(params = {})
8
+ get('/archive/conversations', body: params)
5
9
  end
6
10
 
7
11
  def folder(folder, params = {})
8
12
  params = {
9
13
  folder: folder
10
- }.merge(params)
14
+ }.merge!(params)
11
15
 
12
- get('/api/v1/conversations', body: params)
16
+ get('/conversations', body: params)
13
17
  end
14
18
 
15
19
  def find(conversation_id)
16
- get("/api/v1/conversations/#{conversation_id}")
20
+ get("/conversations/#{conversation_id}")
17
21
  end
18
22
 
19
23
  def move_to_trash(conversation_id)
20
- delete("/api/v1/conversations/#{conversation_id}/trash")
24
+ delete("/conversations/#{conversation_id}/trash")
21
25
  end
22
26
 
23
27
  def mark_as_read(params = {})
24
- patch('/api/v1/conversations/mark', body: params.merge(event: 'mark_as_read'))
28
+ patch('/conversations/mark', body: params.merge(event: 'mark_as_read'))
25
29
  end
26
30
 
27
31
  def mark_as_unread(params = {})
28
- patch('/api/v1/conversations/mark', body: params.merge(event: 'mark_as_unread'))
32
+ patch('/conversations/mark', body: params.merge(event: 'mark_as_unread'))
29
33
  end
30
34
 
31
35
  def move(params = {})
32
- patch('/api/v1/conversations/move', body: params)
36
+ patch('/conversations/move', body: params)
37
+ end
38
+
39
+ def search(params = {})
40
+ get('/search/conversations', body: params)
33
41
  end
34
42
  end
35
43
  end
@@ -1,7 +1,7 @@
1
1
  module PostmanMta
2
2
  class Credential < ApplicationModel
3
3
  def create(params = {})
4
- post('/api/v1/credentials', body: params)
4
+ post('/credentials', body: params)
5
5
  end
6
6
  end
7
7
  end
@@ -1,15 +1,15 @@
1
1
  module PostmanMta
2
2
  class Domain < ApplicationModel
3
- def index
4
- get('/api/v1/domains')
3
+ def index(params = {})
4
+ get('/domains', body: params)
5
5
  end
6
6
 
7
7
  def create(params = {})
8
- post('/api/v1/domains', body: params)
8
+ post('/domains', body: params)
9
9
  end
10
10
 
11
11
  def dns_setup(uuid)
12
- put("/api/v1/domains/#{uuid}/dns_setup")
12
+ put("/domains/#{uuid}/dns_setup")
13
13
  end
14
14
  end
15
15
  end
@@ -6,12 +6,20 @@ module PostmanMta
6
6
  @conversation_id = conversation_id
7
7
  end
8
8
 
9
+ def index(params = {})
10
+ get('/labels', body: params)
11
+ end
12
+
9
13
  def create(params)
10
- post("/api/v1/conversations/#{conversation_id}/labels", body: params)
14
+ post("/conversations/#{conversation_id}/labels", body: params)
15
+ end
16
+
17
+ def update(label_id, params)
18
+ patch("/conversations/#{conversation_id}/labels/#{label_id}", body: params)
11
19
  end
12
20
 
13
21
  def destroy(label_id)
14
- delete("/api/v1/conversations/#{conversation_id}/labels/#{label_id}")
22
+ delete("/conversations/#{conversation_id}/labels/#{label_id}")
15
23
  end
16
24
  end
17
25
  end
@@ -1,15 +1,19 @@
1
1
  module PostmanMta
2
2
  class Message < ApplicationModel
3
3
  def find(token)
4
- get("/api/v1/messages/#{token}")
4
+ get("/messages/#{token}")
5
5
  end
6
6
 
7
7
  def create(params)
8
- post('/api/v1/messages', body: params)
8
+ post('/messages', body: params)
9
9
  end
10
10
 
11
11
  def unread_stats
12
- get('/api/v1/stats/messages/unread')
12
+ get('/stats/messages/unread')
13
+ end
14
+
15
+ def search(params = {})
16
+ get('/search/messages', body: params)
13
17
  end
14
18
  end
15
19
  end
@@ -1,15 +1,15 @@
1
1
  module PostmanMta
2
2
  class Route < ApplicationModel
3
3
  def index
4
- get('/api/v1/routes')
4
+ get('/routes')
5
5
  end
6
6
 
7
7
  def update(uuid, params = {})
8
- patch("/api/v1/routes/#{uuid}", body: params)
8
+ patch("/routes/#{uuid}", body: params)
9
9
  end
10
10
 
11
11
  def create(params = {})
12
- post('/api/v1/routes', body: params)
12
+ post('/routes', body: params)
13
13
  end
14
14
  end
15
15
  end
@@ -7,11 +7,11 @@ module PostmanMta
7
7
  end
8
8
 
9
9
  def create(params)
10
- post("/api/v1/conversations/#{conversation_id}/tags", body: params)
10
+ post("/conversations/#{conversation_id}/tags", body: params)
11
11
  end
12
12
 
13
13
  def destroy(tag_id)
14
- delete("/api/v1/conversations/#{conversation_id}/tags/#{tag_id}")
14
+ delete("/conversations/#{conversation_id}/tags/#{tag_id}")
15
15
  end
16
16
  end
17
17
  end
@@ -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'
@@ -9,11 +9,12 @@ PostmanMta::Engine.routes.draw do
9
9
  end
10
10
 
11
11
  match :starred, on: :collection, via: :get, to: 'conversations#index'
12
+ match :search, on: :collection, via: :get
12
13
  match :read, on: :collection, via: [:put, :patch]
13
14
  match :unread, on: :collection, via: [:put, :patch]
14
15
  match :move, on: :collection, via: [:put, :patch]
15
16
 
16
- resources :labels, only: [:create, :destroy]
17
+ resources :labels, only: [:create, :update, :destroy]
17
18
  resources :tags, only: [:create, :destroy]
18
19
  end
19
20
 
@@ -23,5 +24,11 @@ PostmanMta::Engine.routes.draw do
23
24
  end
24
25
  end
25
26
 
27
+ namespace :archive do
28
+ resources :conversations, only: [:index, :show]
29
+ end
30
+
26
31
  resources :routes, only: :index
32
+ resources :domains, only: :index
33
+ resources :labels, only: :index
27
34
  end
@@ -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'
@@ -19,6 +19,14 @@ module PostmanMta
19
19
  self.class.send(request_type.downcase, path, request_options)
20
20
  end
21
21
 
22
+ def full_path
23
+ @full_path ||= PostmanMta.api_endpoint + path
24
+ end
25
+
26
+ def uri
27
+ @uri ||= URI(full_path)
28
+ end
29
+
22
30
  private
23
31
 
24
32
  def request_options
@@ -26,7 +34,7 @@ module PostmanMta
26
34
  end
27
35
 
28
36
  def auth_headers
29
- PostmanMta::Utils::SignedRequest.new(request_method: request_type.upcase, path: path).headers
37
+ PostmanMta::Utils::SignedRequest.new(request_method: request_type.upcase, path: uri.request_uri).headers
30
38
  end
31
39
 
32
40
  def merge_with_custom_options
@@ -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.7'
4
+ VERSION = '0.2.2'
5
5
  end
@@ -1,6 +1,6 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'postman_mta/version'
6
6
 
@@ -25,9 +25,11 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.add_development_dependency 'bundler', '~> 1.14'
27
27
  spec.add_development_dependency 'guard-rspec', '~> 4.7', '>= 4.7.3'
28
+ spec.add_development_dependency 'overcommit'
28
29
  spec.add_development_dependency 'rake', '~> 10.0'
29
30
  spec.add_development_dependency 'reek'
30
- spec.add_development_dependency 'overcommit'
31
+ spec.add_development_dependency 'rubocop'
32
+ spec.add_development_dependency 'sqlite3'
31
33
 
32
- spec.add_dependency 'httparty', '~> 0.15.6'
34
+ spec.add_dependency 'httparty', '~> 0.15'
33
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.7
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Malinovskiy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-28 00:00:00.000000000 Z
11
+ date: 2020-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,6 +44,20 @@ dependencies:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: 4.7.3
47
+ - !ruby/object:Gem::Dependency
48
+ name: overcommit
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: rake
49
63
  requirement: !ruby/object:Gem::Requirement
@@ -73,7 +87,21 @@ dependencies:
73
87
  - !ruby/object:Gem::Version
74
88
  version: '0'
75
89
  - !ruby/object:Gem::Dependency
76
- name: overcommit
90
+ name: rubocop
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: sqlite3
77
105
  requirement: !ruby/object:Gem::Requirement
78
106
  requirements:
79
107
  - - ">="
@@ -92,14 +120,14 @@ dependencies:
92
120
  requirements:
93
121
  - - "~>"
94
122
  - !ruby/object:Gem::Version
95
- version: 0.15.6
123
+ version: '0.15'
96
124
  type: :runtime
97
125
  prerelease: false
98
126
  version_requirements: !ruby/object:Gem::Requirement
99
127
  requirements:
100
128
  - - "~>"
101
129
  - !ruby/object:Gem::Version
102
- version: 0.15.6
130
+ version: '0.15'
103
131
  description: This gem will add some routes to the application to forward requests
104
132
  from frontend to postman API
105
133
  email:
@@ -112,6 +140,7 @@ files:
112
140
  - ".overcommit.yml"
113
141
  - ".rspec"
114
142
  - ".rubocop.yml"
143
+ - ".ruby-version"
115
144
  - ".travis.yml"
116
145
  - Gemfile
117
146
  - Guardfile
@@ -119,15 +148,19 @@ files:
119
148
  - README.md
120
149
  - Rakefile
121
150
  - app/controllers/postman_mta/application_controller.rb
151
+ - app/controllers/postman_mta/archive/conversations_controller.rb
122
152
  - app/controllers/postman_mta/attachments_controller.rb
123
153
  - app/controllers/postman_mta/conversations_controller.rb
154
+ - app/controllers/postman_mta/domains_controller.rb
124
155
  - app/controllers/postman_mta/labels_controller.rb
125
156
  - app/controllers/postman_mta/messages_controller.rb
126
157
  - app/controllers/postman_mta/routes_controller.rb
127
158
  - app/controllers/postman_mta/stats/messages_controller.rb
128
159
  - app/controllers/postman_mta/tags_controller.rb
129
160
  - app/models/postman_mta/application_model.rb
161
+ - app/models/postman_mta/archive/conversation.rb
130
162
  - app/models/postman_mta/attachment.rb
163
+ - app/models/postman_mta/bookmark.rb
131
164
  - app/models/postman_mta/conversation.rb
132
165
  - app/models/postman_mta/credential.rb
133
166
  - app/models/postman_mta/domain.rb
@@ -143,6 +176,7 @@ files:
143
176
  - lib/postman_mta/api_client.rb
144
177
  - lib/postman_mta/api_request.rb
145
178
  - lib/postman_mta/engine.rb
179
+ - lib/postman_mta/utils/sendfile_url.rb
146
180
  - lib/postman_mta/utils/signature.rb
147
181
  - lib/postman_mta/utils/signed_request.rb
148
182
  - lib/postman_mta/version.rb
@@ -167,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
201
  version: '0'
168
202
  requirements: []
169
203
  rubyforge_project:
170
- rubygems_version: 2.5.2
204
+ rubygems_version: 2.7.6
171
205
  signing_key:
172
206
  specification_version: 4
173
207
  summary: Rails gem to easy integrate postman to your application