postman_mta 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: f7c0fdec2a65670703adfc59f8374a058f0a466e
4
- data.tar.gz: f542a2ebc846f57b555d0c80a4a7e67877e32141
3
+ metadata.gz: d204a94e4b429c874c194ebcfddbc02969cc92c2
4
+ data.tar.gz: 4b42a3e90b282fd6a78cbae5153d16f269900776
5
5
  SHA512:
6
- metadata.gz: 49723e8573284422b37c5f5f9289dbc9487c913e12ebf1e39a4cbc8518fe6f49deda8253dafc4e636cab89dfd586aafacc8f120bf3c6497e2d2dfd568491ce74
7
- data.tar.gz: 49196710bae24dd7354b60dc70b322d126261bd735ad8e172dcbe5c1d7531cf2aa70505e081297adc12eb95a7f0e097fe2a7ff99edbb46f04e0a08fc64c75605
6
+ metadata.gz: 23c96c6b8108320788c4b358be7444f09cfa43f3381dd642eb4d37346bd14f8640e539a57a3811defd8061e652a15d80388e02bd5edbafafd229a6b38982b7cb
7
+ data.tar.gz: d2e16e3f811071a3654198ae354bd5873f7f4b6d1b9d7ece0c980da317005d9fab13f4bca634eacc7432711190a8088bdf5d9b521b6467df06cdc4c078b00144
data/README.md CHANGED
@@ -1,8 +1,12 @@
1
- # PostmanMta
1
+ # Postman MTA
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/postman_mta`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Build Status](https://semaphoreci.com/api/v1/igormalinovskiy/postman_mta/branches/master/shields_badge.svg)](https://semaphoreci.com/igormalinovskiy/postman_mta)
4
+ [![Code Climate](https://codeclimate.com/github/psyipm/postman_mta/badges/gpa.svg)](https://codeclimate.com/github/psyipm/postman_mta)
5
+ [![Gem Version](https://badge.fury.io/rb/postman_mta.svg)](https://badge.fury.io/rb/postman_mta)
4
6
 
5
- TODO: Delete this and the text above, and describe your gem
7
+ Rails gem to easy integrate Postman to your application
8
+
9
+ This gem will add some routes to the application to forward requests from frontend to postman API
6
10
 
7
11
  ## Installation
8
12
 
@@ -22,7 +26,76 @@ Or install it yourself as:
22
26
 
23
27
  ## Usage
24
28
 
25
- TODO: Write usage instructions here
29
+ Mount engine in `config/routes.rb`:
30
+
31
+ ```ruby
32
+ mount PostmanMta::Engine => '/mta'
33
+ ```
34
+
35
+ Then configure the gem:
36
+
37
+ ```ruby
38
+ # config/initializers/postman_mta.rb
39
+ PostmanMta.setup do |config|
40
+ config.api_key = ENV['POSTMAN_API_KEY']
41
+ config.api_secret = ENV['POSTMAN_API_SECRET']
42
+ config.api_endpoint = ENV['POSTMAN_API_ENDPOINT']
43
+ end
44
+ ```
45
+
46
+ This will add the following routes:
47
+
48
+ ```
49
+ Routes for PostmanMta::Engine:
50
+ messages POST /messages(.:format) postman_mta/messages#create
51
+ message GET /messages/:id(.:format) postman_mta/messages#show
52
+ conversation_labels POST /conversations/:conversation_id/labels(.:format) postman_mta/labels#create
53
+ conversation_label DELETE /conversations/:conversation_id/labels/:id(.:format) postman_mta/labels#destroy
54
+ conversation_tags POST /conversations/:conversation_id/tags(.:format) postman_mta/tags#create
55
+ conversation_tag DELETE /conversations/:conversation_id/tags/:id(.:format) postman_mta/tags#destroy
56
+ conversations GET /conversations(.:format) postman_mta/conversations#index
57
+ conversation GET /conversations/:id(.:format) postman_mta/conversations#show
58
+ ```
59
+
60
+ for `messages#create` the following parameters accepted:
61
+
62
+ ```ruby
63
+ attribute :from, String
64
+ attribute :to, Array # The array of recepient email addresses
65
+ attribute :plain_body, String
66
+ attribute :html_body, String
67
+ attribute :bcc, Array # The array of bcc email addresses
68
+ attribute :cc, Array # The array of cc email addresses
69
+ attribute :reply_to, String
70
+ attribute :in_reply_to, String
71
+ attribute :subject, String
72
+ attribute :attachments, Array # [{ base64: "YXNmYXNmYXNm\n", name: 'file.txt', content_type: 'text/plain' }]
73
+ ```
74
+
75
+ Messages are grouped in conversations. Conversations can be accessed using corresponding `#index` and `#show` actions.
76
+
77
+ Filter parameters for `conversations#index`:
78
+
79
+ ```ruby
80
+ { tag_title: 'some_tag', tag_value: 'some_value' }
81
+ { label: 'some_label_title' }
82
+ ```
83
+
84
+ Conversations can be tagged and/or labeled. Labels and tags can be used for search. To create new tag for conversation, send the following params to `tags#create`:
85
+
86
+ ```ruby
87
+ attribute :title, String
88
+ attribute :value, String
89
+ attribute :conversation_id, Integer
90
+ ```
91
+
92
+ Params for label:
93
+
94
+ ```ruby
95
+ attribute :title, String
96
+ attribute :sort_order, Integer
97
+ attribute :color, String
98
+ ```
26
99
 
