postman_mta 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.overcommit.yml +40 -0
- data/.rspec +2 -0
- data/.rubocop.yml +55 -0
- data/.travis.yml +5 -0
- data/Gemfile +13 -0
- data/Guardfile +70 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/app/controllers/postman_mta/application_controller.rb +36 -0
- data/app/controllers/postman_mta/conversations_controller.rb +21 -0
- data/app/controllers/postman_mta/labels_controller.rb +21 -0
- data/app/controllers/postman_mta/messages_controller.rb +21 -0
- data/app/controllers/postman_mta/tags_controller.rb +21 -0
- data/app/models/postman_mta/application_model.rb +11 -0
- data/app/models/postman_mta/conversation.rb +11 -0
- data/app/models/postman_mta/label.rb +17 -0
- data/app/models/postman_mta/message.rb +11 -0
- data/app/models/postman_mta/tag.rb +17 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config/routes.rb +8 -0
- data/config.reek +13 -0
- data/lib/postman_mta/api_client.rb +24 -0
- data/lib/postman_mta/engine.rb +5 -0
- data/lib/postman_mta/utils/signature.rb +63 -0
- data/lib/postman_mta/utils/signed_request.rb +31 -0
- data/lib/postman_mta/version.rb +5 -0
- data/lib/postman_mta.rb +19 -0
- data/postman_mta.gemspec +33 -0
- metadata +166 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f7c0fdec2a65670703adfc59f8374a058f0a466e
|
4
|
+
data.tar.gz: f542a2ebc846f57b555d0c80a4a7e67877e32141
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 49723e8573284422b37c5f5f9289dbc9487c913e12ebf1e39a4cbc8518fe6f49deda8253dafc4e636cab89dfd586aafacc8f120bf3c6497e2d2dfd568491ce74
|
7
|
+
data.tar.gz: 49196710bae24dd7354b60dc70b322d126261bd735ad8e172dcbe5c1d7531cf2aa70505e081297adc12eb95a7f0e097fe2a7ff99edbb46f04e0a08fc64c75605
|
data/.gitignore
ADDED
data/.overcommit.yml
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
CommitMsg:
|
2
|
+
CapitalizedSubject:
|
3
|
+
enabled: false
|
4
|
+
|
5
|
+
EmptyMessage:
|
6
|
+
enabled: false
|
7
|
+
|
8
|
+
TrailingPeriod:
|
9
|
+
enabled: true
|
10
|
+
|
11
|
+
TextWidth:
|
12
|
+
enabled: false
|
13
|
+
|
14
|
+
PreCommit:
|
15
|
+
ALL:
|
16
|
+
on_warn: fail
|
17
|
+
|
18
|
+
AuthorEmail:
|
19
|
+
enabled: true
|
20
|
+
|
21
|
+
AuthorName:
|
22
|
+
enabled: true
|
23
|
+
|
24
|
+
MergeConflicts:
|
25
|
+
enabled: true
|
26
|
+
|
27
|
+
YamlSyntax:
|
28
|
+
enabled: true
|
29
|
+
|
30
|
+
BundleCheck:
|
31
|
+
enabled: true
|
32
|
+
|
33
|
+
RuboCop:
|
34
|
+
enabled: true
|
35
|
+
|
36
|
+
BundleAudit:
|
37
|
+
enabled: true
|
38
|
+
|
39
|
+
Reek:
|
40
|
+
enabled: true
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.3
|
3
|
+
|
4
|
+
Excludes:
|
5
|
+
- "Guardfile"
|
6
|
+
- "Rakefile"
|
7
|
+
- "bin/**/*"
|
8
|
+
- "spec/dummy/**/*"
|
9
|
+
|
10
|
+
##################### Styles ##################################
|
11
|
+
|
12
|
+
Style/Documentation:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
Style/SymbolArray:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Style/FrozenStringLiteralComment:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Style/ClassAndModuleChildren:
|
22
|
+
Exclude:
|
23
|
+
- "app/controllers/*_controller.rb"
|
24
|
+
- "app/controllers/**/*_controller.rb"
|
25
|
+
|
26
|
+
#################### Lint ##################################
|
27
|
+
|
28
|
+
Lint/AmbiguousBlockAssociation:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
##################### Metrics ##################################
|
32
|
+
|
33
|
+
Metrics/LineLength:
|
34
|
+
Max: 110
|
35
|
+
|
36
|
+
Metrics/ClassLength:
|
37
|
+
Max: 200
|
38
|
+
|
39
|
+
Metrics/ModuleLength:
|
40
|
+
Max: 200
|
41
|
+
Exclude:
|
42
|
+
- "**/*_spec.rb"
|
43
|
+
|
44
|
+
Metrics/BlockLength:
|
45
|
+
Max: 50
|
46
|
+
Exclude:
|
47
|
+
- "**/*_spec.rb"
|
48
|
+
|
49
|
+
##################### Rails ##################################
|
50
|
+
|
51
|
+
Rails:
|
52
|
+
Enabled: true
|
53
|
+
|
54
|
+
Rails/SkipsModelValidations:
|
55
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in postman_mta.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
group :development, :test do
|
9
|
+
gem 'rails', '~> 5.0'
|
10
|
+
gem 'rspec-rails', '~> 3.5', '>= 3.5.2'
|
11
|
+
gem 'sqlite3', '~> 1.3', '>= 1.3.13'
|
12
|
+
gem 'webmock', '~> 3.0', '>= 3.0.1'
|
13
|
+
end
|
data/Guardfile
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features) \
|
6
|
+
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
7
|
+
|
8
|
+
## Note: if you are using the `directories` clause above and you are not
|
9
|
+
## watching the project directory ('.'), then you will want to move
|
10
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
11
|
+
#
|
12
|
+
# $ mkdir config
|
13
|
+
# $ mv Guardfile config/
|
14
|
+
# $ ln -s config/Guardfile .
|
15
|
+
#
|
16
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
17
|
+
|
18
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
19
|
+
# rspec may be run, below are examples of the most common uses.
|
20
|
+
# * bundler: 'bundle exec rspec'
|
21
|
+
# * bundler binstubs: 'bin/rspec'
|
22
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
23
|
+
# installed the spring binstubs per the docs)
|
24
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
25
|
+
# * 'just' rspec: 'rspec'
|
26
|
+
|
27
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
28
|
+
require "guard/rspec/dsl"
|
29
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
30
|
+
|
31
|
+
# Feel free to open issues for suggestions and improvements
|
32
|
+
|
33
|
+
# RSpec files
|
34
|
+
rspec = dsl.rspec
|
35
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
36
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
37
|
+
watch(rspec.spec_files)
|
38
|
+
|
39
|
+
# Ruby files
|
40
|
+
ruby = dsl.ruby
|
41
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
42
|
+
|
43
|
+
# Rails files
|
44
|
+
rails = dsl.rails(view_extensions: %w(erb haml slim))
|
45
|
+
dsl.watch_spec_files_for(rails.app_files)
|
46
|
+
dsl.watch_spec_files_for(rails.views)
|
47
|
+
|
48
|
+
watch(rails.controllers) do |m|
|
49
|
+
[
|
50
|
+
rspec.spec.call("routing/#{m[1]}_routing"),
|
51
|
+
rspec.spec.call("controllers/#{m[1]}_controller"),
|
52
|
+
rspec.spec.call("acceptance/#{m[1]}")
|
53
|
+
]
|
54
|
+
end
|
55
|
+
|
56
|
+
# Rails config changes
|
57
|
+
watch(rails.spec_helper) { rspec.spec_dir }
|
58
|
+
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
|
59
|
+
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
60
|
+
|
61
|
+
# Capybara features specs
|
62
|
+
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
|
63
|
+
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
|
64
|
+
|
65
|
+
# Turnip features and steps
|
66
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
67
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
68
|
+
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
|
69
|
+
end
|
70
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Igor Malinovskiy
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# PostmanMta
|
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.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'postman_mta'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install postman_mta
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/postman_mta.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module PostmanMta
|
2
|
+
class ApplicationController < ActionController::Metal
|
3
|
+
abstract!
|
4
|
+
|
5
|
+
MODULES = [
|
6
|
+
AbstractController::Rendering,
|
7
|
+
|
8
|
+
ActionController::UrlFor,
|
9
|
+
ActionController::Redirecting,
|
10
|
+
ActionController::Renderers::All,
|
11
|
+
ActionController::ConditionalGet,
|
12
|
+
|
13
|
+
ActionController::ForceSSL,
|
14
|
+
|
15
|
+
AbstractController::Callbacks,
|
16
|
+
ActionController::StrongParameters,
|
17
|
+
|
18
|
+
# Append rescue at the bottom to wrap as much as possible.
|
19
|
+
ActionController::Rescue,
|
20
|
+
|
21
|
+
# Add instrumentations hooks at the bottom, to ensure they instrument
|
22
|
+
# all the methods properly.
|
23
|
+
ActionController::Instrumentation,
|
24
|
+
|
25
|
+
# Params wrapper should come before instrumentation so they are
|
26
|
+
# properly showed in logs
|
27
|
+
ActionController::ParamsWrapper
|
28
|
+
].freeze
|
29
|
+
|
30
|
+
MODULES.each do |mod|
|
31
|
+
include mod
|
32
|
+
end
|
33
|
+
|
34
|
+
include Rails.application.routes.url_helpers
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module PostmanMta
|
2
|
+
class ConversationsController < ApplicationController
|
3
|
+
def index
|
4
|
+
render json: conversation.index(filter_params).as_json
|
5
|
+
end
|
6
|
+
|
7
|
+
def show
|
8
|
+
render json: conversation.find(params[:id]).as_json
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def conversation
|
14
|
+
@conversation ||= PostmanMta::Conversation.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def filter_params
|
18
|
+
params.permit!
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module PostmanMta
|
2
|
+
class LabelsController < ApplicationController
|
3
|
+
def create
|
4
|
+
render json: label.create(label_params).as_json
|
5
|
+
end
|
6
|
+
|
7
|
+
def destroy
|
8
|
+
render json: label.destroy(params[:id]).as_json
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def label
|
14
|
+
@label ||= PostmanMta::Label.new(params[:conversation_id])
|
15
|
+
end
|
16
|
+
|
17
|
+
def label_params
|
18
|
+
params.permit!
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module PostmanMta
|
2
|
+
class MessagesController < ApplicationController
|
3
|
+
def show
|
4
|
+
render json: message.find(params[:id]).as_json
|
5
|
+
end
|
6
|
+
|
7
|
+
def create
|
8
|
+
render json: message.create(message_params).as_json
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def message
|
14
|
+
@message ||= PostmanMta::Message.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def message_params
|
18
|
+
params.permit!
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module PostmanMta
|
2
|
+
class TagsController < ApplicationController
|
3
|
+
def create
|
4
|
+
render json: tag.create(tag_params).as_json
|
5
|
+
end
|
6
|
+
|
7
|
+
def destroy
|
8
|
+
render json: tag.destroy(params[:id]).as_json
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def tag
|
14
|
+
@tag ||= PostmanMta::Tag.new(params[:conversation_id])
|
15
|
+
end
|
16
|
+
|
17
|
+
def tag_params
|
18
|
+
params.permit!
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module PostmanMta
|
2
|
+
class Label < ApplicationModel
|
3
|
+
attr_reader :conversation_id
|
4
|
+
|
5
|
+
def initialize(conversation_id)
|
6
|
+
@conversation_id = conversation_id
|
7
|
+
end
|
8
|
+
|
9
|
+
def create(params)
|
10
|
+
post("/api/v1/conversations/#{conversation_id}/labels", body: params)
|
11
|
+
end
|
12
|
+
|
13
|
+
def destroy(label_id)
|
14
|
+
delete("/api/v1/conversations/#{conversation_id}/labels/#{label_id}")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module PostmanMta
|
2
|
+
class Tag < ApplicationModel
|
3
|
+
attr_reader :conversation_id
|
4
|
+
|
5
|
+
def initialize(conversation_id)
|
6
|
+
@conversation_id = conversation_id
|
7
|
+
end
|
8
|
+
|
9
|
+
def create(params)
|
10
|
+
post("/api/v1/conversations/#{conversation_id}/tags", body: params)
|
11
|
+
end
|
12
|
+
|
13
|
+
def destroy(tag_id)
|
14
|
+
delete("/api/v1/conversations/#{conversation_id}/tags/#{tag_id}")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "postman_mta"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/config/routes.rb
ADDED
data/config.reek
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module PostmanMta
|
4
|
+
class ApiClient
|
5
|
+
include ::HTTParty
|
6
|
+
base_uri PostmanMta.api_endpoint
|
7
|
+
|
8
|
+
[:get, :post, :put, :patch, :delete].each do |type|
|
9
|
+
define_method type do |url, options = {}|
|
10
|
+
perform_request(type.to_s.upcase, url, options)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def perform_request(request_type, path, options = {})
|
17
|
+
headers = PostmanMta::Utils::SignedRequest.new(
|
18
|
+
request_method: request_type.upcase, path: path
|
19
|
+
).headers
|
20
|
+
|
21
|
+
self.class.send(request_type.downcase, path, { headers: headers }.merge(options)).parsed_response
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'digest/sha1'
|
3
|
+
|
4
|
+
module PostmanMta
|
5
|
+
module Utils
|
6
|
+
# Usage:
|
7
|
+
# request = Signature.new(options)
|
8
|
+
# request.valid?('some-signature-hash', 'some-big-secret-key',)
|
9
|
+
#
|
10
|
+
class Signature
|
11
|
+
SPLITTER = '|'.freeze
|
12
|
+
TTL = 2.minutes
|
13
|
+
|
14
|
+
def initialize(options = {})
|
15
|
+
@options = options
|
16
|
+
@timestamp = Time.zone.at(@options[:timestamp].to_i)
|
17
|
+
end
|
18
|
+
|
19
|
+
def valid?(signature, secret)
|
20
|
+
return false if signature.blank? || secret.blank? || expired?
|
21
|
+
generate_signature(secret) == signature
|
22
|
+
end
|
23
|
+
|
24
|
+
def invalid?(*args)
|
25
|
+
!valid?(*args)
|
26
|
+
end
|
27
|
+
|
28
|
+
def expired?
|
29
|
+
!alive?
|
30
|
+
end
|
31
|
+
|
32
|
+
def alive?
|
33
|
+
alive_timerange.cover?(@timestamp)
|
34
|
+
end
|
35
|
+
|
36
|
+
def alive_timerange
|
37
|
+
@alive_timerange ||= (TTL.ago..Time.zone.now)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Generate signature token
|
41
|
+
#
|
42
|
+
def generate_signature(secret)
|
43
|
+
hmac = OpenSSL::HMAC.digest(digest, secret, string_to_sign)
|
44
|
+
Base64.encode64(hmac).chomp
|
45
|
+
end
|
46
|
+
|
47
|
+
protected
|
48
|
+
|
49
|
+
def digest
|
50
|
+
OpenSSL::Digest::SHA256.new
|
51
|
+
end
|
52
|
+
|
53
|
+
def string_to_sign
|
54
|
+
[
|
55
|
+
@options[:request_method],
|
56
|
+
@options[:path],
|
57
|
+
@options[:access_key],
|
58
|
+
@timestamp.to_i
|
59
|
+
].map(&:to_s).join(SPLITTER)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module PostmanMta
|
2
|
+
module Utils
|
3
|
+
class SignedRequest
|
4
|
+
attr_reader :options
|
5
|
+
|
6
|
+
delegate :api_key, :api_secret, to: :PostmanMta
|
7
|
+
|
8
|
+
def initialize(options = {})
|
9
|
+
@options = options
|
10
|
+
|
11
|
+
@options[:timestamp] ||= Time.zone.now.to_i
|
12
|
+
end
|
13
|
+
|
14
|
+
def headers
|
15
|
+
{
|
16
|
+
'X-Access-Key' => api_key,
|
17
|
+
'X-Timestamp' => options[:timestamp].to_s,
|
18
|
+
'X-Signature' => signature
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def signature
|
23
|
+
generator.generate_signature(api_secret)
|
24
|
+
end
|
25
|
+
|
26
|
+
def generator
|
27
|
+
@_generator ||= PostmanMta::Utils::Signature.new(options.merge(access_key: api_key))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/postman_mta.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'postman_mta/version'
|
2
|
+
require 'postman_mta/engine'
|
3
|
+
|
4
|
+
module PostmanMta
|
5
|
+
module Utils
|
6
|
+
autoload :Signature, 'postman_mta/utils/signature'
|
7
|
+
autoload :SignedRequest, 'postman_mta/utils/signed_request'
|
8
|
+
end
|
9
|
+
|
10
|
+
autoload :ApiClient, 'postman_mta/api_client'
|
11
|
+
|
12
|
+
mattr_accessor :api_key
|
13
|
+
mattr_accessor :api_secret
|
14
|
+
mattr_accessor :api_endpoint
|
15
|
+
|
16
|
+
def self.setup
|
17
|
+
yield self
|
18
|
+
end
|
19
|
+
end
|
data/postman_mta.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'postman_mta/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'postman_mta'
|
9
|
+
spec.version = PostmanMta::VERSION
|
10
|
+
spec.authors = ['Igor Malinovskiy']
|
11
|
+
spec.email = ['igor.malinovskiy@netfix.xyz']
|
12
|
+
|
13
|
+
spec.summary = 'Rails gem to easy integrate postman to your application'
|
14
|
+
spec.description =
|
15
|
+
'This gem will add some routes to the application to forward requests from frontend to postman API'
|
16
|
+
spec.homepage = 'https://github.com/psyipm/postman_mta'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
21
|
+
end
|
22
|
+
spec.bindir = 'exe'
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
27
|
+
spec.add_development_dependency 'guard-rspec', '~> 4.7', '>= 4.7.3'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
spec.add_development_dependency 'reek'
|
30
|
+
spec.add_development_dependency 'overcommit'
|
31
|
+
|
32
|
+
spec.add_dependency 'httparty', '~> 0.15.6'
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: postman_mta
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Igor Malinovskiy
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: guard-rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.7'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 4.7.3
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '4.7'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 4.7.3
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '10.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '10.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: reek
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: overcommit
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: httparty
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 0.15.6
|
96
|
+
type: :runtime
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 0.15.6
|
103
|
+
description: This gem will add some routes to the application to forward requests
|
104
|
+
from frontend to postman API
|
105
|
+
email:
|
106
|
+
- igor.malinovskiy@netfix.xyz
|
107
|
+
executables: []
|
108
|
+
extensions: []
|
109
|
+
extra_rdoc_files: []
|
110
|
+
files:
|
111
|
+
- ".gitignore"
|
112
|
+
- ".overcommit.yml"
|
113
|
+
- ".rspec"
|
114
|
+
- ".rubocop.yml"
|
115
|
+
- ".travis.yml"
|
116
|
+
- Gemfile
|
117
|
+
- Guardfile
|
118
|
+
- LICENSE.txt
|
119
|
+
- README.md
|
120
|
+
- Rakefile
|
121
|
+
- app/controllers/postman_mta/application_controller.rb
|
122
|
+
- app/controllers/postman_mta/conversations_controller.rb
|
123
|
+
- app/controllers/postman_mta/labels_controller.rb
|
124
|
+
- app/controllers/postman_mta/messages_controller.rb
|
125
|
+
- app/controllers/postman_mta/tags_controller.rb
|
126
|
+
- app/models/postman_mta/application_model.rb
|
127
|
+
- app/models/postman_mta/conversation.rb
|
128
|
+
- app/models/postman_mta/label.rb
|
129
|
+
- app/models/postman_mta/message.rb
|
130
|
+
- app/models/postman_mta/tag.rb
|
131
|
+
- bin/console
|
132
|
+
- bin/setup
|
133
|
+
- config.reek
|
134
|
+
- config/routes.rb
|
135
|
+
- lib/postman_mta.rb
|
136
|
+
- lib/postman_mta/api_client.rb
|
137
|
+
- lib/postman_mta/engine.rb
|
138
|
+
- lib/postman_mta/utils/signature.rb
|
139
|
+
- lib/postman_mta/utils/signed_request.rb
|
140
|
+
- lib/postman_mta/version.rb
|
141
|
+
- postman_mta.gemspec
|
142
|
+
homepage: https://github.com/psyipm/postman_mta
|
143
|
+
licenses:
|
144
|
+
- MIT
|
145
|
+
metadata: {}
|
146
|
+
post_install_message:
|
147
|
+
rdoc_options: []
|
148
|
+
require_paths:
|
149
|
+
- lib
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
requirements: []
|
161
|
+
rubyforge_project:
|
162
|
+
rubygems_version: 2.5.2
|
163
|
+
signing_key:
|
164
|
+
specification_version: 4
|
165
|
+
summary: Rails gem to easy integrate postman to your application
|
166
|
+
test_files: []
|