27
100
  ## Development
28
101
 
@@ -32,7 +105,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
105
 
33
106
  ## Contributing
34
107
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/postman_mta.
108
+ Bug reports and pull requests are welcome on GitHub at https://github.com/psyipm/postman_mta.
36
109
 
37
110
  ## License
38
111
 
@@ -1,11 +1,29 @@
1
1
  module PostmanMta
2
2
  class ConversationsController < ApplicationController
3
3
  def index
4
- render json: conversation.index(filter_params).as_json
4
+ render conversation.index(permitted_params)
5
+ end
6
+
7
+ [:inbox, :sent, :spam, :trash].each do |folder|
8
+ define_method folder do
9
+ render conversation.folder(folder, permitted_params)
10
+ end
5
11
  end
6
12
 
7
13
  def show
8
- render json: conversation.find(params[:id]).as_json
14
+ render conversation.find(params[:id])
15
+ end
16
+
17
+ def read
18
+ render conversation.mark_as_read(permitted_params)
19
+ end
20
+
21
+ def destroy
22
+ render conversation.move_to_trash(params[:id])
23
+ end
24
+
25
+ def move
26
+ render conversation.move(permitted_params)
9
27
  end
10
28
 
11
29
  private
@@ -14,7 +32,7 @@ module PostmanMta
14
32
  @conversation ||= PostmanMta::Conversation.new
15
33
  end
16
34
 
17
- def filter_params
35
+ def permitted_params
18
36
  params.permit!
19
37
  end
20
38
  end
@@ -1,11 +1,11 @@
1
1
  module PostmanMta
2
2
  class LabelsController < ApplicationController
3
3
  def create
4
- render json: label.create(label_params).as_json
4
+ render label.create(label_params)
5
5
  end
6
6
 
7
7
  def destroy
8
- render json: label.destroy(params[:id]).as_json
8
+ render label.destroy(params[:id])
9
9
  end
10
10
 
11
11
  private
@@ -1,11 +1,11 @@
1
1
  module PostmanMta
2
2
  class MessagesController < ApplicationController
3
3
  def show
4
- render json: message.find(params[:id]).as_json
4
+ render message.find(params[:token])
5
5
  end
6
6
 
7
7
  def create
8
- render json: message.create(message_params).as_json
8
+ render message.create(message_params)
9
9
  end
10
10
 
11
11
  private
@@ -0,0 +1,13 @@
1
+ module PostmanMta
2
+ class RoutesController < ApplicationController
3
+ def index
4
+ render route.index
5
+ end
6
+
7
+ private
8
+
9
+ def route
10
+ @route ||= PostmanMta::Route.new
11
+ end
12
+ end
13
+ end
@@ -1,11 +1,11 @@
1
1
  module PostmanMta
2
2
  class TagsController < ApplicationController
3
3
  def create
4
- render json: tag.create(tag_params).as_json
4
+ render tag.create(tag_params)
5
5
  end
6
6
 
7
7
  def destroy
8
- render json: tag.destroy(params[:id]).as_json
8
+ render tag.destroy(params[:id])
9
9
  end
10
10
 
11
11
  private
@@ -4,8 +4,28 @@ module PostmanMta
4
4
  get('/api/v1/conversations', body: params)
5
5
  end
6
6
 
7
+ def folder(folder, params = {})
8
+ params = {
9
+ folder: folder
10
+ }.merge(params)
11
+
12
+ get('/api/v1/conversations', body: params)
13
+ end
14
+
7
15
  def find(conversation_id)
8
16
  get("/api/v1/conversations/#{conversation_id}")
9
17
  end
18
+
19
+ def move_to_trash(conversation_id)
20
+ delete("/api/v1/conversations/#{conversation_id}/trash")
21
+ end
22
+
23
+ def mark_as_read(params = {})
24
+ patch('/api/v1/conversations/read', body: params)
25
+ end
26
+
27
+ def move(params = {})
28
+ patch('/api/v1/conversations/move', body: params)
29
+ end
10
30
  end
11
31
  end
@@ -1,7 +1,7 @@
1
1
  module PostmanMta
2
2
  class Message < ApplicationModel
3
- def find(message_id)
4
- get("/api/v1/messages/#{message_id}")
3
+ def find(token)
4
+ get("/api/v1/messages/#{token}")
5
5
  end
6
6
 
7
7
  def create(params)
@@ -0,0 +1,7 @@
1
+ module PostmanMta
2
+ class Route < ApplicationModel
3
+ def index
4
+ get('/api/v1/routes')
5
+ end
6
+ end
7
+ end
data/config/routes.rb CHANGED
@@ -1,8 +1,18 @@
1
1
  PostmanMta::Engine.routes.draw do
2
- resources :messages, only: [:show, :create]
2
+ resources :messages, only: [:show, :create], param: :token
3
+
4
+ resources :conversations, only: [:index, :show, :destroy] do
5
+ [:inbox, :sent, :spam, :trash].each do |folder|
6
+ match folder, on: :collection, via: :get
7
+ end
8
+
9
+ match :starred, on: :collection, via: :get, to: 'conversations#index'
10
+ match :read, on: :collection, via: [:put, :patch]
11
+ match :move, on: :collection, via: [:put, :patch]
3
12
 
4
- resources :conversations, only: [:index, :show] do
5
13
  resources :labels, only: [:create, :destroy]
6
14
  resources :tags, only: [:create, :destroy]
7
15
  end
16
+
17
+ resources :routes, only: :index
8
18
  end
@@ -18,7 +18,9 @@ module PostmanMta
18
18
  request_method: request_type.upcase, path: path
19
19
  ).headers
20
20
 
21
- self.class.send(request_type.downcase, path, { headers: headers }.merge(options)).parsed_response
21
+ response = self.class.send(request_type.downcase, path, { headers: headers }.merge(options))
22
+
23
+ { json: response.parsed_response.as_json, status: response.code }
22
24
  end
23
25
  end
24
26
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PostmanMta
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
data/postman_mta.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ['lib']
25
25
 
26
- spec.add_development_dependency 'bundler', '~> 1.15'
26
+ spec.add_development_dependency 'bundler', '~> 1.14'
27
27
  spec.add_development_dependency 'guard-rspec', '~> 4.7', '>= 4.7.3'
28
28
  spec.add_development_dependency 'rake', '~> 10.0'
29
29
  spec.add_development_dependency 'reek'
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.0
4
+ version: 0.1.1
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-08-31 00:00:00.000000000 Z
11
+ date: 2017-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.15'
19
+ version: '1.14'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.15'
26
+ version: '1.14'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: guard-rspec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -122,11 +122,13 @@ files:
122
122
  - app/controllers/postman_mta/conversations_controller.rb
123
123
  - app/controllers/postman_mta/labels_controller.rb
124
124
  - app/controllers/postman_mta/messages_controller.rb
125
+ - app/controllers/postman_mta/routes_controller.rb
125
126
  - app/controllers/postman_mta/tags_controller.rb
126
127
  - app/models/postman_mta/application_model.rb
127
128
  - app/models/postman_mta/conversation.rb
128
129
  - app/models/postman_mta/label.rb
129
130
  - app/models/postman_mta/message.rb
131
+ - app/models/postman_mta/route.rb
130
132
  - app/models/postman_mta/tag.rb
131
133
  - bin/console
132
134
  - bin/setup